Skip to content

Commit 08b9264

Browse files
committed
Fixing round score calculations in server/main.go
and removing code that is no longer needed in Server around score display in Client apps
1 parent e9515dc commit 08b9264

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

server/main.go

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ type Player struct {
8383
ValidMove string // List of valid moves for the player (e.g., "play", "fold", "draw")
8484
Playorder int // The order in which the player plays (0 is first)
8585
RoundScore int // Score for the current round
86-
Message1 string // Use on the results page to display the counters and score
87-
Message2 string // Additional message line for the results if required
8886
LastPolledTime time.Time // The time when the player last called the get state function
8987
Handsumary string // store the hand summary form for sending via JSON to 8 bit computers the
9088
}
@@ -825,9 +823,8 @@ func EndofRoundScore(tableIndex int) {
825823
fmt.Println("------------- End of round summary ------------------")
826824
for i := 0; i < len(gameStates[tableIndex].Players); i++ {
827825
{
828-
a := 0
829-
b := 0
830-
c := 0
826+
WhiteTokens := 0
827+
BlackTokens := 0
831828
f1 := 0
832829
f2 := 0
833830
f3 := 0
@@ -841,57 +838,58 @@ func EndofRoundScore(tableIndex int) {
841838
case card.Cardvalue == 0:
842839
// do nothing
843840
case card.Cardvalue == 1 && f1 == 0:
844-
a = a + card.Cardvalue
841+
WhiteTokens = WhiteTokens + card.Cardvalue
845842
f1++
846843
case card.Cardvalue == 2 && f2 == 0:
847-
a = a + card.Cardvalue
844+
WhiteTokens = WhiteTokens + card.Cardvalue
848845
f2++
849846
case card.Cardvalue == 3 && f3 == 0:
850-
a = a + card.Cardvalue
847+
WhiteTokens = WhiteTokens + card.Cardvalue
851848
f3++
852849
case card.Cardvalue == 4 && f4 == 0:
853-
a = a + card.Cardvalue
850+
WhiteTokens = WhiteTokens + card.Cardvalue
854851
f4++
855852
case card.Cardvalue == 5 && f5 == 0:
856-
a = a + card.Cardvalue
853+
WhiteTokens = WhiteTokens + card.Cardvalue
857854
f5++
858855
case card.Cardvalue == 6 && f6 == 0:
859-
a = a + card.Cardvalue
856+
WhiteTokens = WhiteTokens + card.Cardvalue
860857
f6++
861858
case card.Cardvalue == 7 && f7 == 0:
862-
b++ // Llama is worth 1 black token (10 points)
859+
BlackTokens++ // Llama is worth 1 black token (10 points)
863860
f7++
864861
}
865862
}
866863

867-
c = a / 10
868-
b = b + c
869-
a = a - (c * 10)
870-
if (a + (b * 10)) == 0 {
864+
RoundScore := WhiteTokens + (BlackTokens * 10)
865+
866+
if RoundScore == 0 { // Player has no cards left in hand so score is 0 for this round and can return a token if they have one
871867
switch {
872868
case gameStates[tableIndex].Players[i].BlackTokens > 0:
873-
gameStates[tableIndex].Players[i].Message1 = gameStates[tableIndex].Players[i].Name + " finished with no cards, so scores zero points and is returning one black token"
874869
gameStates[tableIndex].Players[i].BlackTokens = gameStates[tableIndex].Players[i].BlackTokens - 1
875-
gameStates[tableIndex].Players[i].RoundScore = -10
870+
gameStates[tableIndex].Players[i].RoundScore = 0
876871
case gameStates[tableIndex].Players[i].WhiteTokens > 0:
877-
gameStates[tableIndex].Players[i].Message1 = gameStates[tableIndex].Players[i].Name + " finished with no cards, so scores zero points and is returning one white token"
878872
gameStates[tableIndex].Players[i].WhiteTokens = gameStates[tableIndex].Players[i].WhiteTokens - 1
879-
gameStates[tableIndex].Players[i].RoundScore = -1
873+
gameStates[tableIndex].Players[i].RoundScore = 0
880874
default:
881-
gameStates[tableIndex].Players[i].Message1 = gameStates[tableIndex].Players[i].Name + " finished with no cards, so scores zero points"
882875
gameStates[tableIndex].Players[i].RoundScore = 0
883876
}
884877
} else {
885-
gameStates[tableIndex].Players[i].RoundScore = a + (b * 10) // Calculate the round score
886-
gameStates[tableIndex].Players[i].Message1 = fmt.Sprintf("and gains %d white counters and %d black counters, scoring %d points", a, b, gameStates[tableIndex].Players[i].RoundScore)
887-
gameStates[tableIndex].Players[i].WhiteTokens = gameStates[tableIndex].Players[i].WhiteTokens + a
888-
gameStates[tableIndex].Players[i].BlackTokens = gameStates[tableIndex].Players[i].BlackTokens + b
878+
gameStates[tableIndex].Players[i].RoundScore = RoundScore
879+
gameStates[tableIndex].Players[i].WhiteTokens = gameStates[tableIndex].Players[i].WhiteTokens + WhiteTokens
880+
gameStates[tableIndex].Players[i].BlackTokens = gameStates[tableIndex].Players[i].BlackTokens + BlackTokens
889881

890882
}
891-
gameStates[tableIndex].Players[i].Score = gameStates[tableIndex].Players[i].Score + gameStates[tableIndex].Players[i].RoundScore // Update the player's total score
892-
gameStates[tableIndex].Players[i].Message2 = fmt.Sprintf("Total score is now %d points", gameStates[tableIndex].Players[i].Score)
883+
if gameStates[tableIndex].Players[i].WhiteTokens > 9 {
884+
gameStates[tableIndex].Players[i].BlackTokens = gameStates[tableIndex].Players[i].BlackTokens + int(gameStates[tableIndex].Players[i].WhiteTokens/10)
885+
gameStates[tableIndex].Players[i].WhiteTokens = gameStates[tableIndex].Players[i].WhiteTokens % 10
886+
}
887+
888+
gameStates[tableIndex].Players[i].Score = gameStates[tableIndex].Players[i].WhiteTokens + gameStates[tableIndex].Players[i].BlackTokens // Update the player's total score
889+
893890
}
894891
}
892+
895893
gameStates[tableIndex].LastMovePlayed = "Please view the results"
896894
gameStates[tableIndex].RoundOver = true // Set the round over flag to true to prevent multiple score calculations
897895
gameStates[tableIndex].Table.Status = 4

0 commit comments

Comments
 (0)