Implementing the Mastermind game

In this series I am going to implement a version of the well-known Mastermind board game. Well, it is well know at least to me. As I have encountered many people who are not familiar with it so let’s start by explaining the game:

The Game


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Gábor Szabó

In this series I am going to implement a version of the well-known Mastermind board game. Well, it is well know at least to me. As I have encountered many people who are not familiar with it so let's start by explaining the game:

The Game

  • The computer selects N different items from a pool of M items and puts them in some order. This is the secret that the user has to find in the right order.

  • The user selects N different items from the pool of M items in a certain order.

  • The computer gives a * sign for every item that is in the same location as in the secret and a + sign for every item that is in the secret but not in the place the user put it.The order of the response does NOT correspond to the order of the values.

  • The last two steps are repeated until the user finds the secret and the the user wins. If the user cannot find the secret in K guesses then the user loses.

  • N, M and K can be be anything. Items can be anything (eg. colors, digits, letters, etc.)

  • In the original game M = 6 colors, N = 4 and K = 12 and * was a back stick and + was a white stick.

  • There difficulty can be increased by allowing items to be repeated in the secret and/or by allowing empty spaces in the secret.

Let's see an example when the pool of items are the 6 digits 1-6 and that the size of the secret is 4.

The computer selects 4 values randomly:

  • hidden: 3654
  • guess 1: 1234 *+ (4 is in the right place, 3 is in the wrong place)
  • guess 2: 1256 *+ (5 is in the right place, 6 is in the wrong place)
  • guess 3: 6354 **++ (4 and 5 in the right place, 3 and 6 in the wrong place)
  • guess 4: 3654 **** win

An original box

Image description

Technology

  • First I'll implement a command-line version of the game written in Python
  • Then I will probably implement a web version with plain HTML using the Flask framework written in Python
  • Then I don't know yet. I might implement a different front-end for the game or I will re-implement the whole thing in JavaScript. I don't know yet.

In any case I am going to publish and explain my progress so follow me if you are interested.


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Gábor Szabó


Print Share Comment Cite Upload Translate Updates
APA

Gábor Szabó | Sciencx (2022-12-13T18:09:00+00:00) Implementing the Mastermind game. Retrieved from https://www.scien.cx/2022/12/13/implementing-the-mastermind-game/

MLA
" » Implementing the Mastermind game." Gábor SzabĂł | Sciencx - Tuesday December 13, 2022, https://www.scien.cx/2022/12/13/implementing-the-mastermind-game/
HARVARD
Gábor SzabĂł | Sciencx Tuesday December 13, 2022 » Implementing the Mastermind game., viewed ,<https://www.scien.cx/2022/12/13/implementing-the-mastermind-game/>
VANCOUVER
Gábor SzabĂł | Sciencx - » Implementing the Mastermind game. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/12/13/implementing-the-mastermind-game/
CHICAGO
" » Implementing the Mastermind game." Gábor SzabĂł | Sciencx - Accessed . https://www.scien.cx/2022/12/13/implementing-the-mastermind-game/
IEEE
" » Implementing the Mastermind game." Gábor SzabĂł | Sciencx [Online]. Available: https://www.scien.cx/2022/12/13/implementing-the-mastermind-game/. [Accessed: ]
rf:citation
» Implementing the Mastermind game | Gábor SzabĂł | Sciencx | https://www.scien.cx/2022/12/13/implementing-the-mastermind-game/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.