Example Code

Mastermind Game in LabVIEW

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.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview
This VI is an implementation of the board game Mastermind in LabVIEW.


Description
A secret color sequence of 3 colors is generated at the beginning of each game. It is the player's job to guess the sequence within 8 tries. After each guess, the number of correct colors in the right place in the sequence and the number of correct colors in the wrong place in the sequence are displayed. The player must use this information to narrow down the colors of the sequence and their order.

To determine if the guess matches the actual sequence, the program compares each color in the sequence to each color in the guess. It first checks for matches in the correct place in the sequence; if a match is found, the color in the guess is changed to an unused color so that the match will not be counted multiple times as it goes through the algorithm. After all In-Place matches are found, the program looks for color matches that are in an incorrect location in the sequence. Once these are found, the front panel displays these values and the player guesses again until the correct sequence is found or until the player has guessed 8 times.


Requirements

  • LabVIEW 2012 (or compatible)


Steps to Implement or Execute Code

  1. Run VI

 

Additional Information or References
VI Block Diagram

 Block Diagram.png

 

 

 **This document has been updated to meet the current required format for the NI Code Exchange.**

 

 

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