Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Line 1 contains the dimensional of the game board. Line 2 to line 6 contains the initial state of the game The initial state of

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Line 1 contains the dimensional of the game board. Line 2 to line 6 contains the initial state of the game The initial state of the game is now considered to explain how the game evolve through "generations". As shown in the figure below, the board consists of grid of size 5 by 5 cells. Each of the cell contains either X or where: X represents the cell is active, and represents the cell is inactive. |(1) |(2) (3) (4) (5) 5 cell number (6) 6 |(7) |(8) (9)" (10) cells (11) (12) (13) (14) x |(16) (17) (18) |(19) (20) |(21) (22) |(23) (24) (25) From the initial state of the board, the next "generation of the board is obtained based on the status of each cell i.e. whether the cell is an active cell or an inactive cell, considering all the adjacent cells (horizontal, vertical and diagonal). So, for cell number 13, its neighboring cell includes cells 7, 8, 9, 12, 14, 17, 18 and 19. So, all the internal cells have 8 neighbors in total while the cells at the edges have less than that. The game evolves by applying the following rules to all the cells simultaneously: Game Description: You are going to make a simple game in C, which goes as follows: The game board is a 2-dimensional grid where the game starts with an initial state that is specified in a file state.txt. The sample content of the state.txt file contains only the part shown in the colored box below) looks like this: 5 5 Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 X Line 1 contains the dimensional of the game board. Line 2 to line 6 contains the initial state of the game. The initial state of the game is now considered to explain how the game evolve through "generations". As shown in the figure below, the board consists of grid of size 5 by 5 cells. Each of the cell contains either Xors, where: X represents the cell is active, and represents the cell is inactive. . ( (1) (2) (3) |(4) |(5) cell number (6) (7) |(8) (10) cells (11) |(12) (13) (14) 11251 |(16) (17) (18) (19) |(20) - (21) |(22) (23) (24) (25) From the initial state of the board, the next generation of the board is obtained sed on the status of each cell ie whether the cell is an active cell or an inactive cell, considering all the adjacent cells (horizontal, vertical and diagonal). So, for cell number 13, its neighboring cell Includes cells 7, 8, 9, 12, 14, 17, 18 and 19. So, all the internal cells have 8 neighbors in total while the cells at the edges have less than that. The game evolves by applying the following rules to all the cells simultaneously: 4 2/6 2. An active cell with more than 3 active neighboring cells becomes inactive. 3. An active cell with 2 or 3 active neighboring cells remains active in the next generation. 4. An inactive cell with exactly 3 active neighboring cells becomes an active cell. So, applying the above rules, the initial state of the board changes to: Generation: 1 1) 2) (a) KSM - (6) 7) 19) (10) 8) (11) (12) (14) (15) (13) . (16) (17) (19) (20) (18) - |(21) (22) (23) 24) (25) The next "generation" is as follows: Generation: 2 K2) 3) 4) (5) - - 6) 7) (8) (9) (10) (11) (15) (12) 13) (14) - (16) (17) (18) (19) (20) I (21) (22) (23) (24) 25) So, the above two states keep on repeating for this given initial state. Game instructions: When you run the program, at the very beginning, the program should ask for user name and date. This information would be used to display the list of players that have played the game and their associated scores. After entering this information, you will then get the initial state of the game from the file state.txt. Please make sure the input file name is exactly same as specified. The first line in the file contains the grid size specified by the number of rows followed by the number of columns The remaining lines in the file specifies the initial board state as shown in the example above. You will then ask the user to enter the number of "generations", you want the game to display the board state. For example, if the user enters 5 "generations", then after initial state, your program should display 5 "generations of game state. Each "generation should be clearly specified by the generation number. If for example, all the cells in the board are inactive in the 3rd generation, then you do not display the remaining generation(s). You can simply display the message as: After 3 generation, all cells in the board is inactive. If not all the cells are inactive and all the 5 "generations" (if our example) are displayed, then the program should ask the user if they want to display additional generation(s). If the user enters "yes", then the program should again ask the number of generation(s) to display and the process repeats. If the user enters "no", then the program should display the list of all the players (user name and date) that have played the games and the number of generations displayed for all the users. Programming requirements: Your program should extensively use the following concepts: 1) Files concepts should be used to get the initial state for each game and to save the players information including the number of generations produced for all the players. 2) The program should have at least the following functions: a. main(...): to call all other functions b. playerinfo...): to ask for player Information c. boardinitialization...): to initialize the board d. generations...); to apply the game rules to produce "generations" e displayGeneration...): to display the game (each "generation" including the initial state) f. readPlayersinformation...): to read players information and the generations displayed from the file. information will be passed to the function displayGameSummary ...). displayGameSummaryl...): to display the information of all players and the 41 4/6 Note: It is left to the student to decide the appropriate argument(s) in each function. Each function should be in separate C file. Please use the file name as the function name appending File at the end. For example, the C file that contains function playerInfo() will be assignmentoo_lastName_firstName_playerInfoFile.c 3) You need to use dynamic allocation to create a 2D array to create the initial state of the game. You need to pass the array via pointers to all functions and use pointer arithmetic in the array manipulate and display the array. Note: Whenever dynamic memory is allocated, you need to free that space before exiting the program. 4) Use Structure to contain play information. The fields of the structure should account for following information: a. Player's name b. Date c. Number of "generations" This structure would be used for allfile operation i.e. to write into the file and read from the file. You need to use pointer to the structure to display the game summary. The grading will be as follows: Correct file operation (both reading and writing) using structure. Usage of pointer to structure to pass argument Use of dynamic array to create 2D array. Freeing the dynamic memory used by the array. Use of pointer arithmetic in the array manipulation Use of pointer arithmetic to display array Correct tracking "generation" 1576 [25 Points] [10 Points] (10 Points] [5 Points) [30 Points] [15 Points) [5 Points] . . Line 1 contains the dimensional of the game board. Line 2 to line 6 contains the initial state of the game The initial state of the game is now considered to explain how the game evolve through "generations". As shown in the figure below, the board consists of grid of size 5 by 5 cells. Each of the cell contains either X or where: X represents the cell is active, and represents the cell is inactive. |(1) |(2) (3) (4) (5) 5 cell number (6) 6 |(7) |(8) (9)" (10) cells (11) (12) (13) (14) x |(16) (17) (18) |(19) (20) |(21) (22) |(23) (24) (25) From the initial state of the board, the next "generation of the board is obtained based on the status of each cell i.e. whether the cell is an active cell or an inactive cell, considering all the adjacent cells (horizontal, vertical and diagonal). So, for cell number 13, its neighboring cell includes cells 7, 8, 9, 12, 14, 17, 18 and 19. So, all the internal cells have 8 neighbors in total while the cells at the edges have less than that. The game evolves by applying the following rules to all the cells simultaneously: Game Description: You are going to make a simple game in C, which goes as follows: The game board is a 2-dimensional grid where the game starts with an initial state that is specified in a file state.txt. The sample content of the state.txt file contains only the part shown in the colored box below) looks like this: 5 5 Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 X Line 1 contains the dimensional of the game board. Line 2 to line 6 contains the initial state of the game. The initial state of the game is now considered to explain how the game evolve through "generations". As shown in the figure below, the board consists of grid of size 5 by 5 cells. Each of the cell contains either Xors, where: X represents the cell is active, and represents the cell is inactive. . ( (1) (2) (3) |(4) |(5) cell number (6) (7) |(8) (10) cells (11) |(12) (13) (14) 11251 |(16) (17) (18) (19) |(20) - (21) |(22) (23) (24) (25) From the initial state of the board, the next generation of the board is obtained sed on the status of each cell ie whether the cell is an active cell or an inactive cell, considering all the adjacent cells (horizontal, vertical and diagonal). So, for cell number 13, its neighboring cell Includes cells 7, 8, 9, 12, 14, 17, 18 and 19. So, all the internal cells have 8 neighbors in total while the cells at the edges have less than that. The game evolves by applying the following rules to all the cells simultaneously: 4 2/6 2. An active cell with more than 3 active neighboring cells becomes inactive. 3. An active cell with 2 or 3 active neighboring cells remains active in the next generation. 4. An inactive cell with exactly 3 active neighboring cells becomes an active cell. So, applying the above rules, the initial state of the board changes to: Generation: 1 1) 2) (a) KSM - (6) 7) 19) (10) 8) (11) (12) (14) (15) (13) . (16) (17) (19) (20) (18) - |(21) (22) (23) 24) (25) The next "generation" is as follows: Generation: 2 K2) 3) 4) (5) - - 6) 7) (8) (9) (10) (11) (15) (12) 13) (14) - (16) (17) (18) (19) (20) I (21) (22) (23) (24) 25) So, the above two states keep on repeating for this given initial state. Game instructions: When you run the program, at the very beginning, the program should ask for user name and date. This information would be used to display the list of players that have played the game and their associated scores. After entering this information, you will then get the initial state of the game from the file state.txt. Please make sure the input file name is exactly same as specified. The first line in the file contains the grid size specified by the number of rows followed by the number of columns The remaining lines in the file specifies the initial board state as shown in the example above. You will then ask the user to enter the number of "generations", you want the game to display the board state. For example, if the user enters 5 "generations", then after initial state, your program should display 5 "generations of game state. Each "generation should be clearly specified by the generation number. If for example, all the cells in the board are inactive in the 3rd generation, then you do not display the remaining generation(s). You can simply display the message as: After 3 generation, all cells in the board is inactive. If not all the cells are inactive and all the 5 "generations" (if our example) are displayed, then the program should ask the user if they want to display additional generation(s). If the user enters "yes", then the program should again ask the number of generation(s) to display and the process repeats. If the user enters "no", then the program should display the list of all the players (user name and date) that have played the games and the number of generations displayed for all the users. Programming requirements: Your program should extensively use the following concepts: 1) Files concepts should be used to get the initial state for each game and to save the players information including the number of generations produced for all the players. 2) The program should have at least the following functions: a. main(...): to call all other functions b. playerinfo...): to ask for player Information c. boardinitialization...): to initialize the board d. generations...); to apply the game rules to produce "generations" e displayGeneration...): to display the game (each "generation" including the initial state) f. readPlayersinformation...): to read players information and the generations displayed from the file. information will be passed to the function displayGameSummary ...). displayGameSummaryl...): to display the information of all players and the 41 4/6 Note: It is left to the student to decide the appropriate argument(s) in each function. Each function should be in separate C file. Please use the file name as the function name appending File at the end. For example, the C file that contains function playerInfo() will be assignmentoo_lastName_firstName_playerInfoFile.c 3) You need to use dynamic allocation to create a 2D array to create the initial state of the game. You need to pass the array via pointers to all functions and use pointer arithmetic in the array manipulate and display the array. Note: Whenever dynamic memory is allocated, you need to free that space before exiting the program. 4) Use Structure to contain play information. The fields of the structure should account for following information: a. Player's name b. Date c. Number of "generations" This structure would be used for allfile operation i.e. to write into the file and read from the file. You need to use pointer to the structure to display the game summary. The grading will be as follows: Correct file operation (both reading and writing) using structure. Usage of pointer to structure to pass argument Use of dynamic array to create 2D array. Freeing the dynamic memory used by the array. Use of pointer arithmetic in the array manipulation Use of pointer arithmetic to display array Correct tracking "generation" 1576 [25 Points] [10 Points] (10 Points] [5 Points) [30 Points] [15 Points) [5 Points]

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_2

Step: 3

blur-text-image_3

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

Moving Objects Databases

Authors: Ralf Hartmut Güting, Markus Schneider

1st Edition

0120887991, 978-0120887996

More Books

Students also viewed these Databases questions

Question

What is conservative approach ?

Answered: 1 week ago

Question

What are the basic financial decisions ?

Answered: 1 week ago