! ZENO'S BRIDGE ! ! Example program for floating-point library. ! ! Adapted from the bridge in Beyond Zork, which used rational-number arithmetic ! ! Because I'm merciful, and IEEE-754 floating point allows it, you can actually ! walk across this one. Eventually. Constant Story "ZENO'S BRIDGE"; Constant Headline "^An Interactive Floating-Point Demonstraction^ Copyright (c) 2002 by Kevin Bracey.^ Adapted from Beyond Zork, (c) 1987 Infocom.^"; Include "Parser"; Include "VerbLib"; Include "FP"; Array zero --> 2; Array one --> 2; Array two --> 2; Array five --> 2; Array ten --> 2; Array hundred --> 2; Array thousand --> 2; [ InitFPConstants; fitos(zero, 0); fitos(one, 1); fitos(two, 2); fitos(five, 5); fitos(ten, 10); fitos(hundred, 100); fitos(thousand, 1000); ]; Object North_Chasm "North Chasm" with name 'mist' 'chasm', description "You're shivering on the north edge of a broad chasm. Clammy mists chill the air, and the ground trembles with the roar of a cataract.^^ Your heart sinks as you inspect the crude rope bridge spanning the chasm. A notice hangs near the bridge's entrance.", s_to bridge_n, has light; Object -> bridge_n "bridge" with name 'crude' 'narrow' 'long' 'rope' 'bridge', description "The long, narrow bridge leads south across the roaring water.", door_dir s_to, door_to [; On_Bridge.reset(self.door_dir); return On_Bridge; ], has door scenery open; Object South_Chasm "South Chasm" with name 'mist' 'chasm', description "You're shivering on the south edge of a broad chasm. Clammy mists chill the air, and the ground trembles with the roar of a cataract.^^ Your heart sinks as you inspect the crude rope bridge spanning the chasm. A notice hangs near the bridge's entrance.", n_to bridge, has light; Object -> bridge "bridge" with name 'crude' 'narrow' 'long' 'rope' 'bridge', description "The long, narrow bridge leads north across the roaring water.", door_dir n_to, door_to [; On_Bridge.reset(self.door_dir); return On_Bridge; ], has door scenery open; Object "notice" with name 'notice' 'sign', description [; print "The notice says,^^"; font off; print " ZENO'S BRIDGE^ Cross at thy Own Risk^"; font on; ], found_in North_Chasm South_Chasm, has scenery; Array UnitTable --> "Metres" hundred "Centimetres" ten "Millimetres" thousand "Micrometres" thousand "Nanometres" thousand "Picometres" thousand "Femtometres" thousand "Attometres" thousand "Zeptometres" thousand "Yoctometres" 0; Object On_Bridge "Zeno's Bridge" with short_name [ n u; if (self.vicinity == n_to) n = "North"; else n = "South"; if (feq(self.&position, five)) { print "Halfway to the ", (string) n, " End"; rtrue; } ! Hmm, this should be table-driven fcpy(self.&tmp, self.&position); u = 0; while (UnitTable-->(u*2+1) ~= 0) { if (flt(self.&tmp, one)) { fmul(self.&tmp, self.&tmp, UnitTable-->(u*2+1)); u++; } else break; } u = UnitTable-->(u*2); fesetprintprecision(3); print (fp) self.&tmp, (char) ' ', (string) u; print " from the ", (string) n, " End"; rtrue; ], description [; print "The entire bridge jerks and sways as you struggle to keep your footing on the slippery ropes. "; self.number = (self.number+1) % 4; switch (self.number) { 1: "Clammy mist obscures your view of either end."; 2: "Your ears ring from the roar of water far below."; 3: "Both edges of the chasm are obscured in the clammy mist."; 0: "The deafening roar of water is giving you a headache."; } ], n_to [; return self.my_move(n_to); ], s_to [; return self.my_move(s_to); ], my_move [ dir; give self ~visited; if (dir ~= self.vicinity) { ! Must end up nearer the other end if we reverse direction fsub(self.&position, ten, self.&position); self.vicinity = dir; } fdiv(self.&position, self.&position, two); if (feq(self.&position, zero)) { print "With a sickening underflow sensation, you stagger off the bridge.^"; if (self.vicinity == n_to) return North_Chasm; else return South_Chasm; } else { return self; } ], reset [ dir; fitos(self.&position, 5); self.vicinity = dir; give self ~visited; ], number 0, position 0 0, tmp 0 0, vicinity n_to, has light; [ Initialise; location = South_Chasm; InitFPConstants(); ]; Include "Grammar";