Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with this. It is c code! This is my 3rd time posting because no one can help. Description This homework project involves

I need help with this. It is c code! This is my 3rd time posting because no one can help. image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Description This homework project involves creating a program to play the game of connect 41 The core concept is that two players, for us that will be the User and a randomized computer function, have their own colored discs: Red or Black. On each of their tums, they choose a column to put their colored disc into if that column isn't full. Their disc slides to the lowest row of that column that it can sit within, and the next player takes their turn. This game continues until a player has placed 4 of their colored discs adjacently upon which they win, or, if there are no more spaces in which the players can put a disc the game ends in a draw. The grid used for this game has 6 rows and 7 columns. Connect Four CRE Ford The goal of our program will be to start up, then begin with a round of connect 4 where the player is asked for their name and which color they would like to play as. Then, they take their first move, the computer will randomly choose a spot to move, and this continues until the game ends in a draw or either the player or computer wins. For our purposes here, only vertical and horizontal victories need to be accounted for. Diagonal victories will be counted as bonus work. Once the game has ended, the results should be printed to a file for prosperity. Our main function will contain a loop that asks if the player wants to play again after the game ends. if not the program will come to an end. If so, then our playConnect40 function should be called again with a new round started up from the beginning, such as asking for the players name as a new player may involve themselves in the second round. Your program must define the following functions as directed: ( 7pts) int main() - Your main function should call the playConnect40 function and have a loop that allows a player to play another round if they want to. ( 20pts) void playConnect40 - This is the main play function of the program and should accomplish the following: Ask for the players name, ask which symbol the player wants to use 'B', 'R', or random. Thus setting the player symbol to the one chosen and the computer symbol to the opposite. Then, the game play loop should begin. The player should take their turn, then the game is checked for possible game end states before the computer takes its turn and the game end states are checked again. This continues until a game end state is reached with the result being printed to a file. ( 15pts ) void player Turn(char board[10, char name[], char playerSymbol, int moves) in this function, the player is prompted to pick a valid move to add their piece. In connect 4 the pieces slide to the lowest row of a column, so the player should only need to pick a column and you will find the lowest position such that their symbol can be added. If they pick an incorrect position, the terminal should be cleared and reprinted with the question asking for a valid move asked once again. ( 8pts ) int game Win(char board[][], char symbol) This function should check the board to see if there are 4 consecutive symbols either horizontally or vertically. If there are, then it returns 1, if not, it returns 0. It should also check if there are any spaces in the board that are still open ("O'char instead of 'R' or 'B') as if all spaces are taken, the game is also over. If no spaces are left, it should return 2. ( 4pts ) void getName(char name) Get the users name from them that will be printed to the screen and eventually used for storing the game result to a file. ( 8pts ) void compMove(char board/10, char compColor) In this function, a position should be randomly chosen for the computers symbol to be added. Make sure a position that is empty is the final choice before updating the board and recall that in connect 4 the pieces slide down to the lowest row of that column. ( 4pts ) void clearBoard(char board[10) This function. when run, should set each position of the board to be 'O chars, which are our blank/unused spaces. (2pts ) void clearScreen() Should be called to clear the console screen after a player has finished their current turn and before the next one starts. The command for this is: "system("cls"); (use "system("clear") for unix machines) . . ( 4pts ) void printBoard(char board(0, char playerName[], int moves) - prints the game board to the terminal in a neat readable fashion. The name of the player and how many moves they've made so far should be displayed above this print out. (12pts ) void print2File(char board[](), char playerName[], int moves, int gameState) - This function should be passed the playing board, the player name, and the number of moves they've made. The board, moves, and a time stamp be appended to a "*.txt" file with the name of the player replacing the *. Thus, if the name "John" is entered, this function should open a file called "John.txt" for appending and add a time stamp, number of moves made during the game, along with who won (player loses, player wins, it's a draw), and the game board itself. The games appended to the file should be distinguishable from prior games (so add some new lines to space them out). The time stamp for print2File can be done with the following code (have as one of your included libraries): the_t timestamp = time(NULL); printf("%s , asctime(gmtime(×tamp))); Further Directions: - The submission for this project should be the files: "main.c", "connect4.h", and "connect4.c". (2pts ) - Program header comment: 1. Name, 2. Date, 3. Course, 4. Assignment # and Title, 5. Description ( 4pts) for properly adding a short comment to each function and comments for larger code segments in more complex functions (such as playconnect4 and player Move). TOTAL: 90 pts Nicer terminal printing option: playerName #moves [0|0|0|0|0|0|0] [0|0|0|0|R|0|0] [ 0100 0 R100] [0|0| BORBO] [ 0 BRB BRL 0] [ RIB R RIB B 0 ] (1) (2) (3) (4) (5) (6) (7) The bottom row of numbers informs the player of which column is which value during their move (can use 0-6 if you don't want to adjust the input choice by 1) Description This homework project involves creating a program to play the game of connect 41 The core concept is that two players, for us that will be the User and a randomized computer function, have their own colored discs: Red or Black. On each of their tums, they choose a column to put their colored disc into if that column isn't full. Their disc slides to the lowest row of that column that it can sit within, and the next player takes their turn. This game continues until a player has placed 4 of their colored discs adjacently upon which they win, or, if there are no more spaces in which the players can put a disc the game ends in a draw. The grid used for this game has 6 rows and 7 columns. Connect Four CRE Ford The goal of our program will be to start up, then begin with a round of connect 4 where the player is asked for their name and which color they would like to play as. Then, they take their first move, the computer will randomly choose a spot to move, and this continues until the game ends in a draw or either the player or computer wins. For our purposes here, only vertical and horizontal victories need to be accounted for. Diagonal victories will be counted as bonus work. Once the game has ended, the results should be printed to a file for prosperity. Our main function will contain a loop that asks if the player wants to play again after the game ends. if not the program will come to an end. If so, then our playConnect40 function should be called again with a new round started up from the beginning, such as asking for the players name as a new player may involve themselves in the second round. Your program must define the following functions as directed: ( 7pts) int main() - Your main function should call the playConnect40 function and have a loop that allows a player to play another round if they want to. ( 20pts) void playConnect40 - This is the main play function of the program and should accomplish the following: Ask for the players name, ask which symbol the player wants to use 'B', 'R', or random. Thus setting the player symbol to the one chosen and the computer symbol to the opposite. Then, the game play loop should begin. The player should take their turn, then the game is checked for possible game end states before the computer takes its turn and the game end states are checked again. This continues until a game end state is reached with the result being printed to a file. ( 15pts ) void player Turn(char board[10, char name[], char playerSymbol, int moves) in this function, the player is prompted to pick a valid move to add their piece. In connect 4 the pieces slide to the lowest row of a column, so the player should only need to pick a column and you will find the lowest position such that their symbol can be added. If they pick an incorrect position, the terminal should be cleared and reprinted with the question asking for a valid move asked once again. ( 8pts ) int game Win(char board[][], char symbol) This function should check the board to see if there are 4 consecutive symbols either horizontally or vertically. If there are, then it returns 1, if not, it returns 0. It should also check if there are any spaces in the board that are still open ("O'char instead of 'R' or 'B') as if all spaces are taken, the game is also over. If no spaces are left, it should return 2. ( 4pts ) void getName(char name) Get the users name from them that will be printed to the screen and eventually used for storing the game result to a file. ( 8pts ) void compMove(char board/10, char compColor) In this function, a position should be randomly chosen for the computers symbol to be added. Make sure a position that is empty is the final choice before updating the board and recall that in connect 4 the pieces slide down to the lowest row of that column. ( 4pts ) void clearBoard(char board[10) This function. when run, should set each position of the board to be 'O chars, which are our blank/unused spaces. (2pts ) void clearScreen() Should be called to clear the console screen after a player has finished their current turn and before the next one starts. The command for this is: "system("cls"); (use "system("clear") for unix machines) . . ( 4pts ) void printBoard(char board(0, char playerName[], int moves) - prints the game board to the terminal in a neat readable fashion. The name of the player and how many moves they've made so far should be displayed above this print out. (12pts ) void print2File(char board[](), char playerName[], int moves, int gameState) - This function should be passed the playing board, the player name, and the number of moves they've made. The board, moves, and a time stamp be appended to a "*.txt" file with the name of the player replacing the *. Thus, if the name "John" is entered, this function should open a file called "John.txt" for appending and add a time stamp, number of moves made during the game, along with who won (player loses, player wins, it's a draw), and the game board itself. The games appended to the file should be distinguishable from prior games (so add some new lines to space them out). The time stamp for print2File can be done with the following code (have as one of your included libraries): the_t timestamp = time(NULL); printf("%s , asctime(gmtime(×tamp))); Further Directions: - The submission for this project should be the files: "main.c", "connect4.h", and "connect4.c". (2pts ) - Program header comment: 1. Name, 2. Date, 3. Course, 4. Assignment # and Title, 5. Description ( 4pts) for properly adding a short comment to each function and comments for larger code segments in more complex functions (such as playconnect4 and player Move). TOTAL: 90 pts Nicer terminal printing option: playerName #moves [0|0|0|0|0|0|0] [0|0|0|0|R|0|0] [ 0100 0 R100] [0|0| BORBO] [ 0 BRB BRL 0] [ RIB R RIB B 0 ] (1) (2) (3) (4) (5) (6) (7) The bottom row of numbers informs the player of which column is which value during their move (can use 0-6 if you don't want to adjust the input choice by 1)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Azure SQL Database For Modern Developers Building Applications In The Microsoft Cloud

Authors: Davide Mauri, Silvano Coriani, Anna Hoffma, Sanjay Mishra, Jovan Popovic

1st Edition

1484263693, 978-1484263693

More Books

Students also viewed these Databases questions