Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C Program for The Game of Battleship: Develop a program that plays a game of Battleship. The game is intended to be played between one

C Program for The Game of Battleship: Develop a program that plays a game of Battleship. The game is intended to be played between one player and the computer. Basic Rules for the Game: The game is played on four grids, two for each player (however, since one of the players is the computer, the computers two grids are hidden from view). The grids are 10x10 square. The individual squares in the grid are identified by letter and number. On the major grid the player arranges ships and records the shots by the opponent. On the minor grid the player records his/her own shots. Before play begins, each player secretly arranges their ships on their major grid. Each ship occupies a number of consecutive squares on the grid, arranged either horizontally, vertically or diagonally (we will ignore Pythagoras for this project). The number of squares for each ship is determined by the type of the ship. The ships cannot overlap (i.e. only one ship can occupy any given square on the grid). The types and numbers of ships allowed are the same for each player. Although the player may decide their own ship types and sizes, here are some example ship types and sizes Requirements: In particular, your program should satisfy the following requirements: To begin the game the computer will ask how many ships each side is given, or optionally, provide a file name to read in the information. The ships are represented as variables of type ship and page1image3743024a page1image3737824is a assignment. home / study / engineering / computer science / computer science questions and answers / the game of battleship: your task is to develop a program that plays a game of battleship. ... Your question has been answered Let us know if you got a helpful answer. Rate this answer Question: The Game of Battleship: Your task is to develop a program that plays a game of Battleship. The ga... The Game of Battleship: Your task is to develop a program that plays a game of Battleship. The game is intended to be played between one player and the computer. Basic Rules for the Game: The game is played on four grids, two for each player (however, since one of the players is the computer, the computers two grids are hidden from view). The grids are 10x10 square. The individual squares in the grid are identified by letter and number. On the major grid the player arranges ships and records the shots by the opponent. On the minor grid the player records his/her own shots. Before play begins, each player secretly arranges their ships on their major grid. Each ship occupies a number of consecutive squares on the grid, arranged either horizontally, vertically or diagonally (we will ignore Pythagoras for this project). The number of squares for each ship is determined by the type of the ship. The ships cannot overlap (i.e. only one ship can occupy any given square on the grid). The types and numbers of ships allowed are the same for each player. Although the player may decide their own ship types and sizes, here are some example ship types and sizes Requirements: In particular, your program should satisfy the following requirements: 1. To begin the game the computer will ask how many ships each side is given, or optionally, provide a file name to read in the information. 2. The ships are represented as variables of type ship and is stored as linked list. Using linked lists is a requirement for this assignment. typedef struct ship { char shiptype[20]; int shipsize; int X Location; int Y Location; int X Hit; int Y Hit; struct ship pt; } ship; You are allowed to add attributes to this definition, but not remove any. Ship Type Board Symbol Ship Size Aircraft Carrier A 5 Battleship B 4 Cruiser C 3 Submarine S 3 Patrol Boat P 2 Kayak K 1 Row boat R 1 For each ship added a new node is created in the linked list. The player will be given the option to fill out the structure information at the beginning of the game, or read in the information from a file. The information to be entered is: ship type ship size X-location Y-location Other attribute information of your choice. The computer will place the same type, and number of ships, at locations of his own choosing. Use a random X,Y location for the bow of the ship. The remaining X,Y values must be in a horizontal, vertical, or diagonal sequence. No X,Y values of the ship may be off grid. Your program must check for this and not allow players to break this rule. Ship positions may not overlap. The player is given the first turn to shoot, then the computer takes his turn. The game continues in rounds until all ships of one contestant are destroyed. The player with at least one surviving ship (i.e. one un-hit X,Y location on at least one ship) is declared the winner. Once the game begins each shot is recorded. Both 10x10 grids for the human player are updated with each shot. When a ship is hit the attributes X hit and Y hit are updated. These attributes are used to update the 10x10 grids during play. On the minor grid a record of each shot is kept, using different symbols for a hit/miss. On the major grid a record of the computers shots are recorded. Again, using different symbols for a hit/miss. The computer will choose his shot locations randomly. After each turn the score is updated and displayed. The scoreboard should display (at a minimum) Each players name. The number of hits each player has scored. The number of missed attempts for each player. The number of sunk ships each player has scored. Once a ship is destroyed the node must be removed from the linked list. However, even though the ship is removed from the linked list, the major and minor grids continue to display the results of the sunken ship. Your C program must keep track of both players information. Thus two linked lists are needed, one for each player. At the end of the game the major grids of both players are revealed. Optional Features for Extra Credit: Patterned Search. The computer does not shoot randomly but uses a search pattern to determine his next shot. Upon a hit the computer searches the immediate area until a ship is sunk. Sonar. If a submarine is in the game then a player may choose to use sonar. Upon choosing to ping A single X,Y location of an enemy ship is shown on the players major grid using a sonar location symbol O. This symbol remains on the players major grid for 1 turn only. Since using sonar reveals position information, the player using sonar gives up a single X, Y location of his/her submarine. Sonar does not reveal the orientation of the ships. It merely reveals a single X, Y location per player. A sunk submarine cannot ping so the option is removed if no submarine is present. A submarine may ping only once per game. A ping costs the player 1 turn. Your C program displays the sonar option only when it is an available choice. Abandon Ship. If a large ship (size 3 or greater) is about to be sunk (i.e. has only one remaining un-hit X,Y location) a player may choose to Abandon Ship. Upon abandoning a ship The ship with the remaining X,Y location is forfeit/sunk; since an abandoned ship cannot participate in the battle. As a result of the sunk ship it must be removed from the linked list. The abandon ship turns into two kayaks. Two Kayak nodes, each of size 1, are added to the players linked list. The X,Y location of the Kayaks are randomly placed on the players major grid. If the random position generator chooses an X,Y location that has already been used then that Kayak is automatically eliminated. i.e. If the X,Y location is already occupied by another ship, or if the X,Y location has been previously targeted then the Kayak is eliminated. The opponent is informed that a player has used his/her turn to abandon ship. The abandon ship option may only be used once per game. Your C program displays the abandon ship option only when it is an available choice. 4. Torpedo. An undamaged submarine may choose to fire a torpedo. This option can only be used one time, per player, per game. The torpedo can only exit the bow of the submarine. Thus, in order to code this option you will need to determine how to distinguish, and keep track of, the submarines bow and stern. The torpedo travels in the same direction as the orientation of the submarine. The torpedo can travel up to 2 squares away from the end of the submarine. If the torpedo encounters a ship within 2 squares away from the submarine then a hit is registered. Note: The torpedo may damage friendly ships as well. If a player chooses to use their turn to fire a torpedo, then the message *** TORPEDO AWAY *** must flash on the screen at least three times. This message flashes also when the computer chooses to fire a torpedo. As the torpedo moves, the screen is updated to show the torpedos location. You are free to choose any symbol to represent the torpedo. If the torpedo does not score a hit the symbol disappears from the screen after it has traveled two squares away. Like sonar, using a torpedo reveals position information. The player using the torpedo gives up a single X, Y location of his/her submarine. Your C program displays the torpedo option only when it is an available choice. You should use more than one structure. Maybe a player structure as follows? typedef struct player { char name [20]; // players name int ShotsBoard[10][10];//Keep track of where the shots were taken int ShipsBoard[10][10];//Keep track of current ships int OrigShipsBoard[10][10];//Remember the original configuration int Hits;//Count how many hits int Miss;//Cont how many shots } player; C Program for The Game of Battleship: Develop a program that plays a game of Battleship. The game is intended to be played between one player and the computer. Basic Rules for the Game: The game is played on four grids, two for each player (however, since one of the players is the computer, the computers two grids are hidden from view). The grids are 10x10 square. The individual squares in the grid are identified by letter and number. On the major grid the player arranges ships and records the shots by the opponent. On the minor grid the player records his/her own shots. Before play begins, each player secretly arranges their ships on their major grid. Each ship occupies a number of consecutive squares on the grid, arranged either horizontally, vertically or diagonally (we will ignore Pythagoras for this project). The number of squares for each ship is determined by the type of the ship. The ships cannot overlap (i.e. only one ship can occupy any given square on the grid). The types and numbers of ships allowed are the same for each player. Although the player may decide their own ship types and sizes, here are some example ship types and sizes Requirements: In particular, your program should satisfy the following requirements: To begin the game the computer will ask how many ships each side is given, or optionally, provide a file name to read in the information. The ships are represented as variables of type ship and page1image3743024a page1image3737824is a assignment. home / study / engineering / computer science / computer science questions and answers / the game of battleship: your task is to develop a program that plays a game of battleship. ... Your question has been answered Let us know if you got a helpful answer. Rate this answer Question: The Game of Battleship: Your task is to develop a program that plays a game of Battleship. The ga... The Game of Battleship: Your task is to develop a program that plays a game of Battleship. The game is intended to be played between one player and the computer. Basic Rules for the Game: The game is played on four grids, two for each player (however, since one of the players is the computer, the computers two grids are hidden from view). The grids are 10x10 square. The individual squares in the grid are identified by letter and number. On the major grid the player arranges ships and records the shots by the opponent. On the minor grid the player records his/her own shots. Before play begins, each player secretly arranges their ships on their major grid. Each ship occupies a number of consecutive squares on the grid, arranged either horizontally, vertically or diagonally (we will ignore Pythagoras for this project). The number of squares for each ship is determined by the type of the ship. The ships cannot overlap (i.e. only one ship can occupy any given square on the grid). The types and numbers of ships allowed are the same for each player. Although the player may decide their own ship types and sizes, here are some example ship types and sizes Requirements: In particular, your program should satisfy the following requirements: 1. To begin the game the computer will ask how many ships each side is given, or optionally, provide a file name to read in the information. 2. The ships are represented as variables of type ship and is stored as linked list. Using linked lists is a requirement for this assignment. typedef struct ship { char shiptype[20]; int shipsize; int X Location; int Y Location; int X Hit; int Y Hit; struct ship pt; } ship; You are allowed to add attributes to this definition, but not remove any. Ship Type Board Symbol Ship Size Aircraft Carrier A 5 Battleship B 4 Cruiser C 3 Submarine S 3 Patrol Boat P 2 Kayak K 1 Row boat R 1 For each ship added a new node is created in the linked list. The player will be given the option to fill out the structure information at the beginning of the game, or read in the information from a file. The information to be entered is: ship type ship size X-location Y-location Other attribute information of your choice. The computer will place the same type, and number of ships, at locations of his own choosing. Use a random X,Y location for the bow of the ship. The remaining X,Y values must be in a horizontal, vertical, or diagonal sequence. No X,Y values of the ship may be off grid. Your program must check for this and not allow players to break this rule. Ship positions may not overlap. The player is given the first turn to shoot, then the computer takes his turn. The game continues in rounds until all ships of one contestant are destroyed. The player with at least one surviving ship (i.e. one un-hit X,Y location on at least one ship) is declared the winner. Once the game begins each shot is recorded. Both 10x10 grids for the human player are updated with each shot. When a ship is hit the attributes X hit and Y hit are updated. These attributes are used to update the 10x10 grids during play. On the minor grid a record of each shot is kept, using different symbols for a hit/miss. On the major grid a record of the computers shots are recorded. Again, using different symbols for a hit/miss. The computer will choose his shot locations randomly. After each turn the score is updated and displayed. The scoreboard should display (at a minimum) Each players name. The number of hits each player has scored. The number of missed attempts for each player. The number of sunk ships each player has scored. Once a ship is destroyed the node must be removed from the linked list. However, even though the ship is removed from the linked list, the major and minor grids continue to display the results of the sunken ship. Your C program must keep track of both players information. Thus two linked lists are needed, one for each player. At the end of the game the major grids of both players are revealed. Optional Features for Extra Credit: Patterned Search. The computer does not shoot randomly but uses a search pattern to determine his next shot. Upon a hit the computer searches the immediate area until a ship is sunk. Sonar. If a submarine is in the game then a player may choose to use sonar. Upon choosing to ping A single X,Y location of an enemy ship is shown on the players major grid using a sonar location symbol O. This symbol remains on the players major grid for 1 turn only. Since using sonar reveals position information, the player using sonar gives up a single X, Y location of his/her submarine. Sonar does not reveal the orientation of the ships. It merely reveals a single X, Y location per player. A sunk submarine cannot ping so the option is removed if no submarine is present. A submarine may ping only once per game. A ping costs the player 1 turn. Your C program displays the sonar option only when it is an available choice. Abandon Ship. If a large ship (size 3 or greater) is about to be sunk (i.e. has only one remaining un-hit X,Y location) a player may choose to Abandon Ship. Upon abandoning a ship The ship with the remaining X,Y location is forfeit/sunk; since an abandoned ship cannot participate in the battle. As a result of the sunk ship it must be removed from the linked list. The abandon ship turns into two kayaks. Two Kayak nodes, each of size 1, are added to the players linked list. The X,Y location of the Kayaks are randomly placed on the players major grid. If the random position generator chooses an X,Y location that has already been used then that Kayak is automatically eliminated. i.e. If the X,Y location is already occupied by another ship, or if the X,Y location has been previously targeted then the Kayak is eliminated. The opponent is informed that a player has used his/her turn to abandon ship. The abandon ship option may only be used once per game. Your C program displays the abandon ship option only when it is an available choice. 4. Torpedo. An undamaged submarine may choose to fire a torpedo. This option can only be used one time, per player, per game. The torpedo can only exit the bow of the submarine. Thus, in order to code this option you will need to determine how to distinguish, and keep track of, the submarines bow and stern. The torpedo travels in the same direction as the orientation of the submarine. The torpedo can travel up to 2 squares away from the end of the submarine. If the torpedo encounters a ship within 2 squares away from the submarine then a hit is registered. Note: The torpedo may damage friendly ships as well. If a player chooses to use their turn to fire a torpedo, then the message *** TORPEDO AWAY *** must flash on the screen at least three times. This message flashes also when the computer chooses to fire a torpedo. As the torpedo moves, the screen is updated to show the torpedos location. You are free to choose any symbol to represent the torpedo. If the torpedo does not score a hit the symbol disappears from the screen after it has traveled two squares away. Like sonar, using a torpedo reveals position information. The player using the torpedo gives up a single X, Y location of his/her submarine. Your C program displays the torpedo option only when it is an available choice. You should use more than one structure. typedef struct player { char name [20]; // players name int ShotsBoard[10][10];//Keep track of where the shots were taken int ShipsBoard[10][10];//Keep track of current ships int OrigShipsBoard[10][10];//Remember the original configuration int Hits;//Count how many hits int Miss;//Cont how many shots } player;

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

Beginning Microsoft SQL Server 2012 Programming

Authors: Paul Atkinson, Robert Vieira

1st Edition

1118102282, 9781118102282

More Books

Students also viewed these Databases questions

Question

9. System creates a large, diverse talent pool.

Answered: 1 week ago

Question

What is DDL?

Answered: 1 week ago