From 117250f5c1302375df2af04c37b93b320967540b Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Wed, 17 Mar 2021 13:36:58 -0500 Subject: [PATCH] hands to int64 --- src/game/rule/operation/hand.go | 40 +++++++++++------------ src/game/rule/operation/hand_test.go | 2 +- src/game/rule/operation/int.go | 2 +- src/game/rule/operation/operation_test.go | 2 +- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/game/rule/operation/hand.go b/src/game/rule/operation/hand.go index 16b9e35..145568e 100644 --- a/src/game/rule/operation/hand.go +++ b/src/game/rule/operation/hand.go @@ -5,7 +5,7 @@ import ( "sort" ) -func royalFlush(game *entity.Game, _ interface{}) uint64 { +func royalFlush(game *entity.Game, _ interface{}) int64 { hand := getHand(game) if !hand.Flush() || !hand.Straight() { return 0 @@ -18,7 +18,7 @@ func royalFlush(game *entity.Game, _ interface{}) uint64 { return 1 } -func straightFlush(game *entity.Game, _ interface{}) uint64 { +func straightFlush(game *entity.Game, _ interface{}) int64 { hand := getHand(game) if !hand.Flush() || !hand.Straight() { return 0 @@ -29,14 +29,14 @@ func straightFlush(game *entity.Game, _ interface{}) uint64 { 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) } -func fullHouse(game *entity.Game, _ interface{}) uint64 { +func fullHouse(game *entity.Game, _ interface{}) int64 { hand := getHand(game) counts := counts(hand) trio := entity.Card{} @@ -52,10 +52,10 @@ func fullHouse(game *entity.Game, _ interface{}) uint64 { if trio.Value == 0 || duo.Value == 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) if !hand.Flush() { return 0 @@ -63,7 +63,7 @@ func flush(game *entity.Game, _ interface{}) uint64 { return highCard(game, nil) } -func straight(game *entity.Game, _ interface{}) uint64 { +func straight(game *entity.Game, _ interface{}) int64 { hand := getHand(game) if !hand.Straight() { return 0 @@ -74,14 +74,14 @@ func straight(game *entity.Game, _ interface{}) uint64 { 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) } -func twoPair(game *entity.Game, _ interface{}) uint64 { +func twoPair(game *entity.Game, _ interface{}) int64 { high := nOfAKind(game, 2) if high == 0 { return 0 @@ -92,7 +92,7 @@ func twoPair(game *entity.Game, _ interface{}) uint64 { low := 0 highCard := 0 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 } } @@ -100,18 +100,18 @@ func twoPair(game *entity.Game, _ interface{}) uint64 { return 0 } 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 } } - 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) } -func nOfAKind(game *entity.Game, n int) uint64 { +func nOfAKind(game *entity.Game, n int) int64 { hand := getHand(game) counts := counts(hand) best := entity.Card{} @@ -129,19 +129,19 @@ func nOfAKind(game *entity.Game, n int) uint64 { if best.Value == 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) values := make([]int, 0) for _, card := range hand.AllCards() { values = append(values, card.Value) } sort.Ints(values) - value := uint64(0) + value := int64(0) for i := len(values) - 1; i >= 0; i-- { - value = value*100 + uint64(values[i]) + value = value*100 + int64(values[i]) } return value } diff --git a/src/game/rule/operation/hand_test.go b/src/game/rule/operation/hand_test.go index e003920..551e077 100644 --- a/src/game/rule/operation/hand_test.go +++ b/src/game/rule/operation/hand_test.go @@ -498,7 +498,7 @@ func testHand(t *testing.T, name string, foo Int, public []entity.Card, private }, } got := foo(game, nil) - if got != uint64(want) { + if got != int64(want) { t.Fatal(want, got) } }) diff --git a/src/game/rule/operation/int.go b/src/game/rule/operation/int.go index 77b3014..8ec3dc4 100644 --- a/src/game/rule/operation/int.go +++ b/src/game/rule/operation/int.go @@ -6,7 +6,7 @@ import ( "local/sandbox/cards/src/entity" ) -type Int func(*entity.Game, interface{}) uint64 +type Int func(*entity.Game, interface{}) int64 var intStringified = map[string]Int{ "royalFlush": royalFlush, diff --git a/src/game/rule/operation/operation_test.go b/src/game/rule/operation/operation_test.go index 159123c..8eb52f1 100644 --- a/src/game/rule/operation/operation_test.go +++ b/src/game/rule/operation/operation_test.go @@ -6,7 +6,7 @@ import ( ) func TestOperationInterface(t *testing.T) { - foo := func(*entity.Game, interface{}) uint64 { return 0 } + foo := func(*entity.Game, interface{}) int64 { return 0 } var _ Int = foo bar := func(*entity.Game, interface{}) bool { return false } var _ Bool = bar