#import //a few handy constants enum { EMPTY = -1, PLAYER_1 = 0, PLAYER_2 = 1, DIMENSION = 8, }; //a helper struct used for computing how many pieces are in each line typedef struct { int up_down; int left_right; int up_right_down_left; int up_left_down_right; } LineCounts; //a simple wrapper for returning the data board from this class typedef struct { int board[DIMENSION][DIMENSION]; } BoardStruct; @interface GameBoard : NSView { //our primary game board data structure int board[DIMENSION][DIMENSION]; //for keeping track of where the player can currently move //and highlighting board squares NSArray *currentPlayerMoves; //for keeping track of whose turn it is int playerMoving; //the bezier paths make it easy to determine if a piece is being moused over NSBezierPath *piecesPaths[DIMENSION][DIMENSION]; //handy ivars used with mouse-related events NSPoint hoveredCoord; NSPoint selectedCoord; //board specific attributes float squareDim; NSColor *playerColors[2]; NSColor *boardColors[2]; } //A few standard methods to override and get set up - (BOOL)acceptsFirstResponder; - (id)initWithFrame:(NSRect)frame; - (void)awakeFromNib; - (void)setFrame:(NSRect)frame; - (void)dealloc; //The workhorses - (void)mouseDown:(NSEvent*)event; - (void)mouseMoved:(NSEvent *)event; - (void)drawRect:(NSRect)rect; //Some domain specific methods - (NSRect)rectForBoardCoord:(NSPoint)p; - (NSColor*)squareColorForBoardCoord:(NSPoint)p; - (void)drawRectForBoardCoord:(NSPoint)p andHighlight:(BOOL)h; - (void)drawRectForBoardCoord:(NSPoint)p; - (NSBezierPath*)drawPieceForCoord:(NSPoint)p andPlayer:(int)player; - (NSPoint)boardCoordForClickPoint:(NSPoint)p; - (void)movePieceFromCoord:(NSPoint)p1 toCoord:(NSPoint)p2; - (void)drawBoardBackgroundInRect:(NSRect)rect; //New methods (not included in Part 1) that are related to generating moves - (BOOL)opponentInLineBetweenCoord:(NSPoint)c1 andCoord:(NSPoint)c2; - (LineCounts)lineCountsForSpot:(NSPoint)spot; - (NSArray*)validMovesFromSpot:(NSPoint)spot; - (NSArray*)validMovesFromSpot:(NSPoint)spot withBoard:(int[][])board; //New method (not included in Part 1) that is used to fetch the data board - (BoardStruct)board; @end