Closed adrian-golian closed 4 years ago
Are you sure the remaining player's cards are redrawn or do they just stay the way they were?
We don't erase cards at the end of the game, but I believe we don't redraw them either.
Just simulated a two-player game and, in the final state of the game, the winning player's cards stayed the way they were throughout the last round.
Just to be clear, that is still a problem.
I believe the problem is caused by two things:
hands
array; andn_cards
will be zero and their hand empty. But when the last round finishes, a player's number of cards is zeroed out (and jsonise_hands
starts avoiding the player) even though the player had cards earlier in the round.An elegant way would be to enable the API user to see the final state of the last round (with the losing player having their n_cards
equal to the maximum number of cards allowed and having a non-empty hand and the game state being "Running") by explicitly querying the last round and, separately, let the user see empty hands and status equal to "Finished" when querying the current state of the game.
I propose we do this. Currently we have:
if (round == -1 | round == current_r) {
r <- current_r
game <- readRDS(get_path(game_uuid))
} else {
r <- round
game <- readRDS(get_path(game_uuid, r))
}
I propose that round == current_r
will only return the current state of the game if status
is equal to "Running"
. If status
is equal to "Finished"
, a query about the last round will return its snapshot before the losing player is zeroed out. So:
if (round == -1 | (round == current_r & status == "Running")) {
r <- current_r
game <- readRDS(get_path(game_uuid))
} else {
r <- round
game <- readRDS(get_path(game_uuid, r))
}
...where status
will be obtained from the latest state of the game.
This makes sense. Let's go ahead with that.
When the game status is finished, the last remaining player (winner) still gets cards. Return an empty array for the hands.