Battleship stands as a classic naval strategy game where two players aim to sink each other's concealed ships by deducing their locations on a grid. This guide is tailored for the extended edition of Battleship, integrating additional features and implemented using the Leo programming language within the Aleo development environment.
The game itself — Github
Step 1: Preparing the Game Environment Prior to commencing the gameplay, it's crucial to configure your development environment. This particular game is constructed using Leo, a programming language designed for crafting private applications on Aleo.
Install Leo if not already done.
Execute
leo buildto compile the Leo program.
Step 2: Initiating Players Every player must possess an Aleo account equipped with a private key, view key, and address. You can opt for the provided player accounts or generate your own. Safeguard these keys and addresses as they serve as representations of Player 1 and Player 2.
Adjust the program.json file with Player 1's private key and address.
Step 3: Player 1 Positions Ships Player 1 sets up their board using the leo run initialize_board command, incorporating valid ship bitstrings and Player 2’s address. The result is a board_state.record exclusively owned by Player 1.
Step 4: Player 1 Extends the Game Offer to Player 2 Player 1 extends a game invitation to Player 2 by executing leo run offer_battleship with their board_state.record. The outcome includes an updated board_state.record featuring the game_started flag activated, accompanied by a move.record designated for Player 2.
Step 5: Player 2 Deploys Ships Shift the program.json file to employ Player 2’s keys. Subsequently, Player 2 crafts their board with the leo run initialize_board command, designating Player 1’s address as the adversary.
Step 6: Player 2 Acknowledges the Game Player 2 acknowledges the game offer by initiating leo run start_battleship with their board_state.record and the move.record from Player 1. The output confirms the game initiation, and Player 1 receives a move.record.
Step 7: Player 1 Initiates the First Move Revert to Player 1’s keys in program.json. Player 1 executes the initial move using leo run play with their board_state.record, move.record, and a fire coordinate.
Step 8: Player 2 Takes Their Turn Switch to Player 2’s keys. Player 2 responds by executing the identical leo run play command with their updated records and a fresh fire coordinate.
Step 9: Progressing Through the Game Players maintain the sequence of turns, utilizing the leo run play command with their respective board_state.record and move.record. Each turn's output will update the game state, detailing hits, misses, and played tiles.
Step 10: Securing Victory The game persists until one player successfully sinks all of the opponent's ships. The game state meticulously monitors the progress, and the victor is determined when all tiles corresponding to the opponent’s ships are hit.
Additional Notes:
Players should prudently manage their
board_state.recordandmove.record.Regular updates to the
played_tilesbitstring are necessary with each move to prevent duplicate coordinates.The
hits_and_missesfield within themove.recordsignifies whether the last shot was a hit or a miss.
Conclusion This expanded edition of Battleship on Aleo introduces heightened privacy and strategy, leveraging the Leo programming language to provide a secure and engaging gaming experience. Follow this guide to initiate your game, strategize your moves, and participate in naval warfare with the innovative addition of privacy-preserving technology.
