Example Code

Mastermind

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Operating System

  • Windows

Code and Documents

Attachment

Description

Invented in 1970 by the Israeli postmaster and telecommunications expert Mordecai Meirowitz, Mastermind is a well-known deductive game for two players: the code-maker, who chooses a secret code of four pegs of six possible repeatable colours, and the code-breaker, who tries to break the code by making guesses.

This example code implements a full version of the Mastermind game using an interactive table for playing and showing progress. Controls and decorations are cleverly handled with sub-VIs to provide matrix-style handling. Guesses can be submitted by dragging or double-clicking the pegs from a palette. Right-clicking can affix a hash character to the pegs of the palette to help with guessing. The computer can provide suggestions by selecting the corresponding item in the menu bar or by using the shortcut ctrl+h. The implemented strategy is based on the commutative property of the score (i.e., if you reverse the roles of the secret pattern and guess, the score remains the same). It is a simple but effective strategy that allows the solution to be found with no more than 6 and generally fewer moves.

 

blobid1729367228533.png

 

 

 

How to Use

Open the VI Mastermind.vi and run it. The tip strips will help you navigate through the features.

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors