Skip to content

Instantly share code, notes, and snippets.

@b-adams
Last active December 14, 2015 16:18
Show Gist options
  • Save b-adams/5113620 to your computer and use it in GitHub Desktop.
Save b-adams/5113620 to your computer and use it in GitHub Desktop.
Interface for CS345 Pente Game's model

What Gollum-in-the-closet responds to (without screaming)

  • Is ___ a legal place to move? / Is ___ a legal move? (yes/no)
  • Place ___'s stone at ___ / Make move ____
  • // How many stones has player ___ captured? (0 through 10)
  • Who has won the game? (White/Black/Nobody yet)
  • Whose turn is it? (White/Black)
  • What piece is at location _____? (White/Black/Empty)
  • How wide is the board?

Low priority:

  • Max adjacent stones of stone ___? (0-4) [For user-assistance coloring purposes, still allowing sneaky XX-XX wins.]
  • Is player ___ one stone away from winning?
// CS345CoordinateInterface.h
#import <Foundation/Foundation.h>
@protocol CS345CoordinateInterface <NSObject>
@property (readonly, assign) int x;
@property (readonly, assign) int y;
-(id)initWithX:(int) initialX andY:(int) initialY;
+(id)coordinateWithX:(int) initialX andY:(int) initialY;
@end
// CS345MoveInterface.h
#import <Foundation/Foundation.h>
#import "CS345CoordinateInterface.h"
typedef enum {
CS345NOBODY,
CS345PlayerBlack,
CS345PlayerWhite
} CS345PlayerID;
@protocol CS345MoveInterface <CS345CoordinateInterface> //Every move is also a location
@property (readonly, assign) CS345PlayerID player;
-(id)initWithPlayer:(CS345PlayerID) who atX:(int) initialX andY:(int) initialY;
+(id)moveWithPlayer:(CS345PlayerID) who atX:(int) initialX andY:(int) initialY;
+(id)moveWithPlayer:(CS345PlayerID) who atLocation:(id<CS345CoordinateInterface>) location;
@end
// CS345PenteGameModelInterface.h
#import <Foundation/Foundation.h>
#import "CS345MoveInterface.h"
#import "CS345CoordinateInterface.h"
@protocol CS345PenteGameModelInterface <NSObject>
// Is ___ a legal place to move? / Is ___ a legal move? (yes/no)
-(BOOL) isLegalMove:id<CS345MoveInterface> aMove;
// Place ___'s stone at ___ / Make move ____
-(BOOL) makeMove:id<CS345MoveInterface> aMove;
// How many stones has player ___ captured? (0 through 10)
-(int) capturesByPlayer:(CS345PlayerID) player;
// Who has won the game? (White/Black/Nobody yet)
-(CS345PlayerID) whoIsWinner;
// Whose turn is it? (White/Black)
-(CS345PlayerID) whoseTurnIsIt;
// What piece is at location _____? (White/Black/Empty)
-(CS345PlayerID) whosePieceIsAt:id<CS345CoordinateInterface> aLocation;
// How wide is the board?
-(int) boardWidth;
# Low priority:
// Max adjacent stones of stone ___? (0-4) [For user-assistance coloring purposes, still allowing sneaky XX-XX wins.]
-(int)longestChainForStoneAt:id<CS345CoordinateInterface> aLocation;
// Is player ___ one stone away from winning?
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment