but wait i'm not done
i started coding map war 3 again today, except i started brand new with a new structure. i just have to code in the turn processing and the game rules/settings, then slap on some shiny graphics and we're done!
import networkx as nx
import cPickle
import deepcopy
class Zone:
def __init__(self, id, own = None):
self.id = id
self.econ = 0
self.indus = 0
self.fort = 0
self.own = own
self.dist = None #needs to compute
def upg(typ, amount): #bad form?
if typ == 'econ':
self.econ += amount
elif typ == 'indus':
self.indus += amount
elif typ == 'fort':
self.fort += amount
class Nation:
def __init__(self, id, capital, techs):
self.capital = capital
self.id = id
self.mon = 0
self.econ = 0
self.indus = 0
self.mil = 0
self.zones = [self.capital]
self.techs = techs
self.trades = []
def addzone(self, zone):
self.zone.append(zone)
def compstats(self):
self.econ = sum((zon.econ for zon in self.zones))
self.indus = sum((zon.indus for zon in self.zones))
self.mon += self.econ
def convmil(self, amount):
self.mon -= amount
self.mil += amount
def research(self, tree, amount):
self.techs[tree].rsearch(amount)
def addtrade(self, onat):
self.trades.append(onat)
class Tech:
def __init__(self, dflags, cval = 0):
self.cval = cval
self.dflags = dflags
def rsearch(self, amount):
self.cval += amount
def checkflag(self, typ):
return self.dflags[typ](self.cval)
class World:
def __init__(self, zones, edges, tech):
self.zones = zones
self.edges = edges
self.techs = techs
self.nations = []
self.mgraph()
def mgraph(self):
self.graph = nx.Graph()
for node in self.zones:
self.graph.add_node(node)
for edge in self.edges:
self.graph.add_edge(*edge)
class Turn:
def __init__(self, acts): #zacts, wacts, tacts, racts, nacts, oacts
self.acts = acts
def addacts(self, typ, act):
self.acts[typ].append(act)
def removeacts(self, typ, act):
del self.acts[typ][self.acts[typ].index(act)]
def rotlist(lst):
return [lst.pop()]+lst
class Game:
def __init__(self, world, gamerules, tord):
self.history = [world]
self.world = world
self.gr = gamerules
self.tord = reversed(tord)
self.estate = False
def confirm(self):
self.history.append(copy.deepcopy(self.world))
def lastconfirmed(self):
self.world = copy.deepcopy(self.history[-1])
#
def pzacts(self, zacts):
pass
def pwacts(self, wacts):
pass
def practs(self, racts):
pass
def pnacts(self, nacts):
pass
def poacts(self, oacts):
pass
def pturn(self, turnobj):
self.lastconfirmed()
self.turn = self.tord[0]
zacts, wacts, racts, nacts, oacts = turnobj.acts
self.pzacts(zacts) #zone acts
self.pwacts(wacts) #war acts
self.practs(racts) #tech acts
self.pnacts(nacts) #nation acts
self.poacts(oacts) #other acts
if not(self.estate):
self.tord = rotlist(self.tord)
self.confirm()
class Gamerules: #is a class overkill
def __init__(self):
self.settings = {
}
self.rules = {
}
pass
def tofile(instance, file):
with open(file, 'w') as f:
cPickle.dump(instance, f)