Design a Battleship game in C++ using pipes, where two players (Player 1 and Player 2) play against each other on
a 5x5 grid. The game will be played between two separate processes, and all communication between the players
will happen through pipes. Each player controls a fleet of 3 ships, and the goal is to sink the opponent’s ships by
guessing their positions.
Requirements:
1. Game Board:
o Each player has a 5x5 grid, where each space can either be empty or occupied by a ship.
o Each player controls 3 ships placed at the start of the game. The ship sizes are fixed: 2, 3, and 4
spaces long, and can be placed either horizontally or vertically on the grid.
o Players place their ships on their grid before the game starts, with proper validation to avoid
overlapping ships.
2. Pipes for Communication:
o The game will use two pipes for communication between Player 1 and Player 2 processes.
▪ Pipe 1: Used for Player 1 to send their guesses to Player 2.
▪ Pipe 2: Used for Player 2 to send their guesses to Player 1.

o Players will also communicate their responses (hit or miss) using the same pipes, ensuring a turn-
based gameplay loop.

o Players must wait for the other player's guess and response before proceeding with their own turn.
3. Turn-Based Gameplay:
o Players take turns guessing the opponent’s ship positions by sending (row, col) coordinates through
the pipe.
o After a guess, the opponent responds with either:
▪ H (Hit) if a ship is hit.
▪ M (Miss) if the guess misses the ships.
o The response is sent back through the same pipe.
4. Game Termination:
o The game ends when one player successfully sinks all 3 of the opponent’s ships.
o Each ship requires multiple hits to sink, based on its size (e.g., a ship of size 3 requires 3 hits to
sink).
o Once a player sinks all the opponent’s ships, the game declares the winner and both processes
terminate gracefully.

Game Flow:
• Player 1 Process:
1. Place Ships: Before the game starts, Player 1 places their ships on a private 5x5 grid.
2. Send Guess: Player 1 sends a guess (row, col) to Player 2 through Pipe 1.
3. Receive Response: Player 1 waits for Player 2’s response (Hit/Miss) through Pipe 1.
4. If all of Player 2’s ships are hit, Player 1 wins, and the game ends.
5. If Player 1 does not win, control is passed to Player 2.
• Player 2 Process:
1. Place Ships: Player 2 places their ships on their private 5x5 grid.
2. Receive Guess: Player 2 receives Player 1’s guess (row, col) through Pipe 1.
3. Check Hit or Miss: Player 2 checks if Player 1’s guess hits or misses a ship on their grid and sends
the response (Hit/Miss) back to Player 1 through Pipe 1.
4. Send Guess: Player 2 then sends a guess (row, col) to Player 1 through Pipe 2.
5. Receive Response: Player 2 waits for Player 1’s response (Hit/Miss) through Pipe 2.
6. If all of Player 1’s ships are hit, Player 2 wins, and the game ends.
7. If Player 2 does not win, control is passed back to Player 1.

Synchronization:
• The pipes are used for communication, ensuring that only one player can make a move at a time.
• The guessing process is synchronized using the turn-based system, where a player sends their guess and
waits for the opponent’s response before taking their next turn.
• There should be proper synchronization to ensure that one player cannot make multiple guesses in a row
without waiting for the other player's move.
Pipes Error Handling:
• Implement error handling for the pipes to ensure proper communication. If there’s a failure to