A solver for the super-master-mind game
  • OCaml 84.4%
  • Text 14%
  • Shell 0.8%
  • Dune 0.5%
  • Makefile 0.3%
Find a file
2026-09-08 10:04:04 +02:00
.github Upgrade OCaml and dune in CI 2026-08-12 14:50:05 +02:00
.vscode Remove leftover dependency 2026-03-16 10:49:32 +01:00
doc Keep board img only in the main README 2026-04-10 14:05:55 +02:00
src Improve myers and merge3 vendoring 2026-08-17 16:44:22 +02:00
test Vendor ocaml-merge3 2026-05-18 15:53:02 +02:00
third-party-license Improve myers and merge3 vendoring 2026-08-17 16:44:22 +02:00
.gitattributes added gitattributes 2023-03-03 18:58:37 +01:00
.gitignore Load the opening-book from a dune-site 2025-12-03 08:23:07 +01:00
.headache.config Add headache config 2025-09-12 11:42:59 +02:00
.ocamlformat Upgrade ocamlformat to 0.29.0 2026-03-24 09:10:55 +01:00
CHANGES.md Edit changelog 2025-11-30 22:38:35 +01:00
CODE_OF_CONDUCT.md Adopt OCaml Code Of Conduct 2025-12-16 20:35:57 +01:00
CODEOWNERS Initiate code owners file for GH 2026-02-01 08:21:28 +01:00
COPYING.HEADER Add headache config 2025-09-12 11:42:59 +02:00
dune initial commit (template) 2022-03-01 16:00:50 +01:00
dune-project Remove unused test dependency 2026-05-18 15:59:12 +02:00
dune-workspace.5.2 Upgrade CIs 2026-04-12 13:22:14 +02:00
dune-workspace.5.3 Upgrade CIs 2026-04-12 13:22:14 +02:00
dune-workspace.5.4 Upgrade CIs 2026-04-12 13:22:14 +02:00
dune-workspace.5.5 Upgrade OCaml to latest available versions 2026-09-08 10:04:04 +02:00
dunolint Preparatory changes to reduce deps further 2025-12-17 20:36:35 +01:00
headache.sh Remove left-over unused var (shellcheck) 2026-03-17 11:38:22 +01:00
LICENSE License year 2025-09-12 11:41:37 +02:00
Makefile Upgrade to cmdlang.0.0.4 2024-09-07 15:38:52 +02:00
NOTICE.md Improve myers and merge3 vendoring 2026-08-17 16:44:22 +02:00
README.md Keep board img only in the main README 2026-04-10 14:05:55 +02:00
super-master-mind-dev.opam Upgrade ocamlformat to 0.29.0 2026-03-24 09:10:55 +01:00
super-master-mind-tests.opam Remove unused test dependency 2026-05-18 15:59:12 +02:00
super-master-mind.opam Require cmdlang upgrade and unify nonempty-list type 2026-05-11 18:50:30 +02:00

super-master-mind

CI Status Coverage Status

This is a toy project implementing a solver for the super-master-mind game, written in OCaml.

What is the super-master-mind ?

This is the name of a particular variation of the famous master-mind game, which was commercialized by Invicta and popular in the 70th.

Rules variation 1

Rules of the game

The person playing as code-maker chooses 5 code pegs among 8 colors (allowing color repetitions), and place them in the 5 holes code section, which is hidden to the code-breaker (the other player). The code-breaker will then submit up to 12 guesses to try and figure out the hidden code. The code-maker must respond to each guess by giving information back to the code-breaker by placing black and white key pegs in the holes alongside the guesses.

  • a Black peg must be accounted for each of the code peg that is of the right color and at the right place;
  • a White peg must be accounted for each of the code peg that is of the right color, but misplaced.

In case of color repetition, duplicate colors only get white pegs if the color is also duplicated in the secret code.

The pegs must be placed randomly and not indicate the actual position of the code pegs they are accounting.

This is the variation implemented by this repository.

Other rules are possible, but there are not implemented here.

What does this repository implement ?

The repo contains a solver for the game, which is able to play as code-breaker.

The repo does not implement any user interface to play the game interactively. Rather, the motivation is simply to go over the algorithmic solving part of the game.

Install

Releases for this project are published to a custom opam-repo. To add it to your current opam switch, run:

opam repo add mbarbin https://github.com/mbarbin/opam-repository.git

Then you can install super-master-mind using a normal opam workflow.

opam install super-master-mind

Running the code interactively

Run the following command to see the program play as code-breaker in the terminal:

$ super-master-mind solver

You should see a prompt asking you to make sure you've selected a solution.

Press enter when done choosing a solution:

For example, let's assume our secret code is (Green Yellow Blue Green Red). We don't type it in, and just press ENTER.

The program will print a guess, and expects you to manually enter the number of black and white pins at each round. For example:

...
(1 (Green Red Brown Blue Orange))
#black (correctly placed)  : ?
#white (incorrectly placed): ?

Here, the first Green peg is the only one correctly placed (1 peg). Red and Blue are present but misplaced (2 pegs) and Brown and Orange are not part of the secret code so don't account for a black nor a white peg. Thus we enter 1 for black and 2 for white:

(1 (Green Red Brown Blue Orange))
#black (correctly placed)  : 1
#white (incorrectly placed): 2
(2 (White Red Brown Green Green))
etc....

The game will continues with new guesses until the program breaks the code.

Code Documentation

The code documentation of the latest release is built with odoc and published to GitHub pages here.

Motivations

The main motivation for me was to learn some concepts of information theory and entropy:

Recently I have been playing Wordle with family. I watched a video on YouTube made by 3Blue1Brown on solving Wordle (see the link in the Acknowledgements section). As he puts it in the video, the game of Wordle is a good excuse to him for an information theory lesson. I got inspired by his video, and thought that the game of super-master-mind was well suited to implement some of the concepts contained in the video.

Acknowledgements

The resolution algorithm was inspired by a video on solving the game Wordle, by YouTuber 3Blue1Brown. See it here: