From b4338d649144f9991b77de7d76b6665aa65bae86 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Wed, 22 Feb 2012 03:12:04 -0500 Subject: [PATCH] Fix phantom-base bug - was due to an off-by-one in the star allocation loop. --- sst.py | 14 +++-- test/test3.chk | 132 ----------------------------------------- test/test3.log | 39 ------------ test/test4.chk | 7 ++- test/test5.chk | 158 ------------------------------------------------- test/test5.log | 44 -------------- 6 files changed, 16 insertions(+), 378 deletions(-) delete mode 100644 test/test3.chk delete mode 100644 test/test3.log delete mode 100644 test/test5.chk delete mode 100644 test/test5.log diff --git a/sst.py b/sst.py index 376f05a..b3264ee 100755 --- a/sst.py +++ b/sst.py @@ -159,8 +159,10 @@ class Quadrant: class Page: def __init__(self): self.stars = None - self.starbase = None + self.starbase = False self.klingons = None + def __repr__(self): + return "<%s,%s,%s>" % (self.klingons, self.starbase, self.stars) def fill2d(size, fillfun): "Fill an empty list in 2D." @@ -1179,8 +1181,8 @@ def torpedo(origin, bearing, dispersion, number, nburst): game.state.baseq = filter(lambda x: x != game.quadrant, game.state.baseq) game.quad[w.i][w.j] = '.' game.base.invalidate() - game.state.galaxy[game.quadrant.i][game.quadrant.j].starbase -= 1 - game.state.chart[game.quadrant.i][game.quadrant.j].starbase -= 1 + game.state.galaxy[game.quadrant.i][game.quadrant.j].starbase = False + game.state.chart[game.quadrant.i][game.quadrant.j].starbase = False game.state.basekl += 1 newcnd() return None @@ -5435,10 +5437,12 @@ def setup(): game.instar = 0 for i in range(GALSIZE): for j in range(GALSIZE): - k = randrange(1, QUADSIZE**2/10+1) + k = randrange(1, QUADSIZE**2/10) game.instar += k game.state.galaxy[i][j].stars = k # Locate star bases in galaxy + if game.idebug: + prout("=== Allocating %d bases" % game.inbase) for i in range(game.inbase): while True: while True: @@ -5461,6 +5465,8 @@ def setup(): prout("=== Saving base #%d, close to #%d" % (i, j)) if not contflag: break + if game.idebug: + prout("=== Placing base #%d in quadrant %s" % (i, w)) game.state.baseq.append(w) game.state.galaxy[w.i][w.j].starbase = game.state.chart[w.i][w.j].starbase = True # Position ordinary Klingon Battle Cruisers diff --git a/test/test3.chk b/test/test3.chk deleted file mode 100644 index bad3144..0000000 --- a/test/test3.chk +++ /dev/null @@ -1,132 +0,0 @@ -sst2k: seed set to 1329859817 - - --SUPER- STAR TREK - -Would you like a regular, tournament, or saved game? # recorded by esr@snark on Tue Feb 21 16:30:17 2012 -# Ends with a torpedo miss -r -Would you like a Short, Medium, or Long game? s -Are you a Novice, Fair, Good, Expert, or Emeritus player? n -Choose your game style (plain, almy, fancy or just press enter): - - -It is stardate 2279. The Federation is being attacked by -a deadly Klingon invasion force. As captain of the United -Starship U.S.S. Enterprise, it is your mission to seek out -and destroy this invasion force of 4 battle cruisers. -You have an initial allotment of 7 stardates to complete -your mission. As you proceed you may be given more time. - -You will have 4 supporting starbases. -Starbase locations- 5 - 2 1 - 7 2 - 2 8 - 2 - -The Enterprise is currently in Quadrant 1 - 5 Sector 5 - 8 - -Good Luck! -COMMAND> -COMMAND> move aut 2 8 5 5 - -Ensign Chekov- "Course laid in, Captain." - -Entering Quadrant 2 - 8. -COMMAND> -COMMAND> move aut 4 7 5 5 - -Ensign Chekov- "Course laid in, Captain." - -Entering Quadrant 4 - 7. -COMMAND> -COMMAND> mov aut 6 1 - -COMMAND> -COMMAND> move aut 5 6 2 2 - -Ensign Chekov- "Course laid in, Captain." - -Entering Quadrant 5 - 6. - -130 unit hit on the Enterprise from Klingon at Sector 8 - 10 - - -Energy left 4178 shields down 100%, torpedoes left 10 -COMMAND> phasers - -Manual or automatic? aut -Phasers locked on target. Energy available: 4043.35 -180 units required. Units to fire= 300 - -157 unit hit on Klingon at Sector 8 - 10 -***Klingon at Sector 8 - 10 destroyed. -COMMAND> -COMMAND> move aut 6 1 - -COMMAND> -COMMAND> move aut 7 7 1 1 - -Ensign Chekov- "Course laid in, Captain." - -Entering Quadrant 7 - 7. -COMMAND> -COMMAND> move aut 8 4 1 1 - -Ensign Chekov- "Course laid in, Captain." - -Entering Quadrant 8 - 4. -COMMAND> -COMMAND> move aut 7 3 5 5 - -Ensign Chekov- "Course laid in, Captain." - -Entering Quadrant 7 - 3. - -162 unit hit on the Enterprise from Klingon at Sector 4 - 7 - -177 unit hit on the Enterprise from Klingon at Sector 4 - 4 - - -Energy left 2731 shields down 100%, torpedoes left 10 -COMMAND> torp 2 -Target sector for torpedo number 1- 4 4 -Target sector for torpedo number 2- 4 7 - -Track for torpedo number 1- 4 - 4 -***Klingon at Sector 4 - 4 destroyed. - -Track for torpedo number 2- 4 - 6 4 - 7 -***Klingon at Sector 4 - 7 destroyed. -COMMAND> -COMMAND> -COMMAND> move aut 4 4 5 5 - -Ensign Chekov- "Course laid in, Captain." - -[ANNOUNCEMENT ARRIVING...] - -***Enterprise caught in long range tractor beam-- -Enterprise is pulled to Quadrant 5 - 4, Sector 2 - 3 -Shields raised. - -Enemy attack reduces shield strength to 79%, torpedoes left 8 -COMMAND> -COMMAND> torp -8 torpedoes left. -Number of torpedoes to fire- 2 -Target sector for torpedo number 1- 6 4 -Target sector for torpedo number 2- 6 4 - -Track for torpedo number 1- 3 - 3 4 - 3 5 - 4 -6 - 4 -***Commander at Sector 6 - 4 damaged-- displaced by blast to Sector 3 - 2 - -Track for torpedo number 2- 3 - 3 4 - 3 5 - 4 -6 - 4 7 - 4 8 - 4 9 - 5 10 - 5 -Torpedo missed. - -34 unit hit on the Enterprise from Klingon at Sector 3 - 2 - - -Energy left 2315 shields up 75%, torpedoes left 6 -COMMAND> quit - -May the Great Bird of the Galaxy roost upon your home planet. diff --git a/test/test3.log b/test/test3.log deleted file mode 100644 index 5c972e8..0000000 --- a/test/test3.log +++ /dev/null @@ -1,39 +0,0 @@ -# seed 1329859817 -# options -# recorded by esr@snark on Tue Feb 21 16:30:17 2012 -# Ends with a torpedo miss -r -s -n - - -move aut 2 8 5 5 - -move aut 4 7 5 5 - -mov aut 6 1 - -move aut 5 6 2 2 -phasers -aut -300 - -move aut 6 1 - -move aut 7 7 1 1 - -move aut 8 4 1 1 - -move aut 7 3 5 5 -torp 2 -4 4 -4 7 - - -move aut 4 4 5 5 - -torp -2 -6 4 -6 4 -quit diff --git a/test/test4.chk b/test/test4.chk index 60d06b8..26f0d73 100644 --- a/test/test4.chk +++ b/test/test4.chk @@ -94,7 +94,12 @@ Entering Quadrant 4 - 7. [ANNOUNCEMENT ARRIVING...] Message from Starfleet Command Stardate 2698.43 - Supernova in Quadrant 6 - 6; caution advised. + Supernova in Quadrant 4 - 2; caution advised. + +[ANNOUNCEMENT ARRIVING...] + +Message from Starfleet Command Stardate 2698.75 + Supernova in Quadrant 4 - 3; caution advised. COMMAND> COMMAND> move 5 8 10 1 (Manual movement assumed.) diff --git a/test/test5.chk b/test/test5.chk deleted file mode 100644 index 3adcbc9..0000000 --- a/test/test5.chk +++ /dev/null @@ -1,158 +0,0 @@ -sst2k: seed set to 1329874855 - - --SUPER- STAR TREK - -Would you like a regular, tournament, or saved game? # SST2K version 2.1 -# recorded by esr@snark on Tue Feb 21 20:40:55 2012 -# Tests docking and movement blockage by starbases -r -Would you like a Short, Medium, or Long game? s -Are you a Novice, Fair, Good, Expert, or Emeritus player? n -Choose your game style (plain, almy, fancy or just press enter): - - -It is stardate 2328. The Federation is being attacked by -a deadly Klingon invasion force. As captain of the United -Starship U.S.S. Enterprise, it is your mission to seek out -and destroy this invasion force of 5 battle cruisers. -You have an initial allotment of 7 stardates to complete -your mission. As you proceed you may be given more time. - -You will have 2 supporting starbases. -Starbase locations- 3 - 1 4 - 2 - -The Enterprise is currently in Quadrant 5 - 5 Sector 8 - 3 - -Good Luck! -COMMAND> -COMMAND> move aut 8 1 - -COMMAND> -COMMAND> mov aut 7 2 5 5 - -Ensign Chekov- "Course laid in, Captain." - -Entering Quadrant 7 - 2. - -[ANNOUNCEMENT ARRIVING...] - -Message from Starfleet Command Stardate 2329.35 - Supernova in Quadrant 6 - 5; caution advised. -COMMAND> -COMMAND> mov aut 6 2 8 8 - -Ensign Chekov- "Course laid in, Captain." - -Enterprise blocked by object at 3 - 6; -Emergency stop required 125 units of energy. -Collision detected -COMMAND> -COMMAND> move aut 6 2 8 8 - -Ensign Chekov- "Course laid in, Captain." - -Entering Quadrant 6 - 2. - -253 unit hit on the Enterprise from Klingon at Sector 9 - 9 - -169 unit hit on the Enterprise from Klingon at Sector 5 - 10 - - -Energy left 3943 shields down 100%, torpedoes left 10 -COMMAND> mov aut 8 1 - - -86 unit hit on the Enterprise from Klingon at Sector 9 - 9 - -87 unit hit on the Enterprise from Klingon at Sector 5 - 10 - - -Energy left 3686 shields down 100%, torpedoes left 10 -COMMAND> torp 2 -Target sector for torpedo number 1- 9 9 -Target sector for torpedo number 2- 5 10 - -Track for torpedo number 1- 8 - 2 8 - 3 8 - 4 -8 - 5 8 - 6 9 - 7 9 - 8 9 - 9 -***Klingon at Sector 9 - 9 destroyed. - -Track for torpedo number 2- 8 - 2 7 - 3 7 - 4 -7 - 5 6 - 6 6 - 7 6 - 8 5 - 9 -5 - 10 -***Klingon at Sector 5 - 10 destroyed. -COMMAND> -COMMAND> move aut 1 1 - - -[ANNOUNCEMENT ARRIVING...] - -Message from Starfleet Command Stardate 2331.31 - Supernova in Quadrant 6 - 3; caution advised. -COMMAND> -COMMAND> move aut 2 2 5 5 - -Ensign Chekov- "Course laid in, Captain." - -Entering Quadrant 2 - 2. -COMMAND> -COMMAND> move aut 4 2 5 5 - -Ensign Chekov- "Course laid in, Captain." - -Entering Quadrant 4 - 2. - -[ANNOUNCEMENT ARRIVING...] - -Message from Starfleet Command Stardate 2333.51 - Supernova in Quadrant 1 - 8; caution advised. -COMMAND> -COMMAND> move aut 7 5 - -COMMAND> -COMMAND> move aut 8 5 - - -Enterprise blocked by object at 8 - 5; -Emergency stop required 125 units of energy. -Collision detected -COMMAND> ? -LEGAL COMMANDS ARE: -SRSCAN STATUS REQUEST LRSCAN -PHASERS TORPEDO PHOTONS MOVE SHIELDS -DOCK DAMAGES CHART IMPULSE REST -WARP SCORE SENSORS ORBIT TRANSPORT -MINE CRYSTALS SHUTTLE PLANETS REPORT -COMPUTER COMMANDS EMEXIT PROBE SAVE -FREEZE ABANDON DESTRUCT DEATHRAY DEBUG -MAYDAY SOS CALL QUIT HELP - -COMMAND> dock -Docked. -COMMAND> -COMMAND> move aut 2 5 4 4 - -Ensign Chekov- "Course laid in, Captain." - -Entering Quadrant 2 - 5. - -[ANNOUNCEMENT ARRIVING...] - -Message from Starfleet Command Stardate 2334.46 - Supernova in Quadrant 3 - 7; caution advised. -COMMAND> -COMMAND> move aut 10 10 - -COMMAND> -COMMAND> move aut 4 6 1 1 - -Ensign Chekov- "Course laid in, Captain." - -First Officer Spock- "Captain, I compute that such - a trip would require approximately 124 percent of our - remaining time. Are you sure this is wise?" no -Please answer with "y" or "n": n -COMMAND> -COMMAND> quit - -May the Great Bird of the Galaxy roost upon your home planet. diff --git a/test/test5.log b/test/test5.log deleted file mode 100644 index 229903b..0000000 --- a/test/test5.log +++ /dev/null @@ -1,44 +0,0 @@ -# seed 1329874855 -# options -# SST2K version 2.1 -# recorded by esr@snark on Tue Feb 21 20:40:55 2012 -# Tests docking and movement blockage by starbases -r -s -n - - -move aut 8 1 - -mov aut 7 2 5 5 - -mov aut 6 2 8 8 - -move aut 6 2 8 8 -mov aut 8 1 -torp 2 -9 9 -5 10 - -move aut 1 1 - -move aut 2 2 5 5 - -move aut 4 2 5 5 - -move aut 7 5 - -move aut 8 5 -? -dock - -move aut 2 5 4 4 - -move aut 10 10 - -move aut 4 6 1 1 -no -n - -quit -n -- 2.31.1