self.supernova = False
self.charted = False
self.status = "secure" # Could be "secure", "distressed", "enslaved"
+ def __str__(self):
+ return "<Quadrant: %(klingons)d>" % self.__dict__
+ __repr__ = __str__
class Page:
def __init__(self):
class Snapshot:
def __init__(self):
- self.snap = False # snapshot taken
+ self.snap = False # snapshot taken
self.crew = 0 # crew complement
- self.remkl = 0 # remaining klingons
- self.nscrem = 0 # remaining super commanders
+ self.nscrem = 0 # remaining super commanders
self.starkl = 0 # destroyed stars
self.basekl = 0 # destroyed bases
self.nromrem = 0 # Romulans remaining
self.galaxy = fill2d(GALSIZE, lambda i_unused, j_unused: Quadrant())
# the starchart
self.chart = fill2d(GALSIZE, lambda i_unused, j_unused: Page())
+ def traverse(self):
+ for i in range(GALSIZE):
+ for j in range(GALSIZE):
+ yield (i, j, self.galaxy[i][j])
class Event:
def __init__(self):
self.iscloaked = False # Cloaking device on?
self.ncviol = 0 # Algreon treaty violations
self.isviolreported = False # We have been warned
+ def remkl(self):
+ return sum([q.klingons for (_i, _j, q) in list(self.state.traverse())])
def recompute(self):
# Stas thinks this should be (C expression):
- # game.state.remkl + len(game.state.kcmdr) > 0 ?
- # game.state.remres/(game.state.remkl + 4*len(game.state.kcmdr)) : 99
+ # game.remkl() + len(game.state.kcmdr) > 0 ?
+ # game.state.remres/(game.remkl() + 4*len(game.state.kcmdr)) : 99
# He says the existing expression is prone to divide-by-zero errors
# after killing the last klingon when score is shown -- perhaps also
# if the only remaining klingon is SCOM.
- self.state.remtime = self.state.remres/(self.state.remkl + 4*len(self.state.kcmdr))
+ self.state.remtime = self.state.remres/(self.remkl() + 4*len(self.state.kcmdr))
def unwon(self):
"Are there Klingons remaining?"
- return self.state.remkl + len(self.state.kcmdr) + self.state.nscrem
+ return self.remkl() + len(self.state.kcmdr) + self.state.nscrem
FWON = 0
FDEPLETE = 1
if game.idebug:
prout("== SUPERCOMMANDER")
# Decide on being active or passive
- avoid = ((game.incom - len(game.state.kcmdr) + game.inkling - game.state.remkl)/(game.state.date+0.01-game.indate) < 0.1*game.skill*(game.skill+1.0) or \
+ avoid = ((game.incom - len(game.state.kcmdr) + game.inkling - game.remkl())/(game.state.date+0.01-game.indate) < 0.1*game.skill*(game.skill+1.0) or \
(game.state.date-game.indate) < 3.0)
if not game.iscate and avoid:
# compute move away from Enterprise
if is_scheduled(FCDBAS) and game.battle == game.quadrant:
unschedule(FCDBAS)
elif etype == 'K':
- game.state.remkl -= 1
+ pass
elif etype == 'S':
game.state.nscrem -= 1
game.state.kscmdr.invalidate()
return
game.state.date = datemin
# Decrement Federation resources and recompute remaining time
- game.state.remres -= (game.state.remkl+4*len(game.state.kcmdr))*xtime
+ game.state.remres -= (game.remkl()+4*len(game.state.kcmdr))*xtime
game.recompute()
if game.state.remtime <= 0:
finish(FDEPLETE)
if q.klingons <= 0:
q.status = "secure"
continue
- if game.state.remkl >= MAXKLGAME:
+ if game.remkl() >= MAXKLGAME:
continue # full right now
# reproduce one Klingon
w = ev.quadrant
except JumpOut:
w = m
# deliver the child
- game.state.remkl += 1
q.klingons += 1
if game.quadrant == w:
game.klhere += 1
stars()
game.alldone = True
# destroy any Klingons in supernovaed quadrant
- kldead = game.state.galaxy[nq.i][nq.j].klingons
game.state.galaxy[nq.i][nq.j].klingons = 0
if nq == game.state.kscmdr:
# did in the Supercommander!
survivors = filter(lambda w: w != nq, game.state.kcmdr)
comkills = len(game.state.kcmdr) - len(survivors)
game.state.kcmdr = survivors
- kldead -= comkills
if not game.state.kcmdr:
unschedule(FTBEAM)
- game.state.remkl -= kldead
# destroy Romulans and planets in supernovaed quadrant
nrmdead = game.state.galaxy[nq.i][nq.j].romulans
game.state.galaxy[nq.i][nq.j].romulans = 0
game.alive = False
if game.unwon() != 0:
goodies = game.state.remres/game.inresor
- baddies = (game.state.remkl + 2.0*len(game.state.kcmdr))/(game.inkling+2.0*game.incom)
+ baddies = (game.remkl() + 2.0*len(game.state.kcmdr))/(game.inkling+2.0*game.incom)
if goodies/baddies >= randreal(1.0, 1.5):
prout(_("As a result of your actions, a treaty with the Klingon"))
prout(_("Empire has been signed. The terms of the treaty are"))
klship = 1
else:
klship = 2
- game.score = 10*(game.inkling - game.state.remkl) \
+ game.score = 10*(game.inkling - game.remkl()) \
+ 50*(game.incom - len(game.state.kcmdr)) \
+ ithperd + iwon \
+ 20*(game.inrom - game.state.nromrem) \
if game.state.nromrem and game.gamewon:
prout(_("%6d Romulans captured %5d") %
(game.state.nromrem, game.state.nromrem))
- if game.inkling - game.state.remkl:
+ if game.inkling - game.remkl():
prout(_("%6d ordinary Klingons destroyed %5d") %
- (game.inkling - game.state.remkl, 10*(game.inkling - game.state.remkl)))
+ (game.inkling - game.remkl(), 10*(game.inkling - game.remkl())))
if game.incom - len(game.state.kcmdr):
prout(_("%6d Klingon commanders destroyed %5d") %
(game.incom - len(game.state.kcmdr), 50*(game.incom - len(game.state.kcmdr))))
(game.inkling + game.incom + game.inscom)))
if game.incom - len(game.state.kcmdr):
prout(_(", including %d Commander%s.") % (game.incom - len(game.state.kcmdr), (_("s"), "")[(game.incom - len(game.state.kcmdr))==1]))
- elif game.inkling - game.state.remkl + (game.inscom - game.state.nscrem) > 0:
+ elif game.inkling - game.remkl() + (game.inscom - game.state.nscrem) > 0:
prout(_(", but no Commanders."))
else:
prout(".")
game.state.nscrem = game.inscom = (game.skill > SKILL_FAIR)
game.state.remtime = 7.0 * game.length
game.intime = game.state.remtime
- game.state.remkl = game.inkling = int(2.0*game.intime*((game.skill+1 - 2*randreal())*game.skill*0.1+.15))
+ game.inkling = int(2.0*game.intime*((game.skill+1 - 2*randreal())*game.skill*0.1+.15))
game.incom = min(MINCMDR, int(game.skill + 0.0625*game.inkling*randreal()))
game.state.remres = (game.inkling+4*game.incom)*game.intime
game.inresor = game.state.remres
e = game.enemies[0]
game.quad[e.location.i][e.location.j] = 'S'
e.power = randreal(1175.0, 1575.0) + 125.0*game.skill
- game.iscate = (game.state.remkl > 1)
+ game.iscate = (game.remkl() > 1)
# Put in Romulans if needed
for _i in range(q.romulans):
Enemy('R', loc=dropin(), power=randreal(400.0,850.0)+50.0*game.skill)
--- /dev/null
+sst2k: seed set to 1488349223
+
+
+-SUPER- STAR TREK
+
+
+
+It is stardate 2772. 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- 3 - 3 4 - 1 5 - 6 1 - 5
+
+The Enterprise is currently in Quadrant 6 - 5 Sector 2 - 5
+
+Good Luck!
+COMMAND> # SST2K version 2.1
+# Tests novice game win
+# recorded by esr@snark on Wed Mar 1 01:20:23 2017
+
+COMMAND> m a 3 5 10 10
+
+Ensign Chekov- "Course laid in, Captain."
+
+Entering Quadrant 3 - 5.
+COMMAND>
+COMMAND> m a 1 5
+
+COMMAND> sh up
+Shields raised.
+COMMAND> m a 2 5 10 5
+
+Ensign Chekov- "Course laid in, Captain."
+
+Entering Quadrant 2 - 5.
+
+Enemy attack reduces shield strength to 92%, torpedoes left 10
+COMMAND> phasers
+
+Weapons Officer Sulu- "High-speed shield control enabled, sir."
+Manual or automatic?
+Manual or automatic? a
+Phasers locked on target. Energy available: 4314.29
+240 units required. Units to fire= 240
+
+Shields lowered.
+
+200 unit hit on Klingon at Sector 9 - 2
+***Klingon at Sector 9 - 2 destroyed.
+
+Shields raised.
+COMMAND>
+COMMAND> m a 10 1
+
+COMMAND>
+COMMAND> m a 2 2 10 10
+
+Ensign Chekov- "Course laid in, Captain."
+
+Entering Quadrant 2 - 2.
+COMMAND>
+COMMAND> sh d
+Shields lowered.
+COMMAND>
+COMMAND> m a 5 2 1 1
+
+Ensign Chekov- "Course laid in, Captain."
+
+Entering Quadrant 5 - 2.
+
+[ANNOUNCEMENT ARRIVING...]
+
+Message from Starfleet Command Stardate 2776.05
+ Supernova in Quadrant 5 - 7; caution advised.
+COMMAND>
+COMMAND> sh up
+Shields raised.
+COMMAND>
+COMMAND> m a 5 1 1 10
+
+Ensign Chekov- "Course laid in, Captain."
+
+Entering Quadrant 5 - 1.
+
+17 unit hit on the Enterprise from Klingon at Sector 2 - 4
+
+
+Energy left 3096 shields up 83%, torpedoes left 10
+COMMAND> phasers
+
+Weapons Officer Sulu- "High-speed shield control enabled, sir."
+Manual or automatic? a
+Phasers locked on target. Energy available: 2871.45
+597 units required. Units to fire= 597
+
+Shields lowered.
+
+197 unit hit on Klingon at Sector 1 - 5
+***Klingon at Sector 1 - 5 destroyed.
+65 unit hit on Klingon at Sector 2 - 4
+244 expended on empty space.
+
+Shields raised.
+
+12 unit hit on the Enterprise from Klingon at Sector 2 - 4
+
+
+Energy left 2261 shields up 81%, torpedoes left 10
+COMMAND> capture
+Klingon captain at 2 - 4 surrenders.
+92 Klingons commit suicide rather than be taken captive.
+107 captives taken
+***Klingon at Sector 1 - 10 destroyed.
+COMMAND>
+COMMAND> m a 8 1 1 1
+
+Ensign Chekov- "Course laid in, Captain."
+
+Entering Quadrant 8 - 1.
+COMMAND>
+COMMAND> m a 1 10
+
+COMMAND> sh up
+Shields already up.
+COMMAND> m m .1
+
+Helmsman Sulu- "Aye, Sir."
+
+Entering Quadrant 8 - 2.
+COMMAND>
+COMMAND> m a 7 2 10 1
+
+Ensign Chekov- "Course laid in, Captain."
+
+Entering Quadrant 7 - 2.
+
+83 unit hit on the Enterprise from Klingon at Sector 6 - 5
+
+
+Energy left 1144 shields up 69%, torpedoes left 10
+COMMAND> torp 1 6 5
+
+Torpedo track- 9 - 2 8 - 3 7 - 4
+6 - 5
+***Commander at Sector 6 - 5 damaged-- displaced by blast to Sector 10 - 2
+
+29 unit hit on the Enterprise from Klingon at Sector 10 - 2
+
+
+Energy left 1090 shields up 67%, torpedoes left 9
+COMMAND> phasers
+
+Weapons Officer Sulu- "High-speed shield control enabled, sir."
+Manual or automatic?
+Manual or automatic? a
+Phasers locked on target. Energy available: 890.16
+52 units required. Units to fire= 52
+
+Shields lowered.
+
+45 unit hit on Commander at Sector 10 - 2
+***Commander at Sector 10 - 2 destroyed.
+
+
+
+It is stardate 2778.0.
+
+You have smashed the Klingon invasion fleet and saved
+the Federation.
+The 107 captured Klingons are transferred to Star Fleet Command.
+
+In fact, you have done so well that Starfleet Command
+promotes you one step in rank from "Novice" to "Fair".
+
+LIVE LONG AND PROSPER.
+
+
+Your score --
+ 3 ordinary Klingons destroyed 30
+ 1 Klingon commanders destroyed 50
+107 Klingons captured 323
+ 0.79 Klingons per stardate 396
+[PRESS ENTER TO CONTINUE]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Bonus for winning Novice game 100
+
+TOTAL SCORE 900
+
+May the Great Bird of the Galaxy roost upon your home planet.
--- /dev/null
+# seed 1488349223
+# options regular short novice fancy
+# SST2K version 2.1
+# Tests novice game win
+# recorded by esr@snark on Wed Mar 1 01:20:23 2017
+
+m a 3 5 10 10
+
+m a 1 5
+sh up
+m a 2 5 10 5
+phasers
+
+a
+240
+
+m a 10 1
+
+m a 2 2 10 10
+
+sh d
+
+m a 5 2 1 1
+
+sh up
+
+m a 5 1 1 10
+phasers
+a
+597
+capture
+
+m a 8 1 1 1
+
+m a 1 10
+sh up
+m m .1
+
+m a 7 2 10 1
+torp 1 6 5
+phasers
+
+a
+52
+n
Weapons Officer Sulu- "High-speed shield control enabled, sir."
Manual or automatic? auto
Phasers locked on target. Energy available: 4800.00
-3064 units required. Units to fire= 4800
+1983 units required. Units to fire= 4800
Shields lowered.
-219 unit hit on Klingon at Sector 4 - 7
-***Klingon at Sector 4 - 7 destroyed.
-276 unit hit on Klingon at Sector 6 - 7
-***Klingon at Sector 6 - 7 destroyed.
-753 unit hit on Commander at Sector 6 - 3
-***Commander at Sector 6 - 3 destroyed.
-261 unit hit on Klingon at Sector 8 - 6
-***Klingon at Sector 8 - 6 destroyed.
-280 unit hit on Klingon at Sector 7 - 2
-***Klingon at Sector 7 - 2 destroyed.
-255 unit hit on Klingon at Sector 9 - 5
-***Klingon at Sector 9 - 5 destroyed.
-2175 expended on empty space.
+241 unit hit on Klingon at Sector 4 - 4
+***Klingon at Sector 4 - 4 destroyed.
+278 unit hit on Klingon at Sector 6 - 3
+***Klingon at Sector 6 - 3 destroyed.
+239 unit hit on Klingon at Sector 1 - 7
+***Klingon at Sector 1 - 7 destroyed.
+375 unit hit on Klingon at Sector 5 - 9
+***Klingon at Sector 5 - 9 destroyed.
+342 unit hit on Klingon at Sector 1 - 2
+***Klingon at Sector 1 - 2 destroyed.
+248 unit hit on Klingon at Sector 7 - 8
+***Klingon at Sector 7 - 8 destroyed.
+2881 expended on empty space.
Shields raised.
Weapons officer Sulu- "Phasers overheated, sir."
-
-
-
-
-It is stardate 2149.8.
-
-[CONTINUE?]
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-The Enterprise has been destroyed in battle.
-
-Dulce et decorum est pro patria mori.
-As a result of your actions, a treaty with the Klingon
-Empire has been signed. The terms of the treaty are
-highly unfavorable to the Federation.
-
-
-Your score --
- 5 ordinary Klingons destroyed 50
- 1 Klingon commanders destroyed 50
- 0.00 Klingons per stardate 0
- 1 ship(s) lost or destroyed -100
-Penalty for getting yourself killed -200
-
-TOTAL SCORE -200
+COMMAND> quit
May the Great Bird of the Galaxy roost upon your home planet.
Enterprise is pulled to Quadrant 2 - 8, Sector 4 - 8
Shields raised.
-33 unit hit on the Enterprise from Klingon at Sector 7 - 4
+29 unit hit on the Enterprise from Klingon at Sector 7 - 1
-Energy left 4764 shields up 78%, torpedoes left 10
+Energy left 4768 shields up 81%, torpedoes left 10
COMMAND> torp 2
Target sector for torpedo number 1- 7 4
Target sector for torpedo number 2- 7 5
-Track for torpedo number 1- 5 - 7 6 - 6 6 - 5
+Track for torpedo number 1- 5 - 7 5 - 6 6 - 5
7 - 4
***Klingon at Sector 7 - 4 destroyed.
Track for torpedo number 2- 5 - 7 6 - 6 7 - 5
-***Commander at Sector 7 - 5 damaged-- displaced by blast to Sector 5 - 8
+***Klingon at Sector 7 - 5 destroyed.
-66 unit hit on the Enterprise from Klingon at Sector 5 - 8
+38 unit hit on the Enterprise from Klingon at Sector 7 - 1
-Energy left 4697 shields up 70%, torpedoes left 8
+Energy left 4730 shields up 76%, torpedoes left 8
COMMAND> phasers
Weapons Officer Sulu- "High-speed shield control enabled, sir."
Manual or automatic? a
-Phasers locked on target. Energy available: 4497.40
-159 units required. Units to fire= 300
+Phasers locked on target. Energy available: 4530.26
+724 units required. Units to fire= 300
Shields lowered.
-155 unit hit on Commander at Sector 5 - 8
-***Commander at Sector 5 - 8 destroyed.
+266 unit hit on Commander at Sector 7 - 1
+***Mr. Spock- "Captain, the vessel at Sector 7 - 1
+ has just lost its firepower."
Shields raised.
+
+Enemy attack reduces shield strength to 76%, torpedoes left 8
COMMAND>
COMMAND> m 7 7 5 5
(Manual movement assumed.)
[ANNOUNCEMENT ARRIVING...]
Message from Starfleet Command Stardate 2698.43
- Supernova in Quadrant 3 - 8; caution advised.
-
-[ANNOUNCEMENT ARRIVING...]
-
-Message from Starfleet Command Stardate 2699.95
- Supernova in Quadrant 4 - 5; caution advised.
+ Supernova in Quadrant 8 - 5; caution advised.
COMMAND>
COMMAND> move 5 8 10 1
(Manual movement assumed.)
Ensign Chekov- "Course laid in, Captain."
-Entering Quadrant 2 - 6.
-COMMAND> y
-LEGAL COMMANDS ARE:
-SRSCAN STATUS REQUEST LRSCAN
-PHASERS TORPEDO PHOTONS MOVE SHIELDS
-DOCK DAMAGES CHART IMPULSE REST
-WARP SENSORS ORBIT TRANSPORT MINE
-CRYSTALS SHUTTLE PLANETS REPORT COMPUTER
-COMMANDS EMEXIT PROBE SAVE FREEZE
-ABANDON DESTRUCT DEATHRAY CAPTURE CLOAK
-DEBUG MAYDAY SOS CALL QUIT
-HELP SCORE CURSES
-COMMAND>
-COMMAND> move aut 5 8 5 5
-
-Ensign Chekov- "Course laid in, Captain."
-
-First Officer Spock- "Captain, I compute that such
- a trip would require approximately 135 percent of our
- remaining time. Are you sure this is wise?" n
-COMMAND> move aut 9 9
-
-COMMAND> y
-LEGAL COMMANDS ARE:
-SRSCAN STATUS REQUEST LRSCAN
-PHASERS TORPEDO PHOTONS MOVE SHIELDS
-DOCK DAMAGES CHART IMPULSE REST
-WARP SENSORS ORBIT TRANSPORT MINE
-CRYSTALS SHUTTLE PLANETS REPORT COMPUTER
-COMMANDS EMEXIT PROBE SAVE FREEZE
-ABANDON DESTRUCT DEATHRAY CAPTURE CLOAK
-DEBUG MAYDAY SOS CALL QUIT
-HELP SCORE CURSES
-COMMAND> n
-LEGAL COMMANDS ARE:
-SRSCAN STATUS REQUEST LRSCAN
-PHASERS TORPEDO PHOTONS MOVE SHIELDS
-DOCK DAMAGES CHART IMPULSE REST
-WARP SENSORS ORBIT TRANSPORT MINE
-CRYSTALS SHUTTLE PLANETS REPORT COMPUTER
-COMMANDS EMEXIT PROBE SAVE FREEZE
-ABANDON DESTRUCT DEATHRAY CAPTURE CLOAK
-DEBUG MAYDAY SOS CALL QUIT
-HELP SCORE CURSES
-COMMAND> move aut 5 8 5 5
-
-Ensign Chekov- "Course laid in, Captain."
-
First Officer Spock- "Captain, I compute that such
- a trip would require approximately 145 percent of our
+ a trip would require approximately 221 percent of our
remaining time. Are you sure this is wise?" y
-Entering Quadrant 5 - 8.
+Entering Quadrant 2 - 6.
-It is stardate 3423.8.
+It is stardate 3422.7.
Your time has run out and the Federation has been
conquered. Your starship is now Klingon property,
Your score --
- 2 ordinary Klingons destroyed 20
- 0.20 Klingons per stardate 101
+ 1 ordinary Klingons destroyed 10
+ 0.11 Klingons per stardate 57
-TOTAL SCORE 121
+TOTAL SCORE 67
May the Great Bird of the Galaxy roost upon your home planet.
Your score --
- 0.00 Klingons per stardate 0
+ -1 ordinary Klingons destroyed -10
+ -0.44 Klingons per stardate -217
1 ship(s) lost or destroyed -100
Penalty for getting yourself killed -200
-TOTAL SCORE -300
+TOTAL SCORE -528
Collision detected
May the Great Bird of the Galaxy roost upon your home planet.
Your starship has been destroyed by a nova.
That was a great shot.
-As a result of your actions, a treaty with the Klingon
-Empire has been signed. The terms of the treaty are
-favorable to the Federation.
-
-Congratulations!
+The Federation will be destroyed.
Your score --
- 4 ordinary Klingons destroyed 40
- 0.76 Klingons per stardate 379
+ 3 ordinary Klingons destroyed 30
+ 0.57 Klingons per stardate 284
2 stars destroyed by your action -10
-[PRESS ENTER TO CONTINUE]
+ 8 casualties incurred -8
+ 1 ship(s) lost or destroyed -100
+Penalty for getting yourself killed -200
+[PRESS ENTER TO CONTINUE]
- 8 casualties incurred -8
- 1 ship(s) lost or destroyed -100
-Penalty for getting yourself killed -200
-TOTAL SCORE 101
+TOTAL SCORE -3
May the Great Bird of the Galaxy roost upon your home planet.