Country : Canada
Assignment Task
 

We have provided you with the game logic. We call read_ships_file to create a GameBoard for each player; then, we call read_attacks_file to get an Array of Position objects which represent the attack strategy of each player. If no attack strategy file is provided, the game controller generates 35 random attack positions and uses them instead. Each player's GameBoard's attack_pos method is called alternately with the other player's attacks (i.e., the Position objects), one player's attack, then the other's. The game ends on one of these two cases:
All of the ships of a player are sunk (as determined by the GameBoard's all_sunk? method)
The winner is that player's opponent.
One of the players runs out of attack moves
Every time its the second player's turn, the game controller checks both the attack strategy Arrays to see if there is any valid attack position left. If there is nothing left for one of the two players, the game doesn't go to the next round of attacks. We do the following to determine the winner.
Each GameBoard's num_successful_attacks method is called to compare success of each player. The player that has more successfull attacks will win the game.
You will see an output like the following:
....
....
Game result:
P1 success: 15, P2 success: 7
All player 2 ships sunk!

Yoo-hoooo!
Player 1 has won the game!
====================
Player-1 GameBoard
STRING METHOD IS NOT IMPLEMENTED
====================
Player-2 GameBoard
STRING METHOD IS NOT IMPLEMENTED
Notice that the to_s implementation is optional, but it's highly recommended. It helps with debugging your code. Here is an example with a to_s implemented
Game result:
P1 success: 15, P2 success: 7
All player 2 ships sunk!

Yoo-hoooo!
Player 1 has won the game!
====================
Player-1 GameBoard
1 2 3 4 5 6 7 8 9 10

====================
Player-2 GameBoard
1 2 3 4 5 6 7 8 9 10

In this example, B represents the ship, and A represents the attack made. If there is nothing, - is shown.
Part 1
In this part, you will complete the GameBoard class located in game_board.rb. Please keep in mind that Position coordinates start from 1 in our tests (not 0). Also, although the Battleship game require a 10X10 GameBoard, your code should work with any board size.

initialize(max_row, max_column)
Description: GameBoard initializer.
Please don't rename the instance variables as the game controller relies on this.
For the Battleship game, pass 10 for both row and column since that's how the game works. Your code in this calss should work with any baord size.
max_row and max_column define your GameBoard boundary. Use them accordingly.
add_ship(ship)
Description: Add a Ship to your GameBoard. Return whether it was successful or not.
Type: (Ship) -> Boolean
First check to see if you can add Ship to GameBoard. If you can't add it to the GameBoard, return false.
Check for the following rules
Ships can not overlap on the gameboard.
Ship must be inside the gameboard according to the starting_position and size
If you can add it, add it to your GameBoard and return true
attack_pos(position)
Description: Perform attack on the provided position. Return whether the attack was successful or not.
Type: (Position) -> Boolean
Check if Position is inside the boundary. If it's not, return nil.
Update your GameBoard accordingly, to note whether the attack was successful. Return whether the attack was successful or not: If it hit a Ship in the GameBoard, return true. Return false otherwise. (Note: Attacking the same Position is allowed. Follow the same rules for it.)
num_successful_attacks

Description: Return the number of succesfull attacks made by prior calls to attack_pos.
Type: () -> Int
Return the number of unique parts of ships that have been hit by attacks. In the example picture above, it'd be 4.
all_sunk?
Description: Return a boolean, whether all the ships sunk or not
Type: () -> Boolean
If all the ships are sunk (i.e., every part of every ship has been successfully attacked), return true. Return false otherwise.
to_s (optional)
Description: String representation of GameBoard
Type: () -> String
Implementing the to_s is optional but highly recommended. Here is a string example:
1 2 3 4 5 6 7 8 9 10

In this example, B represents the ship, and A represents the attack made. If there is nothing, - is shown.
Part 2
In this part, you will work on the input_controller.rb, and you will complete read_ships_file and read_attacks_file functions. First, let's understand the input file formats. Again, remember the starting position in a board is (1,1), and it's located in the upper left of the grid.
Input File Formats
There are two types of file formats
Ships Information
Attack Strategy
Ships Information File Format
Example:
(2,2), Right, 2
(8,5), Up, 3
(6,9), Left, 3
(7,2), Down, 2
(7,6), Down, 2
Each line describes a ship: its starting position, orientation, and the size of the ship.
The format is as follows
[Starting position], [Orientation], [Size]
Each part is seperated by a comma followed by a single space.
Starting Position

 

This Game Prototype Assignment has been solved by our Game Prototype experts at UniLearnO. Our Assignment Writing Experts are efficient to provide a fresh solution to this question. We are serving more than 10000+ Students in Australia, UK & US by helping them to score HD in their academics. Our Experts are well trained to follow all marking rubrics & referencing style.
Be it a used or new solution, the quality of the work submitted by our assignment experts remains unhampered. You may continue to expect the same or even better quality with the used and new assignment solution files respectively. There’s one thing to be noticed that you could choose one between the two and acquire an HD either way. You could choose a new assignment solution file to get yourself an exclusive, plagiarism (with free Turnitin file), expert quality assignment or order an old solution file that was considered worthy of the highest distinction.

Eureka! You've stumped our genius minds (for now)! This exciting new question has our experts buzzing with curiosity. We can't wait to craft a fresh solution just for you!

  • Uploaded By : Brett
  • Posted on : June 16th, 2019

Whatsapp Tap to ChatGet instant assistance