Mastermind introduction

Mastermind is a two player logic game where one of the players come with a sequence of a numbers/colors and other player is trying to guess that sequence. In the classical board version, pegs with colors are used, where in this tutorial you will build the zk version of this game :)

Overview

  • The game involves two players: a Code Master and a Code Breaker.

  • Inspired by mastermind-noir, this version replaces colored pegs with a combination of 4 unique, non-zero digits.

Game Rules

  • The Code Master hosts a game and sets a secret combination for the Code Breaker to guess.

  • The Code Breaker makes a guess and waits for the Code Master to provide a clue.

  • The clue indicates the following:

    • Hits: Digits that are correctly guessed and in the correct position.

    • Blows: Digits that are correct but in the wrong position.

    Example:

    • Code Master's secret combination: 1 2 3 4

    • Code Breaker's guess: 1 7 8 2

    • Clue: 2 0 0 1

      • Result: 1 hit and 1 blow.

        • The hit is 1 in the first position.

        • The blow is 2 in the fourth position.

  • The game continues with alternating guesses and clues until the Code Breaker achieves 4 hits and uncovers the secret combination or fails to do so within the maximum allowed attempts.

Now that you know the rules of the game, we can try to understand the design of the relevant zkApp.

Mastermind zkApp Structure

Following the game rules, the MastermindZkApp should be deployed:

  • The zkApp is initialized by calling the initGame method, with maxAttempts as the method parameter to set an upper limit.

  • After initialization, the Code Master calls the createGame method to start the game and set a secret combination for the Code Breaker to solve.

  • The Code Breaker then makes a guess by calling the makeGuess method with a valid combination as an argument.

  • The Code Master submits the solution again to be checked against the previous guess and provides a clue.

  • The Code Breaker should analyze the given clue and make another meaningful guess.

  • The game continues by alternating between makeGuess and giveClue methods until the Code Breaker either uncovers the secret combination or fails by exceeding the allowed maxAttempts, concluding the game.

Now, let's dive deeper into the states and methods of our Mastermind zkApp.

ZkApp Structure

Following the game rules, the MastermindZkApp should be deployed:

  • The zkApp is initialized by calling the initGame method, with maxAttempts as the method parameter to set an upper limit.

  • After initialization, the Code Master calls the createGame method to start the game and set a secret combination for the Code Breaker to solve.

  • The Code Breaker then makes a guess by calling the makeGuess method with a valid combination as an argument.

  • The Code Master submits the solution again to be checked against the previous guess and provides a clue.

  • The Code Breaker should analyze the given clue and make another meaningful guess.

  • The game continues by alternating between makeGuess and giveClue methods until the Code Breaker either uncovers the secret combination or fails by exceeding the allowed maxAttempts, concluding the game.

In the next section, you will learn the states in the zkApp and start building it.

Last updated