Blef-team / blef_game_engine

The game engine API service for the game of Blef
GNU Affero General Public License v3.0
1 stars 0 forks source link

Don't deal cards if game is finished #100

Closed adrian-golian closed 4 years ago

adrian-golian commented 4 years ago

When the game status is finished, the last remaining player (winner) still gets cards. Return an empty array for the hands.

maciej-pomykala commented 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.

maciej-pomykala commented 4 years ago

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.

maciej-pomykala commented 4 years ago

Just to be clear, that is still a problem.

I believe the problem is caused by two things:

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.

maciej-pomykala commented 4 years ago

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.

adrian-golian commented 4 years ago

This makes sense. Let's go ahead with that.