Question
This week you will be modifying your playMove function to only accept certain moves. The game you are making is Othello (if you have not
This week you will be modifying your playMove function to only accept certain moves. The game you are making is Othello (if you have not guessed already). The objective of this game is to have the most pieces of your color on the board when the game finishes. You gain points by placing pieces of your color on the board and flanking (capturing) your opponents pieces. The rules are as follows: 1. A piece (either a 'B' or 'W' in the case of our game) cannot be placed on top of a previously placed piece. The space must be empty. 2. If on your turn you cannot outflank and flip at least one opposing piece, your turn is forfeited and your opponent moves again. If a move is available to you, you may not forfeit your turn. 3. A piece may outflank any number of pieces in one or more rows in any number of directions at the same time - horizontally, vertically or diagonally. (A row is defined as one or more pieces in a continuous straight line). See Figures 1 and 2.
THE TEMPLATE OF THE PROJECT IS GIVEN BELOW
// hw6.c: Assignment #6 template #include//Standard Library #include //Board Size Constant #define BOARD_SIZE 8 //Board Space Constants #define EMPTY_SPACE 0 #define P1_SPACE 1 #define P2_SPACE 2 //Player Constants #define PLAYER1 1 #define PLAYER2 2 //Alignment Constants #define HOR_ALIGN 3 #define VERT_ALIGN 4 #define DIAG_ALIGN 5 // function prototypes: // All these three printBoard function prototypes are equivalent void printBoard(int board[BOARD_SIZE][BOARD_SIZE]); // OK // void printBoard(int board[][BOARD_SIZE]); // Good // void printBoard(int (* board)[BOARD_SIZE]); // Good int validateInput(); // All these three printMove function prototypes are equivalent int playMove(int x, int y, int PLAYER, int board[BOARD_SIZE][BOARD_SIZE]); // OK // int playMove(int x, int y, int PLAYER, int board[][BOARD_SIZE]); // Good //int playMove(int x, int y, int PLAYER, int (* board)[BOARD_SIZE]); // Good int gameOver(int board[BOARD_SIZE][BOARD_SIZE]); int getAlignment(int x1, int y1, int x2, int y2); int main(void){ // ..... int board[BOARD_SIZE][BOARD_SIZE]; //Game Board Variable // use a do-while or while loop here // do{ // ... //Getting Player Input int x, y; printf(" "); printf("Enter X coordinate: "); x = validateInput(); printf("Enter Y coordinate: "); y = validateInput(); playMove(x, y, playersTurn, board); // Place Move on Board printBoard(board); // function call // }while(!gameOver(board)); //Loop while the game is not over return 0; } void printBoard(int board[BOARD_SIZE][BOARD_SIZE]) // OK // void printBoard(int board[][BOARD_SIZE]) // Good //void printBoard(int (* board)[BOARD_SIZE]) // Good { //Display the game board here } //To be changed in XGame Week 5 Assignment int playMove(int x, int y, int PLAYER, int board[BOARD_SIZE][BOARD_SIZE]) // OK // int playMove(int x, int y, int PLAYER, int board[][BOARD_SIZE]) // Good // int playMove(int x, int y, int PLAYER, int (* board)[BOARD_SIZE]) // Good { //Set board to either P1_SPACE or P2_SPACE here return 1; } int gameOver(int board[BOARD_SIZE][BOARD_SIZE]){ //Find if there are any valid moves to be played by either PLAYER1 or PLAYER2 //If there are any valid moves, return 1 //else, return 0 return 0 } int getAlignment(int x1, int y1, int x2, int y2){ //Find alignment between two points //Return HOR_ALIGN, VERT_ALIGN, or DIAG_ALIGN return 0; } int validateInput(){ int num; // validate input here return num; }
These DIse discs placed tipped Figure 1 Figure 2 4. You may not skip over your own color piece to outflank an opposing piece. (See Figure (Continued on next page) ECE114 Intro to C/C++ Programming Spring 2017 This dike only outlankt and flp Whlte dise 1 Figure 3 5. Pieces may only be outflanked as a direct resultof a move and must fall in the direct line of the piece placed down. (See Figure 4 and 5) Disc These dltat flipped Thoso dises re not fipped even though hey appear to Figure 4 be outlankod) Figure 5 6. All pieces outflanked in any one move must be flipped, even if it is to the player's advantage not to flip them at all. 7. If player tries to play an invalid move, their turn is skipped and no points are added or deducted. 8. When it is no longer possible for either player to move, the game is over. The player with the most pieces ('B' or 'W' on the board) is the winner. Your job is to implement these rules inside the playMove function. You playMove function should return the number of pieces gained by that move (including the one placed by that player).These are the points that should be added to the user's score. Next you need to declare a new function called game0ver. This function takes the board as a parameter and returns either 1 (true) or 0 (false) ifthe game is over. Your playMove function and gameover function will look very similar. The playMove function checks if a certain move is valid by a player, whereas the gameover function will look at all remaining moves (empty spaces) and see if any are valid by any player. The game0ver function will replace the condition currently in your game loop. (Instead of asking the user to enter an integer, the computer will check if the game is over, and choose to continue or not). You should be able to impl ement this function with the game rules described above. You may refer to the ate at ECE114 Blackboard. you would like to play rogram tema this game online to get a better feel for it, you may play it here http://www.othelloonline.org/
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started