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