You are expected to complete this assignment individually. If you need help, you are invited to come to office hours and/or ask questions on piazza. Clarification questions about the assignments may be asked publicly. Once you have specific bugs related to your code, make the posts private.
This homework has several exercises. We are also providing you with some resources on printf and error handling for this assignment.
You should submit several files for this assignment ( tictactoe_funcs.h, tictactoe_funcs.c, othello_funcs.h, othello_funcs.c, tictactoe.c, othello.c and Makefile) in your subversion repository as directed below.
Because you are adding a second set of files to your directory, you need to add a second target to your Makefile. In your makefile, add another two lines (with a space between these and the ones already there).
tictactoe: tictactoe_funcs.h tictactoe_funcs.c tictactoe.c clang -Wall tictactoe_funcs.c tictactoe.c -o tictactoe othello: othello_funcs.h othello_funcs.c othello.c clang -Wall othello_funcs.c othello.c -o othello
Remember to make skeleton code so that your code will minimally execute. You must do this in case you do not complete your assignment. Our testing infrastructure needs to compile and execute even if you did not complete the entire assignment.
double surface_area_cylinder(double height, double radius) { // you may put an fprintf stating it's not implemented yet here. return 0.0; }
void print_othello_board( char board[8][8] ) { unsigned int i, j; for(i=0;i<8;i++) { for(j=0;j<8;j++) { printf("%c ",board[i][j]); } printf("\n"); } }
int main() { surface_area_cylinder(1.0, 5.0); // add the rest of the function calls here }
In this exercise, you will complete the code to implement tic-tac-toe. You will write individual functions as specified, as well as a play loop. All of those files will go into tictactoe-funcs.c. Then you will write a main function with both tests for each individual function as well as a call to the play loop to test the entire function.
For the play loop, you are implementing two humans playing against each other. This is the only configuration you will offer. You will see below that you will implement a computer player, and you will test that separately. However, you won't put that in the main play loop. You can write your own testing function for it (which an be in the form of an interactive play loop or explicit test function calls).
First copy over the following functions from the warmup:
In this function, player has just placed its piece in location row, col. Check to see if this makes player win the game. If the player has won, return 1. If not, return 0.
In this function, you, playing as the computer, decide upon a move. You are provided the board and what player you are playing for. You place one player character in an empty space, hopefully a space that will go towards winning the game. row and col are output parameters. Fill those variables in with the row and column of your move. Return 1 if you made a move, 0 if not (e.g. the board is full). It is up to you how sophisticated you make this - see how smart you can make it! You will not be graded on the sophistication of the computer moves - it is merely personal satisfaction if yours is awesome. If we can, we'll try to have a tournament of computers playing each other and determine a winner in the class with a prize. But no guarantees.
This is your game loop. Implement it with the following details:
In this exercise, you will complete the code to implement Othello. You will write individual functions as specified, as well as a play loop. All of those files will go into othello_funcs.c. Then you will write a main function with both tests for each individual function as well as a call to the play loop to test the entire function.
Initialize the board to the starting configuration. Most of the spaces should be '*' indicating that they are empty. The middle four slots are taken with white on the top left and bottom right and black in the bottom left and top right. See the game rules for a diagram.
In this function, check to see if it is a valid move. To be valid:
This is the crux of play. A piece has just been placed at row, col. You must go through all diagonals and rows aligned with that spot and flip over any pieces of the other color that need to be flipped. See the rules of Othello for when to flip pieces. Count how many pieces were flipped.
This function is called as the last check in place_piece - once it is determined that the move is valid in every other respect, then it places the piece and finds out how many pieces have been flipped. If the number is 0, then place_piece will remove the piece again and report an invalid move.
Upon the conclusion of the game, determine who won the game (the player with the most pieces on the board). Return the character of the winner. If it is a tie, return '*'.
In this function, you, playing as the computer, decide upon a move. You are provided the board and what player you are playing for. You need to make a single valid move. It is up to you how intelligent to make your computer. Return 1 if you made a move, 0 if not (e.g. the board is full). row and col are output parameters - put the row and column of your move into those variables.
You will not be graded on the sophistication of the computer moves - it is merely personal satisfaction if yours is awesome. If we can, we'll try to have a tournament of computers playing each other and determine a winner in the class with a prize. But no guarantees.
This is your game loop. Implement it with the following details:
$ svn added all of them (you only ever have to do this once for each file)
$ svn commit -m "hw3 complete"