chschu / HexaFlip

A hexagonal board game for two players
1 stars 1 forks source link

handle quitting out of turn correctly #4

Open chschu opened 11 years ago

chschu commented 11 years ago

If a player quits out of turn, i.e. after taking a turn, the other player may still play on. However, any move is rejected by GameCenter, because the "next player" is in an invalid state.

If the match has been created from an invite, and the inviter quits the match after taking his first turn, but before the invitee takes his first turn, this creates a match on the invitee side that cannot be deleted. This can only be fixed by setting the invitee's outcome programmatically, but not in the game.

The player should be notified that the opponent has quit, and the match should be ended, setting the outcomes properly. This should happen as soon as the player enters the match, or immediately if he already is in the match.

The scenario of both players quitting immediately after another must be considered, because a match can be quit from the GameCenter match selection.

The first quitting player loses the match, regardless of the tile count.

chschu commented 11 years ago

The invitee needs to invoke -participantQuitOutOfTurnWithOutcome: to make the match deletable again. This sets the invitee's participant status from GKTurnBasedParticipantStatusInvited to GKTurnBasedParticipantStatusDone, which is required to delete the match.

chschu commented 11 years ago

There seems to be no way to avoid that with turn based matches. This can only be avoided by allowing the empty participant slot (the inviter) to be populated again. There are two options:

  1. Switch to non-turn-based game. This would require some changes to the multiplayer code.
  2. Allow participants to quit and join mid-game. This would avoid the problems described above, but it would not fit the "privacy" of a two-player board game.

I assume the best way to go is to abandon turn-based gaming and going for a single "live" match instead.

chschu commented 11 years ago

Abandoning turn-based gaming doesn't fit either. It restricts users to a single game. Futhermore, that game is cancelled whenever the App is closed. This is not appropriate.

Turn-based matches will not be abandoned.

Out-of-turn quit can be handled by the GKTurnBasedEventHandlerDelegate. The method -handleTurnEventForMatch is invoked when the remote participant quits out of turn. The match outcome of the local participant can then be set to GKTurnBasedMatchOutcomeWon, and the match can be ended in turn.

chschu commented 11 years ago

The method -handleTurnEventForMatch is not reliable, some events may be lost if the App is not currently running.

Next solution candidate: Custom UI for the game list. This allows proper handling of all quitting scenarios, and might as well solve the undeletable match issue.

chschu commented 11 years ago

The match selection screen will include local games, so this will also include #3.