Coverage -- attack bird after game closed
[open-adventure.git] / notes.adoc
1 = Open Adventure Maintainer's Notes =
2 by Eric S. Raymond
3
4 In which we explain what has been done to this code since Don Woods
5 authorized us to ship it under an open-source license.  There's a
6 separate link:history.html[history] describing how it came to us.
7
8 == Who we are ==
9
10 The principal maintainers of this code are Eric S. Raymond and Jason
11 Ninneman.  Eric received Don Woods's encouragement to update and ship
12 the game; Jason signed on early in the process to help. The assistance
13 of Peje Nilsson in restructuring some particularly grotty gotos is
14 gratefully acknowledged. Petr Voropaev contributed fuzz testing. Aaron
15 Traas did a lot of painstaking work to improve test coverage.
16
17 == Nomenclature ==
18
19 This project is called "Open Adventure" because it's not at all clear
20 to number Adventure past 2.5 without misleading or causing
21 collisions. Various of the non-mainline versions have claimed to be
22 versions 3, 4, 5, 6, 7 and for all I know higher than that.  It seems
23 best just to start a new numbering series while acknowledging the
24 links back.
25
26 We have reverted to "advent" for the binary to avoid a name collision
27 with the BSD Games version.
28
29 == Philosophy ==
30
31 Extreme care has been taken not to make changes that would alter the
32 logic of the game as we received it from Don Woods, except to fix
33 glitches that were clearly bugs.  By policy, all user-visible
34 changes must be revertible with the -o (oldstyle) option.
35
36 It is a goal of this project to exactly preserve the *intended
37 behavior* of 430-point Adventure, but the implementation of it is fair
38 game for improvement. In particular, we are concerned to move it to a
39 form that is (a) readable, and (b) friendly to forward translation to
40 future languages.  It has already survived a move from FORTRAN to C; a
41 future as a Python or Go translation seems possible, even probable.
42
43 == Functional changes ==
44
45 Bug fixes:
46
47 * Reading the relocated Witt's End sign in the endgame didn't work right.
48
49 * Behavior when saying the giant's magic words outside his room wasn't
50   quite corrected - the game responded as though the player were in
51   the room.
52  
53 * Attempting to extinguish an unlit urn caused it to lose its oil.
54
55 By default, advent issues "> " as a command prompt.  This feature
56 became common in many variants after the original 350-point version,
57 but was never backported into Crowther & Woods's main line before now.
58 The "-o" (oldstyle) option reverts the behavior.
59
60 There is a set of standard one-letter command aliases conventional in modern
61 text adventure games; 'l' and 'x'; for 'look' (or 'examine'), 'z' to do nothing
62 for a turn, 'i' for 'inventory', 'g' for 'get', and 'd' for 'drop'.  The 'd'
63 alias collides with 'd' for 'down', but the others have been implemented.
64 The "-o" (oldstyle) option disables them.
65
66 A "seed" command has been added.  This is not intended for human use
67 but as a way for game logs to set the PRNG (pseudorandom-number generator) so
68 that random events (dwarf & pirate appearances, the bird's magic word)
69 will be reproducible.
70
71 A -l command-line option has been added. When this is given (with a
72 file path argument) each command entered will be logged to the
73 specified file.  Additionally, a generated "seed" command will be put
74 early in the file capturing the randomized start state of the PRNG
75 so that replays of the log will be reproducible.
76
77 Using "seed" and -l, the distribution now includes a regression-test
78 suite for the game.  Any log captured with -l (and thus containing
79 a "seed" command) will replay reliably, including random events.
80
81 The adventure.text file is no longer required at runtime.  Instead, an
82 adventure.yaml file is compiled at build time to a source module
83 containing C structures, which is then linked to the advent
84 binary.  The YAML is drastically easier to read and edit than
85 the old ad-hoc format of adventure.txt.
86
87 The game-save format has changed.  This was done to simplify the
88 FORTRAN-derived code that formerly implemented the save/restore
89 functions; without C's fread(3)/fwrite() and structs it was
90 necessarily pretty ugly by modern standards. Encryption and
91 checksumming have been discarded - it's pointless to try
92 tamper-proofing saves when everyone has the source code.
93
94 A -r command-line been added. When it is given (with a file path
95 argument) it is functionally equivalent to a RESTORE command.
96
97 == Translation ==
98
99 The 2.5 code was a mechanical C translation of a FORTRAN original.
100 There were gotos everywhere and the code was, though functional,
101 ugly and quite unreadable.
102
103 Jason Ninneman and I have moved it to what is almost, but not quite,
104 idiomatic modern C.  We refactored the right way, checking correctness
105 against a comprehensive test suite that we built first and verified
106 with coverage tools (we have over 95% coverage, with the remaining
107 confined to exception cases that are very difficult to reach). This is
108 what you are running when you do "make check".
109
110 The move to modern C entailed some structural changes.  The most
111 important was the refactoring of over 350 gotos into if/loop/break
112 structures.  We also abolished almost all shared globals; the main one
113 left is a struct holding the game's saveable/restorable state.
114
115 The original code was greatly complicated by a kind of bit-packing
116 that was performed because the FORTRAN it was written in had no string
117 type.  Text from the adventure.text file was compiled into sequences
118 of sixbit code points in a restricted character set, packed 5 to a
119 32-bit word (it seems clear from the code that words were originally
120 *6* chars each packed into a PDP-10 36-bit word).  A command noun or
121 verb was one of these words, and what would be string operations in a
122 more recent language were all done on sequences of these words.
123
124 We have removed all this bit-packing cruft in favor of proper C
125 strings.  C strings may be a weak and leaky abstraction, but this is
126 one of the rare cases in which they are an obvious improvement over
127 what they're displacing...
128
129 We have also conducted extensive fuzz testing on the game using
130 afl (American Fuzzy Lop).  We've found and fixed some crashers in
131 our new code (which occasionally uses malloc(3)), but none as yet
132 in Don's old code (which didn't).
133
134 The code falls short of being fully modern C in the following
135 ways:
136
137 * We have not attempted to translate the old code to pointer-based
138   idioms (as opposed, in particular, to integer-based array indexing).
139   We don't need whatever minor performance gains this might collect,
140   and the choice to refrain will make forward translation into future
141   languages easier.
142
143 * There are a few gotos left that resist restructuring; all are in the
144   principal command interpreter function implementing its state
145   machine.
146
147 * Linked lists (for objects at a location) are implemented using an array
148   of link indices. This is a surviving FORTRANism that is quite unlike
149   normal practice in C or any more modern language.  We have not tried
150   to fix it because doing so would (a) be quite difficult, and (b)
151   compromise forward-portability to other languages.
152
153 * Much of the code still assumes one-origin array indexing.  Thus,
154   arrays are a cell larger than they strictly need to be and cell 0 is
155   unused.
156
157 * The code is still mostly typeless, slinging around machine longs
158   like a FORTRAN or BCPL program.  Some (incomplete) effort has been made
159   to introduce semantic types.
160
161 We have made exactly one minor architectural change.  In addition to the
162 old code's per-object state-description messages, we now have a per-object
163 message series for state *changes*.  This makes it possible to pull a fair
164 amount of text out of the arbitrary-messages list and associate those
165 mesages with the objects that conceptually own them.
166
167 // end