#include #include #include struct board { int width; int height; char *data; }; inline char board_get( struct board *b, int i, int j ) { if(i<0 || i>=b->width || j<0 || j>=b->height) return '.'; return b->data[b->width*j+i]; } inline void board_set( struct board *b, int i, int j, char c ) { if(i<0 || i>=b->width || j<0 || j>=b->height) return; b->data[b->width*j+i] = c; } inline int board_empty( struct board *b, int i, int j ) { return board_get(b,i,j)=='.'; } struct board * board_create( int width, int height ) { struct board *b = malloc(sizeof(*b)); b->width = width; b->height = height; b->data = malloc(sizeof(*b->data)*width*height); memset(b->data,'.',sizeof(*b->data)*width*height); int x = b->width/2-1; int y = b->height/2-1; board_set(b,x,y,'X'); board_set(b,x+1,y,'O'); board_set(b,x+1,y+1,'X'); board_set(b,x,y+1,'O'); return b; } struct board * board_copy( struct board *b ) { struct board *n = board_create(b->width,b->height); memcpy(n->data,b->data,sizeof(char)*b->width*b->height); return n; } void board_delete( struct board *b ) { free(b->data); free(b); } void board_print( struct board *b ) { int i,j; printf(" "); for(i=0;iwidth;i++) { printf("%2d",i); } printf("\n"); for(j=0;jheight;j++) { printf("%2d",j); for(i=0;iwidth;i++) { printf(" %c",board_get(b,i,j)); } printf("\n"); } } /* Return true if a move to i,j is valid for the given color ('X' or 'O'), otherwise return false. */ int board_move_is_valid( struct board *b, int i, int j, char color ) { return 0; } /* A piece of the given color has just been played at i,j. In the direction di,dj flip any pieces of the opposite color that are surrounded. For example di,dj=(-1,0) means proceed west, and di,dj=(1,1) means proceed northwest. */ void board_fliprow( struct board *b, int i, int j, int di, int dj, char color ) { } /* Place a piece of the given color at i,j, then flip the pieces in all eight straight and diagonal directions. */ void board_move( struct board *b, int i, int j, char color ) { } /* Compute the simple score of a board, which is +1 for each X and -1 for each O. */ int board_score( struct board *b ) { } /* Compute the recursive Minimax score of a board for the player 'color'. */ int board_evaluate( struct board *b, char color, int depth ) { } /* Determine the best move for player 'color', and return it in besti,besti. Simultaneously return the recursive Minimax score for that move. */ int board_find_best_move( struct board *b, char color, int depth, int *besti, int *bestj ) { *besti=-1; *bestj=-1; return 0; } /* Put it all together: print the board, compute the next move, get the user's move, and repeat... */ int main( int argc, char *argv [] ) { return 0; }