hands to int64
parent
cc4a19a47c
commit
117250f5c1
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
func royalFlush(game *entity.Game, _ interface{}) uint64 {
|
func royalFlush(game *entity.Game, _ interface{}) int64 {
|
||||||
hand := getHand(game)
|
hand := getHand(game)
|
||||||
if !hand.Flush() || !hand.Straight() {
|
if !hand.Flush() || !hand.Straight() {
|
||||||
return 0
|
return 0
|
||||||
|
|
@ -18,7 +18,7 @@ func royalFlush(game *entity.Game, _ interface{}) uint64 {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func straightFlush(game *entity.Game, _ interface{}) uint64 {
|
func straightFlush(game *entity.Game, _ interface{}) int64 {
|
||||||
hand := getHand(game)
|
hand := getHand(game)
|
||||||
if !hand.Flush() || !hand.Straight() {
|
if !hand.Flush() || !hand.Straight() {
|
||||||
return 0
|
return 0
|
||||||
|
|
@ -29,14 +29,14 @@ func straightFlush(game *entity.Game, _ interface{}) uint64 {
|
||||||
biggest = card.Value
|
biggest = card.Value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return uint64(biggest)
|
return int64(biggest)
|
||||||
}
|
}
|
||||||
|
|
||||||
func fourOfAKind(game *entity.Game, _ interface{}) uint64 {
|
func fourOfAKind(game *entity.Game, _ interface{}) int64 {
|
||||||
return nOfAKind(game, 4)
|
return nOfAKind(game, 4)
|
||||||
}
|
}
|
||||||
|
|
||||||
func fullHouse(game *entity.Game, _ interface{}) uint64 {
|
func fullHouse(game *entity.Game, _ interface{}) int64 {
|
||||||
hand := getHand(game)
|
hand := getHand(game)
|
||||||
counts := counts(hand)
|
counts := counts(hand)
|
||||||
trio := entity.Card{}
|
trio := entity.Card{}
|
||||||
|
|
@ -52,10 +52,10 @@ func fullHouse(game *entity.Game, _ interface{}) uint64 {
|
||||||
if trio.Value == 0 || duo.Value == 0 {
|
if trio.Value == 0 || duo.Value == 0 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return uint64(trio.Value*100 + duo.Value)
|
return int64(trio.Value*100 + duo.Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func flush(game *entity.Game, _ interface{}) uint64 {
|
func flush(game *entity.Game, _ interface{}) int64 {
|
||||||
hand := getHand(game)
|
hand := getHand(game)
|
||||||
if !hand.Flush() {
|
if !hand.Flush() {
|
||||||
return 0
|
return 0
|
||||||
|
|
@ -63,7 +63,7 @@ func flush(game *entity.Game, _ interface{}) uint64 {
|
||||||
return highCard(game, nil)
|
return highCard(game, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func straight(game *entity.Game, _ interface{}) uint64 {
|
func straight(game *entity.Game, _ interface{}) int64 {
|
||||||
hand := getHand(game)
|
hand := getHand(game)
|
||||||
if !hand.Straight() {
|
if !hand.Straight() {
|
||||||
return 0
|
return 0
|
||||||
|
|
@ -74,14 +74,14 @@ func straight(game *entity.Game, _ interface{}) uint64 {
|
||||||
big = card.Value
|
big = card.Value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return uint64(big)
|
return int64(big)
|
||||||
}
|
}
|
||||||
|
|
||||||
func threeOfAKind(game *entity.Game, _ interface{}) uint64 {
|
func threeOfAKind(game *entity.Game, _ interface{}) int64 {
|
||||||
return nOfAKind(game, 3)
|
return nOfAKind(game, 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
func twoPair(game *entity.Game, _ interface{}) uint64 {
|
func twoPair(game *entity.Game, _ interface{}) int64 {
|
||||||
high := nOfAKind(game, 2)
|
high := nOfAKind(game, 2)
|
||||||
if high == 0 {
|
if high == 0 {
|
||||||
return 0
|
return 0
|
||||||
|
|
@ -92,7 +92,7 @@ func twoPair(game *entity.Game, _ interface{}) uint64 {
|
||||||
low := 0
|
low := 0
|
||||||
highCard := 0
|
highCard := 0
|
||||||
for k, v := range counts {
|
for k, v := range counts {
|
||||||
if ((uint64(k.Value) != high && v >= 2) || v >= 4) && k.Value > low {
|
if ((int64(k.Value) != high && v >= 2) || v >= 4) && k.Value > low {
|
||||||
low = k.Value
|
low = k.Value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -100,18 +100,18 @@ func twoPair(game *entity.Game, _ interface{}) uint64 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
for k, v := range counts {
|
for k, v := range counts {
|
||||||
if ((uint64(k.Value) != high && k.Value != low) || v > 4 || v == 3) && k.Value > highCard {
|
if ((int64(k.Value) != high && k.Value != low) || v > 4 || v == 3) && k.Value > highCard {
|
||||||
highCard = k.Value
|
highCard = k.Value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return high*100*100 + uint64(low*100+highCard)
|
return high*100*100 + int64(low*100+highCard)
|
||||||
}
|
}
|
||||||
|
|
||||||
func pair(game *entity.Game, _ interface{}) uint64 {
|
func pair(game *entity.Game, _ interface{}) int64 {
|
||||||
return nOfAKind(game, 2)
|
return nOfAKind(game, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func nOfAKind(game *entity.Game, n int) uint64 {
|
func nOfAKind(game *entity.Game, n int) int64 {
|
||||||
hand := getHand(game)
|
hand := getHand(game)
|
||||||
counts := counts(hand)
|
counts := counts(hand)
|
||||||
best := entity.Card{}
|
best := entity.Card{}
|
||||||
|
|
@ -129,19 +129,19 @@ func nOfAKind(game *entity.Game, n int) uint64 {
|
||||||
if best.Value == 0 {
|
if best.Value == 0 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return uint64(best.Value*100 + high.Value)
|
return int64(best.Value*100 + high.Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func highCard(game *entity.Game, _ interface{}) uint64 {
|
func highCard(game *entity.Game, _ interface{}) int64 {
|
||||||
hand := getHand(game)
|
hand := getHand(game)
|
||||||
values := make([]int, 0)
|
values := make([]int, 0)
|
||||||
for _, card := range hand.AllCards() {
|
for _, card := range hand.AllCards() {
|
||||||
values = append(values, card.Value)
|
values = append(values, card.Value)
|
||||||
}
|
}
|
||||||
sort.Ints(values)
|
sort.Ints(values)
|
||||||
value := uint64(0)
|
value := int64(0)
|
||||||
for i := len(values) - 1; i >= 0; i-- {
|
for i := len(values) - 1; i >= 0; i-- {
|
||||||
value = value*100 + uint64(values[i])
|
value = value*100 + int64(values[i])
|
||||||
}
|
}
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -498,7 +498,7 @@ func testHand(t *testing.T, name string, foo Int, public []entity.Card, private
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
got := foo(game, nil)
|
got := foo(game, nil)
|
||||||
if got != uint64(want) {
|
if got != int64(want) {
|
||||||
t.Fatal(want, got)
|
t.Fatal(want, got)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"local/sandbox/cards/src/entity"
|
"local/sandbox/cards/src/entity"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Int func(*entity.Game, interface{}) uint64
|
type Int func(*entity.Game, interface{}) int64
|
||||||
|
|
||||||
var intStringified = map[string]Int{
|
var intStringified = map[string]Int{
|
||||||
"royalFlush": royalFlush,
|
"royalFlush": royalFlush,
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestOperationInterface(t *testing.T) {
|
func TestOperationInterface(t *testing.T) {
|
||||||
foo := func(*entity.Game, interface{}) uint64 { return 0 }
|
foo := func(*entity.Game, interface{}) int64 { return 0 }
|
||||||
var _ Int = foo
|
var _ Int = foo
|
||||||
bar := func(*entity.Game, interface{}) bool { return false }
|
bar := func(*entity.Game, interface{}) bool { return false }
|
||||||
var _ Bool = bar
|
var _ Bool = bar
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue