This is Rules.m in view mode; [Download] [Up]
/* * Rules * description: abstract superclass for a rules object for board games * history: * 2/15/93 [Erik Kay] - created * 6/13/93 [Erik Kay] - made into abstract superclass */ #import "Rules.h" @implementation Rules - init { [super init]; initialBoard = nil; return self; } // return a list of boards that define the available moves for the player // with the board specified - (List *)validMoves:(Board *)b forPlayer:(square_state)piece { return nil; } // is a given move valid? - (BOOL)validMove:(move *)mv onBoard:(Board *)b { return NO; } // actually do a move on a board - doMove:(move *)mv onBoard:(Board *)b { return self; } // undo the last move - (Board *)undoMove:(move_list *)mvlist { return nil; } // set the initial board. This is what should be used by undo. Also, // a good optimization strategy is to build up a list of valid moves on the // board into a table from this initial board. - setInitialBoard:(Board *)b { if (initialBoard) [initialBoard free]; initialBoard = [b trueCopy]; return self; } // does this player have any available moves? - (BOOL)gameOver:(Board *)b forPlayer:(square_state)player { return YES; } // who is the winner of the game - winner:game { return nil; } @end
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.