Git Product home page Git Product logo

zkchess's Introduction

Welcome to the next generation of Gaming using MINA !

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.

TLDR

A zkprogram & smartcontract/zkApp to play chess.

  1. Proves that every move is played correctly and the final result win ,loose ,draw (along with draw_by_stalemate),
  2. Players may also create chess puzzles using a custom inital state of the Board. Potentially solve puzzles without revealing the solutions.

UI demo

hosted on vercel

Usage

  1. Chess matches are verified onchain and player ratings can be trusted.
  2. Create onchain chess puzzles.

How it works?

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.

PvPChessProgramSubmission

πŸ’‘submit(zkProgram:PvPChessProgram)

  1. accepts matches that have ended (won,lost,drawn,drawnByStalemate)
  2. updates the elo ratings of the players accordingly.

PvPChessProgram

✨ start(whiteKey: PublicKey, blackKey: PublicKey)

  1. takes in the public keys of the white and black players.
  2. starts the game with the initial starting positions (configurable).

🚚 move(move:Move)

  1. verifies whether the current move is valid or not.

  2. a Move consists of a path of size 8 and promotion choice.

  3. finally updates the piece's position to the end of the path.

    How handling Draws and Stalemates Work

    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.

🀝 offerDraw()

  1. the player calls this to offer a draw request.
  2. this can only be called if the game is ongoing.

🀝 resolveDraw()

  1. accept or reject the draw request.
  2. can only be called when draw is offered.

πŸ˜– resign()

  1. the player calls this to resign.

Take a look at the contract for other methods that handles possible disputes.

How does multiplayer work?

Option 1 : MatchMaker Server + Web Sockets for comms.

Please checkout branch v0.1.4 -> server folder.

Option 2 : Peer.js + Link sharing

Take a look at the example scenario of Alice and Bob playing a game of zkchess.

A few things to note:
  1. Once a match is started the invite link is not longer valid.
  2. If during the match if anyone leaves the page the game is stalled idefinitely (they cannot rejoin as of now).
  3. If the Game Machine somehow receives an invalid proof, it simply ignores it expecting a valid version of that proof to come next.

Future Aspects

Utilizing the ZK aspect with "Transcendental Chess"

Rethinking the possibilities of chess with this groundbreaking zk technology.

  1. Chess pieces can move into different realms becoming invisible to the opponent (while still moving according to the rules).
  2. Switch realms to evade enemy strikes and execute unexpected assaults.
  3. 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.

Contributing Is Easy

  1. clone this repository

  2. go to contracts folder.

  3. run npm install and then npm run test to test the contract.

  4. run npm run build to build the contracts

  5. go to ui folder.

  6. run npm install and then npm run dev to run it on dev mode

Video links

you can check out this youtube video (last updated on Nov 1, 2023)

zkchess's People

Contributors

raunaque97 avatar rudrakpatra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

zkchess's Issues

Stalemate

Implement a solution as mentioned in readme.

Castling

1.Need to store extra state onchain.
2.Castling logic.
3.Tests

En Passant

En Passant move is not possible with current state need for extra state.
1.extra state
2.verification logic
3.tests

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.