mm.c (rate): Simplify the algorithm.
[mm] / mm.6
CommitLineData
57ecfc46
MW
1.TH mm 6 "Mark Wooding"
2.SH NAME
3mm \- simple Mastermind game
4.SH SYNOPSIS
5.B mm
39aedf80 6.RB [ \-CHSa ]
57ecfc46
MW
7.RI [ holes " " colours ]
8.RI [ code ...]
9.SH DESCRIPTION
10The
11.B mm
12program plays the game of Mastermind.
13.SS "About the game"
39aedf80
MW
14In the original game,
15there are a collection of coloured code pegs,
16and a board.
17The board has a number of rows of holes.
18There are two players.
19One player
20\(en the code setter \(en
21chooses a
22.I code
23\en a sequence of coloured pegs \(en and
24enters it at their end of the board,
25concealed by a small screen from the other player.
26The other player
27\(en the code guesser \(en
28attempts to guess the code.
57ecfc46 29.PP
39aedf80
MW
30In each turn,
31the guesser makes a guess
32by filling in a row of holes with coloured pegs.
33The setter then
57ecfc46 34.I scores
39aedf80
MW
35the guess.
36They award a black scoring peg
37for each peg in the guess which matches
38the corresponding peg in the code,
39i.e., the right colour in the right place.
40They award a white scoring peg
41for each guess peg which matches a code peg in colour
42but not in position,
43i.e., the right colour in the wrong place.
44Each guess peg can be scored at most once.
45Only the number of black or white scoring pegs matters;
46the order in which they're placed on the board is irrelevant.
57ecfc46 47.PP
39aedf80
MW
48The game ends either if the guesser guesses the code correctly,
49or if they run out of guessing rows on the board.
50.SS "User interface"
51Since this is a computer game,
52there is no physical board on which to run out of space.
53The game can therefore continue until either
54the guesser successfully guesses the code,
55or they give up.
56.PP
57Since this is a very simple program,
58intended mostly to be a substrate for the computer player,
59it doesn't have coloured pegs.
60Instead, it uses numbers,
61between zero and some upper limit specified on the command line
62(see later).
63The default number of `colours' is 6,
64and so the numbers should be between 0 and 5 inclusive.
65.PP
66When a human is expected to
67.I guess
68a code,
69they should type in a sequence of numbers
70representing the desired colours, separated by whitespace,
71and followed by a newline.
72.PP
73When a human is expected to
74.I rate
75a guess,
76they should type the number of black scoring pegs awarded
77(correct colour, correct place)
78and by the number of white scoring pegs awarded
79(correct colour, but wrong place),
80separated by whitespace and followed by a newline.
81.SS "Command-line options"
82The following command-line options are recognized.
83.TP
84.B "\-C"
85Computer guesser.
86A human chooses the code,
87and the computer attempts to guess.
88This is the default mode.
89If a code is provided on the command line,
90then the computer will automatically rate its own guesses against it
91(but promises not to cheat);
92otherwise the human user is expected to rate the guesses.
93.TP
94.B "\-H"
95Human guesser.
96The computer chooses the code
97unless one was provided on the command line
98(presumably by a
99.I different
100human),
101and the human tries to guess it.
102.TP
103.B "\-S"
104Solver mode.
105This mode can be used to cheat at some other Mastermind-ish game.
106Initially, the user is expected to enter
107their guesses in that other game,
108and the ratings which their guesses received.
109After the user has finished entering their guesses,
110they should type
111.RB ` . '\&
112followed by a newline in place of the guess,
113and the computer will start offering its own sensible guesses.
114The human should relay these to the other game,
115and enter the rating.
116.TP
117.B "\-a"
118Tournament mode.
119This mode simply runs the computer guesser
120against every possible input code
121and (eventually) reports some statistics about how well it did.
122This is used to compare computer-guesser algorithms.
123.SS "Command-line arguments"
124Following the options, if any,
125game parameters may be specified,
126as a pair of numbers
127.I holes
128and
129.IR colours .
130The
131.I holes
132is the number of pegs in a code, and defaults to 4;
133the
134.I colours
135is the number of differently coloured pegs, and defaults to 6.
136.PP
137Following the parameters, a code may be given,
138as a sequence of small integers.
139This is ignored in tournament and solver modes;
140in the computer and human guesser modes,
141it gets the computer to rate guesses against the provided code,
142rather than asking the human to rate (which is surprisingly error-prone)
143or getting the computer to rate against a secret, random code.
144.SH BUGS
145The user interface is terrible.
146.SH SEE ALSO
147.BR guess (6)
148(in Simon Tatham's portable puzzle collection).
149.SH AUTHOR
150Mark Wooding,
151<mdw@distorted.org.uk>