diff --git a/backend/gameLogic/game.go b/backend/gameLogic/game.go index dcb3b7f..3e85ed8 100644 --- a/backend/gameLogic/game.go +++ b/backend/gameLogic/game.go @@ -432,7 +432,12 @@ func (g *Game) newBlackCard() error { // Not thread safe, gives each player new cards func (g *Game) newWhiteCards() error { for pid, p := range g.PlayersMap { - cards, err := g.CardDeck.GetNewWhiteCards(uint(HandSize - len(p.Hand))) + numberOfCardsRequired := HandSize - len(p.Hand) + if numberOfCardsRequired < 0 { + continue + } + + cards, err := g.CardDeck.GetNewWhiteCards(uint(numberOfCardsRequired)) if err != nil { return errors.New(fmt.Sprintf("Cannot create game: %s", err)) } @@ -487,6 +492,11 @@ func (g *Game) StartGame() (RoundInfo, error) { g.newCzar() g.GameState = GameStateWhiteCardsBeingSelected + // Reset scores + for _, player := range g.PlayersMap { + player.Points = 0 + } + err = g.newWhiteCards() if err != nil { return RoundInfo{}, err @@ -596,6 +606,7 @@ func (g *Game) moveToCzarJudgingPhase() (CzarJudingPhaseInfo, error) { newHand := make(map[int]*WhiteCard) for _, playerCard := range player.Hand { + // Remove cards in current play from the hand found := false for _, card := range player.CurrentPlay { if card.Id == playerCard.Id { diff --git a/backend/gameLogic/game_test.go b/backend/gameLogic/game_test.go index a513685..e3baff2 100644 --- a/backend/gameLogic/game_test.go +++ b/backend/gameLogic/game_test.go @@ -850,6 +850,7 @@ func TestPlayingCardCausesCzarJudingPhase(t *testing.T) { for _, hand := range resp.CzarJudingPhaseInfo.PlayerHands.Hands { assert.NotNil(t, hand) + assert.Len(t, hand, 7) } } diff --git a/backend/game_in_game_test.go b/backend/game_in_game_test.go index a8bb594..23c2c4d 100644 --- a/backend/game_in_game_test.go +++ b/backend/game_in_game_test.go @@ -224,3 +224,6 @@ func (s *ServerTestSuite) TestPlayingCardInGame() { assert.NoError(t, err) assert.Equal(t, client.PlayerId, cardPlayedMsg.PlayerId) } + +// TODO: test czar can select a winner +// TODO: test czar can select a winner and cause a game to end diff --git a/cahfrontend/src/gameState/gameState.ts b/cahfrontend/src/gameState/gameState.ts index 6287cd0..ff7a342 100644 --- a/cahfrontend/src/gameState/gameState.ts +++ b/cahfrontend/src/gameState/gameState.ts @@ -335,10 +335,10 @@ class GameState { bodyText: x?.bodyText ?? "Cannot load this card :(", }; }); + this.onRoundStateChange?.(structuredClone(this.roundState)); this.lobbyState.gameState = GameStateCzarJudgingCards; this.onLobbyStateChange?.(structuredClone(this.lobbyState)); - this.onRoundStateChange?.(structuredClone(this.roundState)); this.onAllPlaysChanged?.( data.allPlays.map((x) => x.map((card) => {