mirror of
https://github.com/cubixle/codekata-golang.git
synced 2026-04-30 17:58:41 +01:00
53: poker hands
structs
This commit is contained in:
+30
-16
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -24,24 +25,24 @@ func main() {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
line := string(a)
|
line := string(a)
|
||||||
cards := strings.Split(line, " ")
|
cs := strings.Split(line, " ")
|
||||||
if len(cards) != 10 {
|
if len(cs) != 10 {
|
||||||
panic("invalid line")
|
panic("invalid line")
|
||||||
}
|
}
|
||||||
h := hand{
|
h := hand{
|
||||||
player1: [5]string{
|
player1: cards{
|
||||||
cards[0],
|
card(cs[0]),
|
||||||
cards[1],
|
card(cs[1]),
|
||||||
cards[2],
|
card(cs[2]),
|
||||||
cards[3],
|
card(cs[3]),
|
||||||
cards[4],
|
card(cs[4]),
|
||||||
},
|
},
|
||||||
player2: [5]string{
|
player2: cards{
|
||||||
cards[5],
|
card(cs[5]),
|
||||||
cards[6],
|
card(cs[6]),
|
||||||
cards[7],
|
card(cs[7]),
|
||||||
cards[8],
|
card(cs[8]),
|
||||||
cards[9],
|
card(cs[9]),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
input = append(input, h)
|
input = append(input, h)
|
||||||
@@ -53,10 +54,23 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type hand struct {
|
type hand struct {
|
||||||
player1 [5]string
|
player1 cards
|
||||||
player2 [5]string
|
player2 cards
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hand) isPlayer1Win() bool {
|
func (hand) isPlayer1Win() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type card string
|
||||||
|
|
||||||
|
func (c card) number() int {
|
||||||
|
i, _ := strconv.Atoi(string(c[0]))
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c card) suit() string {
|
||||||
|
return string(c[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
type cards [5]card
|
||||||
|
|||||||
Reference in New Issue
Block a user