Optimal Brainmaster on a Phone:
Bayesian Adaptive Design with Lookahead

Brainmaster solver project Β· Technical report Β· 21 November 2026 Β· PDF version

Abstract

We describe a small, framework-free web app that plays the codebreaker in Mastermind (also sold as Brainmaster) against a human codemaker. It treats each guess as an experiment in a Bayesian adaptive design. The posterior over the 𝑀𝑃 codes is kept as an explicit table, and guesses are ranked by their expected information gain. Pure information-greedy play is myopic. The app therefore re-ranks the most informative guesses by one-step lookahead (a rollout of the greedy policy), and it switches to an exact branch-and-bound search for the minimum expected number of moves once few codes remain. For the classic game with 6 colours and 4 positions, the app needs 4.3403 guesses on average (5625/1296). This equals the proven optimum, so the app plays the classic game optimally. Pure information-greedy play needs 4.4151. The app never needs more than 6 guesses, and every decision takes well under a second in a phone browser. We report the method, the implementation, and an empirical analysis of its behaviour and expected number of moves across 23 game sizes.

1 Introduction

In Mastermind, the codemaker hides a code of 𝑃 pegs (classically 𝑃=4), each one of 𝑀 colours (𝑀=6); colours may repeat. The codebreaker guesses codes and receives, for each guess, a number of black pins (right colour in the right position) and white pins (right colour in the wrong position). The board has ten rows.

The app is meant for the table. Someone else picks a secret, the app proposes every guess, and the user taps in the pins the codemaker places. The aim is to show that a principled strategy reliably cracks the code in four or five moves. The app also shows, at every move, the quantities that make the strategy legible: the number of codes still possible, the remaining uncertainty in bits, the expected information gain of the proposed guess, its probability of being the secret, and the exact expected number of remaining moves.

Three questions shaped the design. Can the app use Bayesian adaptive experimental design (Lindley 1956; Chaloner and Verdinelli 1995) literally, with an explicit hypothesis table? How far is information-greedy play from optimal play? And how much of optimal play can a phone afford? SectionΒ 2 derives the information-gain criterion and its cost. SectionΒ 3 develops the decision policy, SectionΒ 4 the app, and SectionΒ 5 the analysis.

2 The codebreaker as a Bayesian experimenter

Let π’žοΈ€={0,…,π‘€βˆ’1}𝑃 be the set of codes, 𝑁=|π’žοΈ€|=𝑀𝑃. A guess π‘”βˆˆπ’žοΈ€ against a secret 𝑠 yields the feedback πœ‘(𝑔,𝑠)=(𝑏,𝑀). The feedback alphabet π’ͺοΈ€ consists of all (𝑏,𝑀) with 𝑏+𝑀≀𝑃 except (π‘ƒβˆ’1,1), so |π’ͺοΈ€|=(𝑃+1)(𝑃+2)/2βˆ’1, which is 14 for 𝑃=4.

Posterior. Under a uniform prior and noise-free feedback, the posterior after a history (𝑔1,𝑓1),…,(𝑔𝑑,𝑓𝑑) is uniform on the consistent set

𝑆𝑑={π‘ βˆˆπ’žοΈ€:πœ‘(𝑔𝑖,𝑠)=𝑓𝑖 for all 𝑖≀𝑑}.

The app stores 𝑆𝑑 as a list of code indices; the remaining uncertainty is 𝐻(𝑆𝑑)=log2|𝑆𝑑| bits (10.34 bits at the start of the classic game).

Expected information gain. A guess 𝑔 partitions 𝑆 into classes 𝑆𝑓={π‘ βˆˆπ‘†:πœ‘(𝑔,𝑠)=𝑓} with sizes 𝑛𝑓, βˆ‘π‘“π‘›π‘“=𝑛=|𝑆|. Since the posterior after observing 𝑓 is uniform on 𝑆𝑓, the expected information gain (Lindley 1956) is

EIG(𝑔)=log2π‘›βˆ’βˆ‘π‘“π‘›π‘“π‘›log2𝑛𝑓=βˆ’βˆ‘π‘“π‘›π‘“π‘›log2𝑛𝑓𝑛,

the entropy of the partition induced by 𝑔. A guess that cannot be the secret still has positive EIG if it splits 𝑆. Such probe guesses are often the most informative.

Cost. One might expect a quadratic sum over pairs of feasible codes. Because the feedback is a deterministic function of (𝑔,𝑠), a single pass over 𝑆 that counts class sizes suffices. Scoring every possible guess therefore costs 𝑂(𝑁⋅𝑛) table look-ups: 1.7 million for the first move of the classic game. Up to 𝑁=4096 the app precomputes the full 𝑁×𝑁 feedback table (one byte per entry); above that it scores on the fly.

Symmetry. If a colour has not appeared in any guess so far, all such colours are interchangeable: permuting them maps 𝑆𝑑 onto itself. It therefore suffices to consider canonical guesses, in which unused colours appear in increasing order of first occurrence. This reduces the 1296 first guesses to 15, one per set partition of the positions, and it is exact, not a heuristic.

Displayed statistics. For the current guess 𝑔: Pr[win]=1/𝑛 if π‘”βˆˆπ‘† and 0 otherwise; the EIG as above; and the expected number of remaining moves π‘‡πœ‹(𝑆)/𝑛, where π‘‡πœ‹(𝑆) is the total number of guesses the app’s own policy πœ‹ needs, summed over all π‘ βˆˆπ‘† (the winning guess included). The app computes π‘‡πœ‹ exactly by simulating the policy against every consistent secret (SectionΒ 4).

3 From information to expected moves

The objective of the game is the number of guesses, not information. The optimal expected-moves policy satisfies the Bellman recursion

π‘‡βˆ—(𝑆)=minπ‘”βˆˆπ’žοΈ€[𝑛+βˆ‘π‘“β‰ (𝑃,0)π‘‡βˆ—(𝑆𝑓)],π‘‡βˆ—({𝑠})=1,

which charges one guess to every remaining secret and stops for the secret that was hit. Information-greedy play maximises a one-step proxy for this objective. The proxy is good, but it ignores, for instance, that guessing a feasible code may win immediately.

Exact search. The app solves the recursion exactly by depth-first branch and bound when 𝑆 is small. Any guess yields at most |π’ͺοΈ€|βˆ’1 non-winning classes, so a set of size 𝑛 needs at least

𝐿(𝑛)=𝑛+βˆ‘π‘—=1|π’ͺοΈ€|βˆ’1𝐿(π‘šπ‘—),𝐿(1)=1,

total guesses, where (π‘šπ‘—) is a balanced split of π‘›βˆ’1 into |π’ͺοΈ€|βˆ’1 parts. This bound is valid because 𝐿 is convex (verified numerically for all 𝑛≀104 in the test suite), so a balanced split minimises the sum. At each node:

On small games the search agrees with an unpruned exhaustive search over all guesses.

Rollout. For medium-sized sets, exact search is too slow for a phone. The app then applies one step of policy improvement (Bertsekas et al. 1997) to a base policy πœ‹0, which is the EIG-greedy rule plus exact search on small sets. Among the π‘˜ guesses with the highest EIG, it picks the one minimising 𝑛+βˆ‘π‘“π‘‡πœ‹0(𝑆𝑓), where each child’s total is obtained by simulating πœ‹0 to the end. SectionΒ 3.1 states the operator precisely and shows that the resulting policy is never worse than πœ‹0, at any point of the game.

Tiers. The policy is deterministic, and its tier depends on 𝑛 only: exact search if 𝑐𝑛𝑁≀60β‹…1296 (i.e. 𝑛≀60 for the classic game), rollout if 𝑐𝑛𝑁≀12962, and plain max-EIG otherwise (only the first move or two of the largest games). The constant 𝑐 is 1 when the feedback table is available and 3 otherwise, which reflects the cost of scoring on the fly. In hard mode the candidates are restricted to 𝑆, and 𝑛2 replaces 𝑛𝑁. Rollout uses π‘˜=20 candidates for games with 𝑁≀1296, decreasing as π‘˜=max(10,⌊20β‹…1296/π‘βŒ‹) for larger games. Exact search has one more shortcut: if a feasible guess splits the remaining codes into singletons, it meets the bound 𝐿(𝑛)=2π‘›βˆ’1 and is accepted immediately. This avoids scanning all 𝑁 candidates on the many tiny sets that rollout simulations visit. Because the policy is deterministic, its first two moves for every configuration can be precomputed into a 28 kB opening book (5 kB compressed). A test checks that the book is a cache, not an approximation: recomputing its entries reproduces them exactly.

3.1 Rollout as policy improvement

Background. Rollout is policy iteration cut down to one improvement step, carried out on line at the states actually reached (Bertsekas et al. 1997; Bertsekas 2020). At the current state it tries each admissible decision, follows a base policy from the resulting state, and takes the decision with the lowest total cost. It was introduced to improve heuristics for combinatorial optimisation, with conditions under which the result is never worse than the base (Bertsekas et al. 1997). It needs no training, only a base policy that can be simulated; the price is many simulations per decision.

The operator. The solver’s state is (𝑆,π‘ˆ), where π‘ˆ is the set of colours used so far; π‘ˆ fixes the canonical candidates 𝒒︀ (𝒒︀=𝑆 in hard mode). Guess 𝑔 leads to the states (𝑆𝑓𝑔,π‘ˆβˆͺπ‘ˆπ‘”), with 𝑆𝑓𝑔 its classes and π‘ˆπ‘” its colours; we keep writing π‘‡πœ‹(𝑆). For a deterministic policy πœ‹, let π‘„πœ‹(𝑆,𝑔)=𝑛+βˆ‘π‘“β‰ (𝑃,0)π‘‡πœ‹(𝑆𝑓𝑔) be the total for guessing 𝑔 once and following πœ‹ afterwards, so π‘‡πœ‹(𝑆)=π‘„πœ‹(𝑆,πœ‹(𝑆)). On rollout-tier states the app plays

πœ‹1(𝑆)=arg minπ‘”βˆˆπΆπ‘˜(𝑆)π‘„πœ‹0(𝑆,𝑔),

where πΆπ‘˜(𝑆) holds the π‘˜ candidates of highest EIG and ties go to the higher-ranked guess; elsewhere πœ‹1=πœ‹0. The base πœ‹0 is the app with rollout switched off (β€œMax EIG + exact endgame” in TableΒ 1): the branch-and-bound optimum on exact-tier states, where π‘‡πœ‹0=π‘‡βˆ—, and the max-EIG guess on all other states, rollout-tier ones included, with ties broken in favour of feasible codes, then of the smaller code index. baseTotal evaluates π‘‡πœ‹0 over all children without sampling, so the compared values of π‘„πœ‹0 are exact.

Restricting the candidates. Improvement rests on the one-step inequality

π‘„πœ‹0(𝑆,πœ‹1(𝑆))β‰€π‘„πœ‹0(𝑆,πœ‹0(𝑆))=π‘‡πœ‹0(𝑆),

(1)

which needs only πœ‹0(𝑆)βˆˆπΆπ‘˜(𝑆), not that the best guess is a candidate: the filter limits how much rollout gains, not whether (π‘˜=1 gives back πœ‹0). At a rollout-tier state, πœ‹0(𝑆) is the max-EIG guess, and rankByEig uses the same candidates, score and tie rule as greedy. So the base guess is ranked first and lies in πΆπ‘˜(𝑆) for every π‘˜β‰₯1, up to one floating-point caveat: both treat EIG values within 10βˆ’12 as equal. In the classic game, its hard variant, and the 5Γ—4, 7Γ—4 and 4Γ—5 games, the base guess was ranked first at all 50 rollout-tier states the policy visits. The guarantee would fail if filter and base disagreed, e.g. if πœ‹0 used exact search where candidates are still filtered by EIG.

Over the whole game. EquationΒ 1 covers one deviation followed by πœ‹0, but πœ‹1 deviates again at every later rollout-tier state. In the terminology of rollout algorithms (Bertsekas et al. 1997; Bertsekas 2020), πœ‹0 is sequentially consistent: after one step it continues exactly as it would have anyway, because its guess is a deterministic function of (𝑆,π‘ˆ), and because tiers depend on 𝑛 alone and grow with 𝑛, so exact-tier states have exact-tier children and π‘‡βˆ— is the cost of actually following πœ‹0 there. With πœ‹0(𝑆)βˆˆπΆπ‘˜(𝑆), the restricted rollout is then sequentially improving, meaning that EquationΒ 1 holds at every rollout-tier state, and π‘‡πœ‹1β‰€π‘‡πœ‹0 follows on every state by induction on 𝑛. Children are strictly smaller, since a guess that neither splits 𝑆 nor can win has π‘„πœ‹0=𝑛+π‘‡πœ‹0(𝑆), which EquationΒ 1 excludes for πœ‹1, and the max-EIG guess has positive EIG for 𝑛β‰₯2. On exact-tier states πœ‹1 and πœ‹0 agree on the whole subtree; on greedy-tier states they make the same guess, and the induction hypothesis applies child by child; on rollout-tier states, with 𝑔=πœ‹1(𝑆),

π‘‡πœ‹1(𝑆)=𝑛+βˆ‘π‘“π‘‡πœ‹1(𝑆𝑓𝑔)β‰€π‘„πœ‹0(𝑆,𝑔)β‰€π‘‡πœ‹0(𝑆).

The feedback is random from the codebreaker’s point of view, but 𝑇 sums over all children exactly, so the deterministic argument carries over. Two qualifications remain. An exact search that exceeds its work cap (4β‹…108 units) falls back to the greedy guess, and whether it does depends on the memo, so πœ‹0 would no longer be a function of the state; the cap was never reached in the runs above. And the guarantee is a weak inequality relative to πœ‹0 only: it does not make πœ‹1 optimal, nor comparable with rollout on another base, as the non-monotone exact-threshold ablation in FigureΒ 2 shows.

Cost. A rollout decision scores all candidates (|𝒒︀|𝑛 look-ups) and then, for each of the π‘˜ candidates, simulates πœ‹0 to the end on every child: a max-EIG step on every non-exact set below, at most 𝑁 look-ups per code and level, and memoised exact searches on the small sets at the bottom. That is about π‘˜π‘‘π‘π‘› look-ups plus the exact searches, where 𝑑 is the number of non-exact levels below 𝑆, against |𝒒︀|𝑛 for a greedy decision. A candidate is dropped once its partial total reaches the best so far, so cost grows more slowly than π‘˜: the full-tree times in TableΒ 2 rise from 1.19 s at π‘˜=1 to 5.94 s at π‘˜=20. Computing π‘‡πœ‹1 for the displayed expected moves repeats this at every rollout-tier state of the tree.

4 Implementation

The app consists of static files with no dependencies and no build step: index.html, styles.css and app.js for the interface, solver.js (about 600 lines) for the solver, which runs unchanged in Web Workers and in Node, worker.js, the generated book.js, and a service worker and manifest that make it installable and usable offline.

Two workers. A suggest worker returns the hypothesis-set size, the proposed guess, its EIG and its answer distribution. An expected worker simulates the policy against every consistent secret to obtain π‘‡πœ‹. A new request can supersede an expected-moves simulation that is still running; the app then simply terminates and respawns that worker, so the interface never waits for stale work. If the user overrides the guess, the simulation starts from the user’s guess.

Interaction. The answer pad is a triangular grid of the valid (𝑏,𝑀) outcomes, drawn as pins and annotated with the app’s predicted probability 𝑛𝑓/𝑛, so the prediction can be checked against what happens. Answers with probability zero are disabled: they would contradict an earlier answer, so the codemaker must have mis-scored a row, and Undo is one tap away. Any peg of the proposed guess can be changed through a palette, and the statistics update for the user’s guess. This shows directly how a plausible-looking alternative costs expected moves. State is kept in local storage.

Testing. The Node test suite covers:

A headless-Chrome test plays complete games through the interface. It covers undo, persistence, overrides, settings, offline reload, and the absence of horizontal scrolling at 320–390 px widths.

5 Results

All numbers below were produced by tools/analyze.mjs on a 32-thread AMD Ryzen 9 7950X3D 16-Core Processor with Node v23.4.0. Each policy is evaluated exactly, by following it against every one of the 𝑁 secrets, with no sampling.

5.1 The classic game

Strategy𝔼TotalMax1234567
Max EIG (entropy)4.415157226147161259612
Most parts4.373556686112726355697
Min. expected size4.395156966110546455833
Minimax (Knuth)4.4761580151662533694
Max EIG + exact endgame4.398957016157662058212
App: EIG + rollout + exact4.34035625618826655382
Max EIG, hard4.46455786611310350262057
Minimax, hard4.4969582861129946866254
App, hard4.44295758611310051463335
Optimum (Koyama and Lai 1993)4.340356256
TableΒ 1: Classic game (𝑀=6, 𝑃=4): expected number of guesses 𝔼, total over the 1296 secrets, worst case, and the number of secrets solved in exactly 𝑑 guesses. One-step heuristics use the same symmetry reduction and break ties in favour of feasible guesses.

TableΒ 1 places the app within the classic heuristics. Three entries serve as checks. The entropy strategy reproduces the published total of 5722 (4.415). The minimax strategy reproduces Knuth’s five-guess worst case and his total of 5801 (Knuth 1976). The app’s total of 5625 equals the minimum over all strategies established by exhaustive search (Koyama and Lai 1993). No strategy can do better, so the app’s policy is an optimal strategy for the expected number of guesses, although it never searches the full game tree. It is 0.075 guesses per game better than pure information-greedy play.

The exact endgame alone recovers only about a fifth of the gap between greedy and optimal play. Most of the gap comes from the first two guesses, and that is where rollout matters. Its first decision illustrates this. The most informative opening is 1234 (3.0567 bits), but rollout prefers 1123 (3.0437 bits). The pair of identical pegs costs 0.013 bits of information, but 1123 leads to better-balanced follow-ups. Because the policy that opens with 1123 attains the optimum, 1123 is an optimal opening for the expected-moves objective.

The app optimises the mean, not the worst case. Only 2 of the 1296 secrets need six guesses, whereas Knuth’s minimax strategy needs at most five, at the price of 0.136 extra guesses per game. Hard mode, which only ever plays codes that could be the secret, costs 0.103 guesses per game.

FigureΒ 1: Distribution of game lengths for the classic game. The app shifts mass from five to four guesses; minimax trades a worse mean for the absence of six-guess games.

5.2 Ablations

FigureΒ 2: Sensitivity of the classic game to the number of rollout candidates (left, exact threshold 60) and to the exact-search threshold (right, π‘˜=20). Dashed: optimum.
Setting𝔼TotalFull-tree time (s)
π‘˜=14.398957011.19
π‘˜=24.352656411.69
π‘˜=34.348856362
π‘˜=54.343456293.19
π‘˜=104.341856274.57
π‘˜=204.340356255.94
π‘˜=404.340356257.8
exact 𝑛≀04.344956311.51
exact 𝑛≀154.346556331.17
exact 𝑛≀304.343456292.22
exact 𝑛≀604.340356255.79
exact 𝑛≀1204.3403562514.26
TableΒ 2: Ablation data. β€œFull-tree time” is the cost of evaluating the policy against all 1296 secrets from a cold start (the same computation that yields the starting expected-moves figure).

FigureΒ 2 and TableΒ 2 show that a single rollout candidate (π‘˜=1, which is plain greedy with an exact endgame) leaves most of the gain on the table. Two or three candidates already capture most of it. Reaching the optimum takes π‘˜=20; more candidates change nothing. The optimum is therefore always among the 20 most informative guesses in the positions where rollout operates. Information ranking is an excellent filter, even where it is a poor final criterion. The exact threshold matters less once rollout is in place, and its effect is not monotone. Raising it changes the base policy whose cost rollout uses to rank candidates, so a slightly better base can lead to a slightly worse choice higher up. With π‘˜=20, thresholds of 60 or more reach the optimum.

5.3 How the information is gathered

FigureΒ 3: Classic game, app policy, averaged over the secrets still unsolved at each move: remaining uncertainty log2|𝑆| and expected information gain of the guess.

FigureΒ 3 shows the information budget of a typical game. The first two guesses each remove about three bits, roughly 23, that is, an eight-fold reduction of the hypothesis set. By move three the set is small (on average 17.6 codes, geometric mean) and the exact search takes over; from then on the guesses are chosen for winning rather than for information. Averaged over uniformly drawn secrets, the information actually obtained equals the expected information gain exactly, because the posterior is correct, so it is not plotted separately. The decision tiers used per move were: move 1: rollout 1296; move 2: rollout 1180, exact 115; move 3: exact 1287; move 4: exact 1205; move 5: exact 540; move 6: exact 2.

5.4 Other game sizes

𝑀𝑃𝑁BoundMax EIGAppMaxApp hardMaxOpening
2381.8752.2502.25032.2503112
33272.6302.7042.70442.7044112
43642.8443.2503.21943.2194112
531253.3363.6243.60853.6405123
632163.6163.9813.95454.0006123
733433.7584.3384.29764.3827123
835123.8384.6784.60764.7648123
937294.0844.9964.93365.1439123
10310004.3325.3105.24775.52910123
24162.0632.7502.75042.75041112
34812.8153.0863.03743.04941123
442563.2273.5633.53543.54751123
546253.6833.9623.94153.96251123
6412963.8474.4154.34064.44361123
7424013.9264.7394.71264.75971234
8440964.3715.0515.02175.09581234
9465614.6075.3235.30375.40891234
104100004.7425.6215.60285.740101234
25322.3443.3133.03143.031411122
352432.9143.3583.35843.391511123
4510243.6073.8843.86653.889611223
5531253.8714.3504.32864.349611223
6577764.0174.7694.76074.769711223
TableΒ 3: Expected number of guesses for every supported configuration (𝑀𝑃≀104): the counting bound 𝐿(𝑁)/𝑁, pure max-EIG, the app in normal and hard mode with worst cases, and the app’s opening (colours numbered from 1).

TableΒ 3 extends the analysis to all 23 supported configurations. The app’s advantage over pure max-EIG is largest for mid-sized games, where rollout operates on the first moves. For the largest games the first moves are still chosen by max EIG, and the gap narrows. The counting bound is loose (it assumes that every guess splits the set into equal classes), but it shows how the difficulty grows: roughly log|π’ͺοΈ€|𝑁 plus a constant.

5.5 Speed

GameStatesSampledSuggest p50p95maxExpected p95max
7Γ—335350.10.54.20.70.8
7Γ—3 hard343400.10.30.10.3
8Γ—337370.15.99.311.1
8Γ—3 hard353500.70.90.20.3
9Γ—336362.1241001.31.5
9Γ—3 hard35350.11.33.50.20.2
10Γ—356561881515.614
10Γ—3 hard35350.417260.40.6
4Γ—4585800.10.100.2
4Γ—4 hard595900000.2
5Γ—4919100.41.500.3
5Γ—4 hard909000.10.100.3
6Γ—41021020.32.4210.31.3
6Γ—4 hard949400.22.900.4
7Γ—43361140.96313569
7Γ—4 hard10510502140.111
8Γ—48561031.211017926104
8Γ—4 hard1081080.1181300.20.5
9Γ—419311011.87892247480
9Γ—4 hard2471090.949207219
10Γ—430911022.628684691336
10Γ—4 hard3521030.81072368.863
4Γ—517510800.52.700.4
4Γ—5 hard16510300.10.202.1
5Γ—56401001377428.2
5Γ—5 hard21312700.24.300.4
6Γ—520621022.413014659110
6Γ—5 hard3181100.123300.30.8
TableΒ 4: Desktop latency in ms (Node, cold solver per state) for positions beyond the opening book that the policy actually reaches. β€œSuggest” is the time to choose the next guess; β€œExpected” is the time to compute the exact expected number of remaining moves. The largest 40 positions are always included in the sample.
GameMovesFirstSuggestExpected
6Γ—44.5613233
6Γ—4 hard4.5373334
7Γ—44.75723396
8Γ—45168132330
10Γ—45.752034629
5Γ—54.514133146
6Γ—54.252282113
TableΒ 5: End-to-end latency in headless desktop Chrome (ms, maximum over four games per row, measured by polling the DOM, so about 30 ms is the floor). β€œFirst”: page load to first usable suggestion, including building the feedback table in the worker. β€œSuggest” and β€œexpected”: time from tapping an answer to the next suggestion and to the expected-moves figure, for moves 2 onwards.

TableΒ 4 and TableΒ 5 show that the hybrid policy fits a phone budget. No decision in any configuration takes longer than 236 ms on the desktop, and the classic game never exceeds 21 ms. We could not measure phone latency directly. Chrome’s CPU throttling applies to the page thread only, not to the Web Workers that run the solver. Assuming the usual factor of 3–5 between desktop and phone single-thread JavaScript performance, the slowest decision stays around one second, and the classic game stays instantaneous. Thanks to the opening book, the expensive first two decisions are free, and so is the expensive initial expected-moves figure (several seconds of computation for the classic game). Later decisions involve sets that the tiers keep small. The slowest positions are mid-sized sets in the largest games, where rollout simulations score many candidates without a feedback table.

6 Discussion

What the app demonstrates. The explicit hypothesis table makes the Bayesian reading concrete: the board shows how many codes are left after each answer, and the answer pad shows the predicted distribution of the next answer. Information gain explains most of good play. The remaining few hundredths of a guess come from planning: preferring guesses that leave well-structured follow-ups and, late in the game, guesses that can win.

Limitations. Optimality is established for the classic game only, by comparison with the published optimum. For other sizes, the policy is guaranteed only to be no worse than its greedy base (SectionΒ 3.1), and the cost-aware tiers deliberately give up up to 0.01 guesses per game in the largest games to keep every decision under a second on a phone. Full exact optimisation from the first move remains out of reach in a browser for general 𝑀, and the app does not attempt it. The symmetry reduction exploits colour permutations only. Adding position permutations would shrink the candidate sets further and would be the first step towards computing optimal opening books offline. The app assumes the codemaker scores correctly. It detects impossible answers but does not reason about noisy feedback, which would require a likelihood model instead of hard elimination.

References

Dimitri P. Bertsekas (2020). Rollout, Policy Iteration, and Distributed Reinforcement Learning. Belmont, MA: Athena Scientific.

Dimitri P. Bertsekas, John N. Tsitsiklis, and Cynara Wu (1997). Rollout Algorithms for Combinatorial Optimization. In Journal of Heuristics 3.3, pages 245–262.

Kathryn Chaloner and Isabella Verdinelli (1995). Bayesian Experimental Design: A Review. In Statistical Science 10.3, pages 273–304.

Donald E. Knuth (1976). The Computer as Master Mind. In Journal of Recreational Mathematics 9.1, pages 1–6.

Kenji Koyama and Tony W. Lai (1993). An Optimal Mastermind Strategy. In Journal of Recreational Mathematics 25.4, pages 251–256.

Dennis V. Lindley (1956). On a Measure of the Information Provided by an Experiment. In The Annals of Mathematical Statistics 27.4, pages 986–1005.