X-Git-Url: https://jxself.org/git/?p=super-star-trek.git;a=blobdiff_plain;f=sst.py;h=a598e43f709d5e2d254263ee2821f7357f37b2a3;hp=5b7dcdd08b3d9b515b43b764129208585e647f6d;hb=11091a194a879833f28764e6f7537e7dabe431ae;hpb=3a68f1d0e66f97562cdc0ace6adb458e0bc8d990 diff --git a/sst.py b/sst.py index 5b7dcdd..a598e43 100755 --- a/sst.py +++ b/sst.py @@ -45,11 +45,17 @@ import random class randomizer: @staticmethod def withprob(p): - return random.random() < p + b = random.random() < p + if logfp: + logfp.write("#withprob(%.2f) -> %s\n" % (p, b)) + return b @staticmethod def randrange(*args): - return random.randrange(*args) + s = random.randrange(*args) + if logfp: + logfp.write("#randrange%s -> %s\n" % (args, s)) + return s @staticmethod def real(*args): @@ -58,10 +64,14 @@ class randomizer: v *= args[0] # from [0, args[0]) elif len(args) == 2: v = args[0] + v*(args[1]-args[0]) # from [args[0], args[1]) + if logfp: + logfp.write("#real%s -> %f\n" % (args, v)) return v @staticmethod def seed(n): + if logfp: + logfp.write("#seed(%d)\n" % n) random.seed(n) GALSIZE = 8 # Galaxy size in quadrants @@ -328,7 +338,7 @@ FSCMOVE = 6 # Supercommander moves (might attack base) FSCDBAS = 7 # Supercommander destroys base FDSPROB = 8 # Move deep space probe FDISTR = 9 # Emit distress call from an inhabited world -FENSLV = 10 # Inhabited word is enslaved */ +FENSLV = 10 # Inhabited word is enslaved FREPRO = 11 # Klingons build a ship in an enslaved system NEVENTS = 12 @@ -508,8 +518,8 @@ def welcoming(iq): def tryexit(enemy, look, irun): "A bad guy attempts to bug out." iq = Coord() - iq.i = game.quadrant.i+(look.i+(QUADSIZE-1))/QUADSIZE - 1 - iq.j = game.quadrant.j+(look.j+(QUADSIZE-1))/QUADSIZE - 1 + iq.i = game.quadrant.i+(look.i+(QUADSIZE-1))//QUADSIZE - 1 + iq.j = game.quadrant.j+(look.j+(QUADSIZE-1))//QUADSIZE - 1 if not welcoming(iq): return False if enemy.type == 'R': @@ -594,7 +604,7 @@ def movebaddy(enemy): irun = False # This should probably be just (game.quadrant in game.state.kcmdr) + (game.state.kscmdr==game.quadrant) if game.skill >= SKILL_EXPERT: - nbaddys = (((game.quadrant in game.state.kcmdr)*2 + (game.state.kscmdr==game.quadrant)*2+game.klhere*1.23+game.irhere*1.5)/2.0) + nbaddys = int(((game.quadrant in game.state.kcmdr)*2 + (game.state.kscmdr==game.quadrant)*2+game.klhere*1.23+game.irhere*1.5)/2.0) else: nbaddys = (game.quadrant in game.state.kcmdr) + (game.state.kscmdr==game.quadrant) old_dist = enemy.kdist @@ -1201,7 +1211,7 @@ def collision(rammed, enemy): # In the pre-SST2K version, all devices got equiprobably damaged, # which was silly. Instead, pick up to half the devices at # random according to our weighting table, - ncrits = rnd.randrange(NDEVICES/2) + ncrits = rnd.randrange(NDEVICES//2) while ncrits > 0: ncrits -= 1 dev = randdevice() @@ -2132,7 +2142,7 @@ def capture(): game.ididit = False # Nothing if we fail game.optime = 0.0 - # Make sure there is room in the brig */ + # Make sure there is room in the brig if game.brigfree == 0: prout(_("Security reports the brig is already full.")) return @@ -2150,7 +2160,7 @@ def capture(): prout(_("Uhura- \"Getting no response, sir.\"")) return - # if there is more than one Klingon, find out which one */ + # if there is more than one Klingon, find out which one # Cruddy, just takes one at random. Should ask the captain. # Nah, just select the weakest one since it is most likely to # surrender (Tom Almy mod) @@ -2166,12 +2176,12 @@ def capture(): x = game.energy / (weakest.power * len(klingons)) #prout(_("Stats: energy = %s, kpower = %s, klingons = %s") # % (game.energy, weakest.power, len(klingons))) - x *= 2.5 # would originally have been equivalent of 1.4, - # but we want command to work more often, more humanely */ + x *= 2.5 # would originally have been equivalent of 1.4, + # but we want command to work more often, more humanely #prout(_("Prob = %.4f" % x)) # x = 100; // For testing, of course! if x < rnd.real(100): - # guess what, he surrendered!!! */ + # guess what, he surrendered!!! prout(_("Klingon captain at %s surrenders.") % weakest.location) i = rnd.real(200) if i > 0: @@ -2186,7 +2196,7 @@ def capture(): finish(FWON) return - # big surprise, he refuses to surrender */ + # big surprise, he refuses to surrender prout(_("Fat chance, captain!")) # Code from events.c begins here. @@ -6692,7 +6702,6 @@ if __name__ == '__main__': line = replayfp.readline().strip() (leader, __, seed) = line.split() seed = eval(seed) - sys.stderr.write("sst2k: seed set to %s\n" % seed) line = replayfp.readline().strip() arguments += line.split()[2:] replay = True