rance/automate.py

78 lines
3.1 KiB
Python
Raw Normal View History

import random as ra
import json as j
# Package imports
# Does Python have real package support?
from . import unit
from . import board
from os.path import dirname,join
with open(join(dirname(__file__),'data.json')) as d:
data=j.load(d)
board.actinfo=data['actions']
classlist=data['classes']
def randomunit(cls,name=None):
# TODO: Rewrite this to include a power-point system
if cls=='musket': return unit.RosterUnit(cls,*[wra(10,3,1) for _ in range(4)],wra(300,3,100),wra(3,1,1),name=name)
return unit.RosterUnit(cls,*[wra(10,3,1) for _ in range(4)],wra(600,3,300),wra(7,3,2),name=name)
def wra(top,dice,bot=0):
return bot+int(sum([ra.random()*(top-bot) for _ in range(dice)])/dice)
mcls=[k for k,v in classlist.items() if 'tmelee' in v['attrs']]
rcls=[k for k,v in classlist.items() if 'tranged' in v['attrs']]
def blindplayer(unitnum):
cls=yield {'melee':mcls,'ranged':rcls,'melees':'\n'.join(mcls),'rangeds':'\n'.join(rcls)}
if not (len(cls)==unitnum):
raise Exception("Picked the wrong unit count")
units=[randomunit(cl) for cl in cls]
# Ensure this gives back an integer
reroll=yield {'units':[u.static() for u in units],'strunits':'\n'.join([u.static() for u in units])}
new=randomunit(units[reroll].cls)
# A boolean
confirm=yield {'old':units[reroll].static(),'new':new.static()}
if confirm: units[reroll]=new
# List of integers (between 1 and 6)
names=yield {'strunits':'\n'.join([u.static() for u in units])}
for k,v in names.items(): units[k].name=v
positions=yield {'units':[u.static() for u in units],'strunits':'\n'.join([u.static() for u in units])}
units={positions[i]:units[i] for i in range(unitnum)}
yield {k:unit.BattleUnit.tobattle(u) for k,u in units.items()}
return
def blindstart(unitnum,p1,p2):
# Ensure this gives back a tuple of lists
# Haha yeah maybe listing the available classes is a good idea
# Haha yeah, maybe splitting them by range is a good idea
cls=yield mcls,rcls
if not (len(cls[0])==len(cls[1])==unitnum):
raise Exception("Someone picked the wrong unit count")
p1u=[randomunit(cl) for cl in cls[0]]
p2u=[randomunit(cl) for cl in cls[1]]
# Ensure this gives back a tuple of integers
reroll=yield [u.static() for u in p1u],[u.static() for u in p2u]
new=randomunit(p1u[reroll[0]].cls),randomunit(p2u[reroll[1]].cls)
# Tuple of booleans
confirm=yield tuple(u.static() for u in new)
if confirm[0]: p1u[reroll[0]]=new[0]
if confirm[1]: p2u[reroll[1]]=new[1]
# Tuple of lists of integers (between 1 and 6)
names=yield True
for k,v in names[0].items(): p1u[k].name=v
for k,v in names[1].items(): p2u[k].name=v
positions=yield [u.static() for u in p1u],[u.static() for u in p2u]
p1u={positions[0][i]:p1u[i] for i in range(unitnum)}
p2u={positions[1][i]:p2u[i] for i in range(unitnum)}
keys=yield True
p1u={k:unit.BattleUnit.tobattle(u) for k,u in p1u.items()}
p2u={k:unit.BattleUnit.tobattle(u) for k,u in p2u.items()}
return board.Board(p1,p2,keys[0],keys[1],p1u,p2u)
# Utility function for looking at damage scaling stuff. Not part of the game itself.
# I don't really remember how it works.
def bump(a):
for i in range(1,10):
for j in range(1,10):
print(f'{(a**(i-j)+1):.4f}',end=' ')
print()