cleanup winner README.md files
Fixed cases where there was a bad trailing backslash. Improved a few cases where a code block was needed to highlight some text. Changed a few cases where a code block needed to declared as, say, a sh code block. Fixed a few cases where the winner information was not properly formatted. Plus a few nits and clarifying text was added.
This commit is contained in:
1 parent
394f710bc3
commit
360708f858
120 files changed
+1198
-1024
No files matched your search
+93
-86
@@ -38,9 +38,11 @@ Make and run as follows:
|
||||
where the `move_location` is a digit from 1 to 9 that represents
|
||||
a move on a tic-tac-toe board:
|
||||
|
||||
1 2 3
|
||||
4 5 6
|
||||
7 8 9
|
||||
```
|
||||
1 2 3
|
||||
4 5 6
|
||||
7 8 9
|
||||
```
|
||||
|
||||
If you omit `move_location`, then the computer moves first. For your\
|
||||
next move, recompile `nextmove.c` and play it again:
|
||||
@@ -61,7 +63,7 @@ make ttt
|
||||
./ttt next_move
|
||||
|
||||
```
|
||||
\
|
||||
|
||||
The shell script determines when the game is over, and automatically\
|
||||
replaces `merlyn.c` (copied from [westley.c](westley.c) with an improved version after a loss. The [ttt](ttt.sh) script\
|
||||
has two other modes:
|
||||
@@ -172,113 +174,118 @@ longer loses games.
|
||||
If you want a program that never loses, simply replace the string
|
||||
`"9999999999 :-| "` with `"9883857753 :-| "`.
|
||||
|
||||
### How it works (rot13 to read):
|
||||
### How it works
|
||||
|
||||
The vertical "bars" of the grid are identical functions, with the
|
||||
name of the function as a(), b(), or c(). After each function is
|
||||
called, the global variables X and O contain bitmasks of where all
|
||||
the Xs and Os are placed. The statement:
|
||||
|
||||
Gur iregvpny "onef" bs gur tevq ner vqragvpny shapgvbaf, jvgu gur
|
||||
anzr bs gur shapgvba nf n(), o(), be p(). Nsgre rnpu shapgvba vf
|
||||
pnyyrq, gur tybony inevnoyrf K naq B pbagnva ovgznfxf bs jurer nyy
|
||||
gur Kf naq Bf ner cynprq. Gur fgngrzrag:
|
||||
```c
|
||||
X=- <char> -1;
|
||||
``
|
||||
|
||||
K=- <pune> -1;
|
||||
evaluates to 1, -1, or -2 when X is 1 and <char> is one of "X",
|
||||
"0", or " ". The function S(&X) sets the appropriate bits in
|
||||
(global var) X and O and resets the value of &X to 1. This is how
|
||||
the current position is computed.
|
||||
|
||||
rinyhngrf gb 1, -1, be -2 jura K vf 1 naq <pune> vf bar bs "K",
|
||||
"0", be " ". Gur shapgvba F(&K) frgf gur nccebcevngr ovgf va
|
||||
(tybony ine) K naq B naq erfrgf gur inyhr bs &K gb 1. Guvf vf ubj
|
||||
gur pheerag cbfvgvba vf pbzchgrq.
|
||||
The player's move is OR'd into the X mask, and (if it is the
|
||||
opening move) the strategy string's first character is set to the
|
||||
player's first move (or "5" if the computer moves first).
|
||||
|
||||
Gur cynlre'f zbir vf BE'q vagb gur K znfx, naq (vs vg vf gur
|
||||
bcravat zbir) gur fgengrtl fgevat'f svefg punenpgre vf frg gb gur
|
||||
cynlre'f svefg zbir (be "5" vs gur pbzchgre zbirf svefg).
|
||||
The evalution function y(M) checks if the mask has a winning
|
||||
pattern (any of the first eight bitmasks of the w[N array), and
|
||||
sets the variable q to 0 if it does.
|
||||
|
||||
Gur rinyhgvba shapgvba l(Z) purpxf vs gur znfx unf n jvaavat
|
||||
cnggrea (nal bs gur svefg rvtug ovgznfxf bs gur j[] neenl), naq
|
||||
frgf gur inevnoyr d gb 0 vs vg qbrf.
|
||||
The player's move is evaluated to see if the human has won. The
|
||||
smiley is set to :-) or :-( depending on this. Also, if the human
|
||||
has won, the digit in the strategy string is decremented to change
|
||||
the computer's play for next game.
|
||||
|
||||
Gur cynlre'f zbir vf rinyhngrq gb frr vs gur uhzna unf jba. Gur
|
||||
fzvyrl vf frg gb :-) be :-( qrcraqvat ba guvf. Nyfb, vs gur uhzna
|
||||
unf jba, gur qvtvg va gur fgengrtl fgevat vf qrperzragrq gb punatr
|
||||
gur pbzchgre'f cynl sbe arkg tnzr.
|
||||
If the human has NOT won, the e(N,M) function evaluates if ANY move
|
||||
not in mask N can produce a win in mask M. The first evaluation
|
||||
e(X,O) checks if O can make a legal winning move. If so, the
|
||||
computer has a winning move and makes it. If not, the smiley is
|
||||
set to :-|, and a non-winning move is generated.
|
||||
|
||||
Vs gur uhzna unf ABG jba, gur r(A,Z) shapgvba rinyhngrf vs NAL zbir
|
||||
abg va znfx A pna cebqhpr n jva va znfx Z. Gur svefg rinyhngvba
|
||||
r(K,B) purpxf vs B pna znxr n yrtny jvaavat zbir. Vs fb, gur
|
||||
pbzchgre unf n jvaavat zbir naq znxrf vg. Vs abg, gur fzvyrl vf
|
||||
frg gb :-|, naq n aba-jvaavat zbir vf trarengrq.
|
||||
A non-winning move first checks if X can win in one move; if so,
|
||||
this move is selected, blocking the win. Otherwise, a move is
|
||||
generated by looking down the list of "move templates". The first
|
||||
move template that generates a move that is NOT already occupied by
|
||||
an X or O is returned.
|
||||
|
||||
N aba-jvaavat zbir svefg purpxf vs K pna jva va bar zbir; vs fb,
|
||||
guvf zbir vf fryrpgrq, oybpxvat gur jva. Bgurejvfr, n zbir vf
|
||||
trarengrq ol ybbxvat qbja gur yvfg bs "zbir grzcyngrf". Gur svefg
|
||||
zbir grzcyngr gung trarengrf n zbir gung vf ABG nyernql bpphcvrq ol
|
||||
na K be B vf erghearq.
|
||||
The "move templates" are static tic-tac-toe positions that generate
|
||||
possible moves by making the e() function return "winning" moves,
|
||||
e.g. the template:
|
||||
|
||||
Gur "zbir grzcyngrf" ner fgngvp gvp-gnp-gbr cbfvgvbaf gung trarengr
|
||||
cbffvoyr zbirf ol znxvat gur r() shapgvba erghea "jvaavat" zbirf,
|
||||
r.t. gur grzcyngr:
|
||||
```
|
||||
. . .
|
||||
O , O (this is the value 40; 2^3+2^5)
|
||||
. . . ("O"s are 1 bits, "." and "," are 0 bits)
|
||||
```
|
||||
|
||||
. . .
|
||||
B , B (guvf vf gur inyhr 40; 2^3+2^5)
|
||||
. . . ("B"f ner 1 ovgf, "." naq "," ner 0 ovgf)
|
||||
...will make the e() function return a center move, as
|
||||
this is the only move that produces three in a row. Notice that
|
||||
the computer does not consider which cells contain Xs and Os when
|
||||
making a template move, only which cells are empty and not-empty.
|
||||
This makes for unusual play.
|
||||
|
||||
...jvyy znxr gur r() shapgvba erghea n pragre zbir, nf
|
||||
guvf vf gur bayl zbir gung cebqhprf guerr va n ebj. Abgvpr gung
|
||||
gur pbzchgre qbrf abg pbafvqre juvpu pryyf pbagnva Kf naq Bf jura
|
||||
znxvat n grzcyngr zbir, bayl juvpu pryyf ner rzcgl naq abg-rzcgl.
|
||||
Guvf znxrf sbe hahfhny cynl.
|
||||
The templates are carefully chosen to eventually block all traps
|
||||
that X can try, by just blundering in the way.
|
||||
|
||||
Gur grzcyngrf ner pnershyyl pubfra gb riraghnyyl oybpx nyy gencf
|
||||
gung K pna gel, ol whfg oyhaqrevat va gur jnl.
|
||||
Also note that the winning & strategy templates are part of the
|
||||
compile line, making it possible to change the rules of the game by
|
||||
changing the compile line.
|
||||
|
||||
Nyfb abgr gung gur jvaavat & fgengrtl grzcyngrf ner cneg bs gur
|
||||
pbzcvyr yvar, znxvat vg cbffvoyr gb punatr gur ehyrf bs gur tnzr ol
|
||||
punatvat gur pbzcvyr yvar.
|
||||
The templates are:
|
||||
|
||||
Gur grzcyngrf ner:
|
||||
```
|
||||
O , O
|
||||
, , ,
|
||||
O , O
|
||||
|
||||
B , B
|
||||
, , ,
|
||||
B , B
|
||||
, . .
|
||||
. O .
|
||||
. . O
|
||||
|
||||
, . .
|
||||
. B .
|
||||
. . B
|
||||
. . .
|
||||
O , O
|
||||
. . .
|
||||
|
||||
. . .
|
||||
B , B
|
||||
. . .
|
||||
. . .
|
||||
O O ,
|
||||
. . .
|
||||
|
||||
. . .
|
||||
B B ,
|
||||
. . .
|
||||
. . .
|
||||
O , O
|
||||
. . .
|
||||
|
||||
. . .
|
||||
B , B
|
||||
. . .
|
||||
. , ,
|
||||
. O .
|
||||
O O ,
|
||||
|
||||
. , ,
|
||||
. B .
|
||||
B B ,
|
||||
O , O
|
||||
, , .
|
||||
O . .
|
||||
|
||||
B , B
|
||||
, , .
|
||||
B . .
|
||||
, . O
|
||||
O , O
|
||||
O . ,
|
||||
|
||||
, . B
|
||||
B , B
|
||||
B . ,
|
||||
O . ,
|
||||
O , O
|
||||
, . O
|
||||
|
||||
B . ,
|
||||
B , B
|
||||
, . B
|
||||
O , O
|
||||
, , ,
|
||||
O , O
|
||||
```
|
||||
|
||||
B , B
|
||||
, , ,
|
||||
B , B
|
||||
|
||||
N qvtvg bs "9" zrnaf fgneg jvgu gur svefg grzcyngr, "8" fgnegf ng
|
||||
gur frpbaq, rgp. Gur grzcyngrf ner fpnaarq hagvy n yrtny zbir vf
|
||||
sbhaq. N grzcyngr vf fpnaarq sebz obggbz gb gbc, evtug gb yrsg
|
||||
(v.r. zbir 9 vf grfgrq svefg, gura 8, qbja gb zbir 1).
|
||||
A digit of "9" means start with the first template, "8" starts at
|
||||
the second, etc. The templates are scanned until a legal move is
|
||||
found. A template is scanned from bottom to top, right to left
|
||||
(i.e. move 9 is tested first, then 8, down to move 1).
|
||||
|
||||
|
||||
## Copyright and CC BY-SA 4.0 License:
|
||||
|
||||
Reference in new issue
Block a user