This project primarily shows that it is possible to write game logic as 'complex' as chess using Mina's o1js.
Disclaimer: This project is a part of the Mina Navigator's Program, primarily focused on understanding how Mina works.
- Proves that every move is played correctly and the final result
win
,loose
,draw
(along withdraw_by_stalemate
), - Players may also create chess puzzles using a custom inital state of the Board. Potentially solve puzzles without revealing the solutions.
hosted on vercel
- Chess matches are verified onchain and player ratings can be trusted.
- Create onchain chess puzzles.
Originally there was a single smart contract that does everything (checkout the ChessContract
folder).
Now the functionalities are divided into a zkprogram namely PvPChessProgram
and smartcontract namely PvPChessProgramSubmission
.
- accepts matches that have ended (won,lost,drawn,drawnByStalemate)
- updates the elo ratings of the players accordingly.
- takes in the public keys of the white and black players.
- starts the game with the initial starting positions (configurable).
-
verifies whether the current move is valid or not.
-
a
Move
consists of a path of size 8 and promotion choice. -
finally updates the piece's position to the end of the path.
If a player has no valid move to play and its king is not in check, then it's a stalemate and the game is a draw. Handling stalemates is tricky any normal approach would take enough time to be unfeasible. However, taking some reasonable compromises, we can greatly reduce it exponentially using a interactive approach. Take a look at the contract for a more detailed explanation.
- the player calls this to offer a draw request.
- this can only be called if the game is ongoing.
- accept or reject the draw request.
- can only be called when draw is offered.
- the player calls this to resign.
Take a look at the contract for other methods that handles possible disputes.
Please checkout branch v0.1.4
-> server folder.
Take a look at the example scenario of Alice and Bob playing a game of zkchess.
A few things to note:- Once a match is started the invite link is not longer valid.
- If during the match if anyone leaves the page the game is stalled idefinitely (they cannot rejoin as of now).
- If the Game Machine somehow receives an invalid proof, it simply ignores it expecting a valid version of that proof to come next.
Rethinking the possibilities of chess with this groundbreaking zk technology.
- Chess pieces can move into different realms becoming invisible to the opponent (while still moving according to the rules).
- Switch realms to evade enemy strikes and execute unexpected assaults.
- With so many options checkmating may be difficult so may be the kings cannot shift realms when under check, uh we will think about that.
There is a lot of crazy ideas to think about.
-
clone this repository
-
go to contracts folder.
-
run
npm install
and thennpm run test
to test the contract. -
run
npm run build
to build the contracts -
go to ui folder.
-
run
npm install
and thennpm run dev
to run it on dev mode
you can check out this youtube video (last updated on Nov 1, 2023)