mirror of
https://github.com/AleoHQ/leo.git
synced 2024-09-21 12:07:56 +03:00
fix battleship readme - does not change any code
This commit is contained in:
parent
dac17f3768
commit
8be9c1fdb3
@ -3,15 +3,15 @@
|
||||
- [Summary](#summary)
|
||||
- [Build](#how-to-build)
|
||||
- [Run](#how-to-run)
|
||||
- [1. Setup](#1-setup)
|
||||
- [2. Select Player 1's Board](#2-select-player-1s-board)
|
||||
- [3. Pass to Player 2](#3-pass-to-player-2)
|
||||
- [4. Select Player 2's Board](#4-select-player-2s-board)
|
||||
- [5. Pass to Player 1](#5-pass-to-player-1)
|
||||
- [6. Player 1 Shoots First](#6-player-1-shoots-first)
|
||||
- [7. Player 2 Shoots Second](#7-player-2-shoots-second)
|
||||
- [8. Player 1 Shoots Third](#8-player-1-shoots-third)
|
||||
- [9. Player 2 Shoots Fourth](#9-player-2-shoots-fourth)
|
||||
- [1. Initializing the Players](#1-initializing-the-players)
|
||||
- [2: Player 1 Places Ships On The Board](#2-player-1-places-ships-on-the-board)
|
||||
- [3: Player 1 Passes The Board To Player 2](#3-player-1-passes-the-board-to-player-2)
|
||||
- [4: Player 2 Places Ships On The Board](#4-player-2-places-ships-on-the-board)
|
||||
- [5: Passing The Board Back To Player 1](#5-passing-the-board-back-to-player-1)
|
||||
- [6: Player 1 Takes The 1st Turn](#6-player-1-takes-the-1st-turn)
|
||||
- [7: Player 2 Takes The 2nd Turn](#7-player-2-takes-the-2nd-turn)
|
||||
- [8: Player 1 Takes The 3rd Turn](#8-player-1-takes-the-3rd-turn)
|
||||
- [9: Player 2 Takes The 4th Turn](#9-player-2-takes-the-4th-turn)
|
||||
- [10. Who Wins?](#10-who-wins)
|
||||
- [ZK Battleship Privacy](#zk-battleship-privacy)
|
||||
- [Modeling the Boards and Ships](#modeling-the-board-and-ships)
|
||||
@ -37,10 +37,9 @@ leo build
|
||||
```
|
||||
|
||||
## How to Run
|
||||
<details><summary>Commands and Playing the Game</summary>
|
||||
<details open><summary>Commands and Playing the Game</summary>
|
||||
|
||||
|
||||
### 1. Setup
|
||||
### 1. Initializing the Players
|
||||
In order to play battleship, there must be two players with two boards.
|
||||
Players will be represented by their Aleo address.
|
||||
You can use the provided player accounts or [generate your own](https://aleohq.github.io/aleo/).
|
||||
@ -72,7 +71,7 @@ Save the keys and addresses. Set the `program.json` private_key and address to o
|
||||
}
|
||||
```
|
||||
|
||||
### 2. Select Player 1's Board
|
||||
### 2. Player 1 Places Ships on the Board
|
||||
Now, we need to make a board as Player 1.
|
||||
See the [modeling the boards and ships](#modeling-the-board-and-ships) section for information on valid ship bitstrings and placements on the board.
|
||||
For this example, we will be using sample valid inputs.
|
||||
@ -116,7 +115,7 @@ or laid out in columns and rows:
|
||||
0 0 0 0 0 1 1 1
|
||||
```
|
||||
|
||||
### 3. Pass to Player 2
|
||||
### 3: Player 1 Passes The Board To Player 2
|
||||
Now, we can offer a battleship game to player 2. Run `leo run offer_battleship 'board_state.record'` with the record you just created:
|
||||
**Run**
|
||||
```
|
||||
@ -170,7 +169,7 @@ there are no fire coordinates included to play on Player 2's board,
|
||||
and no information about any previous Player 2 moves (Player 2 has not made any moves yet).
|
||||
This move.record is owned by Player 2, who must use that in combination with their own board_state.record to accept the game. Let's do that now.
|
||||
|
||||
### 4. Select Player 2's Board
|
||||
### 4: Player 2 Places Ships On The Board
|
||||
We must run the program as Player 2 now, so switch the `program.json` file to use Player 2's keys:
|
||||
```json
|
||||
{
|
||||
@ -222,7 +221,7 @@ Note, the output ships here is 9044591273705727u64, which in a bitstring is:
|
||||
1 1 1 1 1 1 1 1
|
||||
```
|
||||
|
||||
### 5. Pass to Player 1
|
||||
### 5: Passing The Board Back To Player 1
|
||||
Now, we can accept Player 1's offer. Run `leo run start_battleship 'board_state.record' 'move.record'`:
|
||||
**Run**
|
||||
```bash
|
||||
@ -279,7 +278,7 @@ Notice the outputs here are similar to `offer_battleship`.
|
||||
A dummy move.record is owned by Player 1, and Player 2 gets a board_state.record with the `game_started` flag updated.
|
||||
However, now that Player 1 has a move.record and a started board, they can begin to play.
|
||||
|
||||
### 6. Player 1 Shoots First
|
||||
### 6: Player 1 Takes The 1st Turn
|
||||
**Switch** `program.json`'s keys back to Player 1's.
|
||||
Player 1 now makes the first real move: `leo run play 'board_state.record' 'move.record' fire_coordinate`
|
||||
|
||||
@ -337,9 +336,9 @@ Player 1 has an updated board_state.record -- they have a new `played_tiles` bit
|
||||
which corresponds to the fire coordinate they just sent to Player 2.
|
||||
You can see that the `incoming_fire_coordinate` in the move.record owned by Player 2 matches exactly the input given by Player 1.
|
||||
Player 2 can now play this move tile and respond with a fire coordinate of their own,
|
||||
and they will also let Player 1 know whether or not Player 1's fire coordinate hit or miss Player 2's ships.
|
||||
and they will also let Player 1 know whether their fire coordinate hit or miss Player 2's ships.
|
||||
|
||||
### 7. Player 2 Shoots Second
|
||||
### 7: Player 2 Takes The 2nd Turn
|
||||
**Switch** `program.json` to Player 2's keys. Player 2 makes their move:
|
||||
|
||||
**Run**
|
||||
@ -409,7 +408,7 @@ as well as figure out the result of Player 2's fire coordinate.
|
||||
Now that Player 1 has some `played_tiles`, they can no longer choose an alread-played fire coordinate.
|
||||
For example, running `aleo run play 'board_state.record' 'move.record' 1u64` will fail, because 1u64 has already been played.
|
||||
|
||||
### 8. Player 1 Shoots Third
|
||||
### 8: Player 1 Takes The 3rd Turn
|
||||
**Switch** `program.json` to use Player 1's keys.
|
||||
|
||||
**Run**
|
||||
@ -478,7 +477,7 @@ The board_state.record now contains 3u64 as the `played_tiles`, which looks like
|
||||
|
||||
The board_state.record `hits_and_misses` field has also been updated with the result of their previous move. The new move.record owned by Player 2 now contains information about whether Player 2's previous move was a hit or miss, as well as Player 1's new fire coordinate.
|
||||
|
||||
### 9. Player 2 Shoots Fourth
|
||||
### 9: Player 2 Takes The 4th Turn
|
||||
**Switch** `program.json`'s keys to Player 2. Player 2 makes their next move:
|
||||
|
||||
**Run**
|
||||
@ -670,7 +669,7 @@ Ships splitting across rows and columns:
|
||||
```
|
||||
</details>
|
||||
|
||||
Given these rules, our strategy will be to validate each individaul ship bitstring placement on a board, and then, if all the ships are valid, compose all the positions onto a board and validate that the board with all ships are valid. If each individual ship's position is valid, then all the ships together should be valid unless any overlapping occurs.
|
||||
Given these rules, our strategy will be to validate each individual ship bitstring placement on a board, and then, if all the ships are valid, compose all the positions onto a board and validate that the board with all ships are valid. If each individual ship's position is valid, then all the ships together should be valid unless any overlapping occurs.
|
||||
|
||||
## Validating a single ship at a time
|
||||
|
||||
|
@ -8,7 +8,14 @@ fi
|
||||
|
||||
# Follow along in the README.md for a detailed explanation of each step.
|
||||
|
||||
# 1. Setup
|
||||
# 1: Initializing Player 1
|
||||
echo "
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 1: Initializing Player 1 ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
echo "{
|
||||
\"program\": \"battleship.aleo\",
|
||||
\"version\": \"0.0.0\",
|
||||
@ -21,10 +28,29 @@ echo "{
|
||||
\"license\": \"MIT\"
|
||||
}" > program.json
|
||||
|
||||
# 2. Select Player 1's Board
|
||||
echo "✅ Successfully initialized Player 1."
|
||||
|
||||
# 2: Player 1 Places Ships On The Board
|
||||
echo "
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 2: Player 1 Places Ships On The Board ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
leo run initialize_board 34084860461056u64 551911718912u64 7u64 1157425104234217472u64 aleo1wyvu96dvv0auq9e4qme54kjuhzglyfcf576h0g3nrrmrmr0505pqd6wnry
|
||||
|
||||
# 3. Pass to Player 2
|
||||
echo "
|
||||
✅ Successfully initialized Player 1's board."
|
||||
|
||||
# 3: Player 1 Passes The Board To Player 2
|
||||
echo "
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 3: Player 1 Passes The Board To Player 2 ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
leo run offer_battleship '{
|
||||
owner: aleo15g9c69urtdhvfml0vjl8px07txmxsy454urhgzk57szmcuttpqgq5cvcdy.private,
|
||||
gates: 0u64.private,
|
||||
@ -36,8 +62,17 @@ leo run offer_battleship '{
|
||||
game_started: false.private,
|
||||
_nonce: 3887646704618532506963887075433683846689834495661101507703164090915348189037group.public
|
||||
}'
|
||||
echo "
|
||||
✅ Successfully passed the board to Player 2."
|
||||
|
||||
# 4. Select Player 2's Board
|
||||
# 4: Player 2 Places Ships On The Board
|
||||
echo "
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 4: Player 2 Places Ships On The Board ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
(
|
||||
echo "{
|
||||
\"program\": \"battleship.aleo\",
|
||||
@ -53,8 +88,18 @@ leo run offer_battleship '{
|
||||
|
||||
leo run initialize_board 31u64 2207646875648u64 224u64 9042383626829824u64 aleo15g9c69urtdhvfml0vjl8px07txmxsy454urhgzk57szmcuttpqgq5cvcdy
|
||||
)
|
||||
echo "
|
||||
✅ Successfully initialized Player 2's board."
|
||||
|
||||
# 5. Pass to Player 1
|
||||
# 5: Passing The Board Back To Player 1
|
||||
echo "
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 5: Passing The Board Back To Player 1 ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
|
||||
"
|
||||
leo run start_battleship '{
|
||||
owner: aleo1wyvu96dvv0auq9e4qme54kjuhzglyfcf576h0g3nrrmrmr0505pqd6wnry.private,
|
||||
gates: 0u64.private,
|
||||
@ -74,8 +119,17 @@ leo run start_battleship '{
|
||||
prev_hit_or_miss: 0u64.private,
|
||||
_nonce: 4374626042494973146987320062571809401151262172766172816829659487584978644457group.public
|
||||
}'
|
||||
echo "
|
||||
✅ Successfully passed the board back to Player 1."
|
||||
|
||||
# 6. Player 1 Shoots First
|
||||
# 6: Player 1 Takes The 1st Turn
|
||||
echo "
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 6: Player 1 Takes The 1st Turn ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
(
|
||||
echo "{
|
||||
\"program\": \"battleship.aleo\",
|
||||
@ -109,8 +163,17 @@ leo run start_battleship '{
|
||||
_nonce: 3742551407126138397717446975757978589064777004441277005584760115236217735495group.public
|
||||
}' 1u64
|
||||
)
|
||||
echo "
|
||||
✅ Successfully executed Player 1's turn."
|
||||
|
||||
# 7. Player 2 Shoots Second
|
||||
# 7: Player 2 Takes The 2nd Turn
|
||||
echo "
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 7: Player 2 Takes The 2nd Turn ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
(
|
||||
echo "{
|
||||
\"program\": \"battleship.aleo\",
|
||||
@ -144,8 +207,17 @@ leo run start_battleship '{
|
||||
_nonce: 5481529266389297320813092061136936339861329677911328036818179854958874588416group.public
|
||||
}' 2048u64
|
||||
)
|
||||
echo "
|
||||
✅ Successfully executed Player 2's turn."
|
||||
|
||||
# 8. Player 1 Shoots Third
|
||||
# 8: Player 1 Takes The 3rd Turn
|
||||
echo "
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 8: Player 1 Takes The 3rd Turn ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
(
|
||||
echo "{
|
||||
\"program\": \"battleship.aleo\",
|
||||
@ -179,8 +251,17 @@ leo run start_battleship '{
|
||||
_nonce: 5851606198769770675504009323414373017067582072428989801313256693053765675198group.public
|
||||
}' 2u64
|
||||
)
|
||||
echo "
|
||||
✅ Successfully executed Player 1's turn."
|
||||
|
||||
# 9. Player 2 Shoots Fourth
|
||||
# 9: Player 2 Takes The 4th Turn
|
||||
echo "
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 9: Player 2 Takes The 4th Turn ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
(
|
||||
echo "{
|
||||
\"program\": \"battleship.aleo\",
|
||||
@ -214,3 +295,5 @@ leo run start_battleship '{
|
||||
_nonce: 710336412388939616658264778971886770861024495941253598683184288448156545822group.public
|
||||
}' 4u64
|
||||
)
|
||||
echo "
|
||||
✅ Successfully executed Player 2's turn."
|
||||
|
Loading…
Reference in New Issue
Block a user