Checkers and Hexchequer now detect victory when the other player can't move.
5 // Created by Jens Alfke on 7/3/08.
6 // Copyright 2008 Jens Alfke. All rights reserved.
18 /** Game API for subclasses to use / override */
19 @interface Game (Protected)
21 /** Should return a string describing the initial state of a new game.
22 The default value is an empty string. */
23 - (NSString*) initialStateString;
26 #pragma mark Abstract methods for subclasses to implement:
28 /** Called by -setBoard: Should all all necessary Grids/Pieces/Cards/etc. to _board.
29 This method is always called during initialization of a new Game, and may be called
30 again afterwards, for example if the board area is resized. */
33 /** Should return the winning player, if the current position is a win, else nil.
34 Default implementation returns nil. */
35 - (Player*) checkForWinner;
38 #pragma mark Protected methods for subclasses to call:
40 /** Sets the number of players in the game. Subclass initializers should call this. */
41 - (void) setNumberOfPlayers: (unsigned)n;
43 /** Animate a piece moving from src to dst. Used in implementing -applyMoveString:. */
44 - (BOOL) animateMoveFrom: (CALayer<BitHolder>*)src to: (CALayer<BitHolder>*)dst;
46 /** Animate a piece being placed in dst. Used in implementing -applyMoveString:. */
47 - (BOOL) animatePlacementIn: (CALayer<BitHolder>*)dst;
49 /** Checks for a winner and advances to the next player. */
55 /** Optional Game API for tracking the history of a game, and being able to replay moves. */
56 @interface Game (State)
58 /** A string describing the current state of the game (the positions of all pieces,
59 orderings of cards, player scores, ... */
60 @property (copy) NSString* stateString;
62 /** Add a move to the game based on the contents of the string.
63 The string must have been returned by -currentMove at some point. */
64 - (BOOL) applyMoveString: (NSString*)move;
66 /** An optional method called as a subroutine by -[Grid setStateString:].
67 If you decide to call that in your -setStateString: implementation, you need to implement this too. */
68 - (Piece*) makePieceNamed: (NSString*)name;