🚀 Bunker War Z !

Presentation

Web app link : Bunker War Z

Bunker War Z is a game running on FHE encrypted blockchains. Two players play against each other, competing to build the maximum number of houses on a grid and protect them with bunkers from the missiles of the opponent!

Rules 📝

Each player starts with an empty grid. The dimensions of the grid are adjustable when the game is created. The goal is to build a maximum number of houses before the game stops. Each house standing at the end of the game adds 1 point to the player's score.

The game stops after a number of turns equal to the number of cells on a board, for instance 16 turns for a 4x4 grid. Buildings of the opponent (houses or bunkers) are visible, but their type is encrypted.

Turns of the game

At each turn, a player can take one of three actions:

  • 🏠 Build a hidden house: A house adds 1 point to the player's score. The house being hidden to the opponent, the player's score also is.

  • 🏰 Build a hidden bunker: A bunker does not add score, but it protects the houses below it on the row from missiles (row can be called columns depending of the horizontal or display of the boards).

  • 🚀 Send a missile to a row of the opponent's grid: the missile will destroy all unprotected houses on the row, decreasing the score of the opponent! The missile stops if there is a bunker on the row, and does not destroy it. All houses below the bunker are thus safe for the whole game. A player cannot send 2 missiles in a row.

Hidden buildings and revealed information: When the opponent builds a house or a bunker, the player can see where the new building is on the opponent's grid, but the type of the building is hidden because it is encrypted. The score of the opponent stays encrypted as well. When a missile hits however, both player know where it stops, and thus they can deduce if there were unprotected houses that got destroyed and if there was a bunker.

Here's how a few turns of the game might unfold:

  1. The player has one protected house and two unprotected houses on row 2, and the opponent sends a missile to row number 2:
  1. The unprotected houses get destroyed, and the missile stops on the bunker on row number 2. The opponent can thus deduces there is a bunker there, and also that he/she destroyed 2 houses. The player replicates with a missile toward the opponent's row number 3:
  1. The player discovers that he/she successfully destroyed a house and now also deduces there is a bunker where the missile stopped at:

End of the game ⏰

When the maximum number of turns has passed, the game stops. The end of game status can then be querried, telling which player won or if there is a tie. The precise score of the opponent remains hidden, as the hidden constructions stay encrypted. This allows a player to keep his/her strategy secret for future games.

When the maximum number of turns has passed, the game stops. The end of game status can then be querried, telling which player won or if there is a tie. The precise score of the opponent remains hidden, as the hidden constructions stay encrypted. This allows a player to keep his/her strategy secret for future games.

Run ui

⚠️ Important notice

The ZAMA blockchain being in developpment, there is no subgraphs available on it. Thus, the app fetches events directly on the explorer, but there is a caveat: before starting a session (and each time one refreshes the page), one should provide a Start block: value on the UI in the navigation bar.

This value will tell what block the code should start looking at to fetch events, and it should be pretty recent (few hours) to prevent looking for events too far in the past. A value of a recent block can be found at Zama explorer in the Transactions field.

Later, when subgraphs will be available, the smart contract and the web app can be changed (see TODO in the smart contract) so as to easily querry all relevant events and values of the past of the smart contract.

This value can also be set in the code before a local game session in game.index.ts.

Run online

The game is playable online at: Bunker War Z

Run locally

This starter uses bun runtime environment for performance improvement on proof generation. It is also compatible with npm, pnpm and yarn.

Make sure to install the dependencies:

# bun
bun install

# npm
bun install
# pnpm
pnpm install

# yarn
yarn install

Start the development server on http://localhost:3000:

# npm
bun run dev

# npm
npm run dev

# pnpm
pnpm run dev

# yarn
yarn dev

Smart contract

Link to the smart contract dev repository on github

Last deployed smart contract address: 0xaDCE6E593dE93309e068a9b1B9e2E36C3D8c8655

deploy

bun run deploy:contract —network zama

Dev

When subgraphs are available, create a subgraph and adapt both the smart contrat and the web app to querry game information on the subgraph. Delete the Start block input field of the naviguation bar then.