Beispiel #1
0
    def __init__(self, grid=Grid(), defender=None, attacker=None):
        self.grid = grid
        self.defender = defender
        self.attacker = attacker
        #player/battlefield logic for testing
        if self.defender == None:
            self.defender = Player('Defender', squads=[rand_squad()])
        if self.attacker == None:
            self.attacker = Player('Attacker', squads=[rand_squad()])
        self.battlefield = Battlefield(grid, self.defender.squads[0],
                                       self.attacker.squads[0])

        self.state = State()
        self.players = (self.defender, self.attacker)
        self.map = self.unit_map()
        self.winner = None
        self.units = self.map_unit()
        self.log = Log(self.players, self.units, self.battlefield.grid)
        self.log['owners'] = self.log.get_owners()
        self.state['old_defsquad_hp'] = self.battlefield.defsquad.hp()
        self.whose_turn = self.defender
Beispiel #2
0
from binary_tactics.zodb_hex_battle import Game, Action
from stores.yaml_store import load
from binary_tactics.hex_battlefield import Battlefield
from binary_tactics.player import Player
from binary_tactics.grid import Loc


def hp():
    for s in btl.squads:
        print s.name
        for u in s:
            print "     %s\n    %s" % (u.name, u.hp)
        print ""


p1 = Player(name='p1', squads=[load('yaml/ice_maxes.yaml')])
p2 = Player(name='p2', squads=[load('yaml/fire_maxes.yaml')])

game = Game(defender=p1, attacker=p2)

btl = game.battlefield

for s in range(2):
    for x in range(4):
        btl.place_object(btl.squads[s][x], Loc(x, s))

game.log['init_locs'] = game.log.init_locs()


def show_squad(squad):
    for u in squad:
Beispiel #3
0
def convert_dict(dict):
    """takes a dict and returns composite objects."""
    key, value = dict.items()[0]
    if key == 'tile':
        #this obviously dramatically slows down the instanciation of a
        #previously instanciated grid, but when would this be done in real-time?
        if value['contents'] == None:
            return Tile(**eval("".join(str(value).replace("u'", "'"))))
        else:
            contents = convert_dict(value['contents'])
            del value['contents']
            tile = Tile(**eval("".join(str(value).replace("u'", "'"))))
            tile.contents = contents
            return tile
    elif key == 'grid':
        #It's dat eval hammer, boy!!! WOOO!!!
        comp = eval("".join(str(value['comp']).replace("u'", "'")))
        tiles = {}
        x = value['x']
        y = value['y']
        for i in xrange(x):
            new_x = {}
            for j in xrange(y):
                new_x.update({j: convert_dict(value['tiles'][str(i)][str(j)])})
            tiles.update({i: new_x})
        return Grid(comp, x, y, tiles)

    elif key == 'squad':
        squad = Squad(name=value['name'])
        data = value['data']
        for unit in data:
            squad.append(convert_dict(unit))
        return squad

    elif key == 'scient':
        scient = {}
        scient['element'] = value['element']
        scient['comp'] = value['comp']
        scient['name'] = value['name']
        scient = Scient(**scient)
        if not value['weapon'] == None:
            scient.weapon = convert_dict(value['weapon'])
        if not value['location'] == None:
            scient.location = Loc(value['location'][0], value['location'][1])
        return scient

    elif key == 'nescient':
        nescient = {}
        nescient['element'] = value['element']
        nescient['comp'] = value['comp']
        nescient['name'] = value['name']
        nescient['facing'] = value['facing']
        nescient['body'] = {}
        for part in value['body'].keys():
            nescient['body'][part] = Part(
                None, value['body'][part]['part']['location'])
        nescient = Nescient(**nescient)
        if not value['location'] == None:
            nescient.location = Loc(value['location'][0], value['location'][1])
        return nescient

    elif key == 'player':
        squads = []
        for squad in value['squads']:
            squads.append(convert_dict(squad))
        return Player(value['name'], squads)

    else:
        #for weapons
        return eval(
            key.capitalize())(**eval(''.join(str(value).replace("u'", "'"))))
Beispiel #4
0
from binary_tactics.player import Player
from binary_tactics.units import Squad
from stores.store import get_persisted #which is actually buggy in this case.
import pycassa

pool = pycassa.connect('bt')
cf = pycassa.ColumnFamily(pool, 'PLAYERS')
p =  Player({}, 'player 1', get_persisted(Squad()), {}, {}, {})
foo = {'1': p}
cf.insert(foo.keys()[0], foo['1'])


===


from stores.store import *
from binary_tactics.player  import Player
from binary_tactics.helpers import *
from binary_tactics.weapons import *
from binary_tactics.units   import *
from binary_tactics.stone   import *
Beispiel #5
0
            if e.args[0] == 'Game Over':
                write_battlelog()
                reactor.stop()

    world_zeo = World_zeo()
    world = world_zeo.root
    maxsecs = timedelta(0, world['resigntime'])
    world_coords = str(sys.argv[1])
    #this copy is really important, copies the objects out of the zeo and into memory.
    f = copy.deepcopy(world['Fields'][world_coords])
    ply_time = 600  #for testing ending conditions
    #ply_time = f.ply_time
    atkr_name, atksquad = f.battlequeue[0]
    defsquad = f.get_defenders()
    #TODO rewrite player and hex_battle
    dfndr = Player(f.owner, [defsquad])
    atkr = Player(atkr_name, [atksquad])
    game = Game(grid=f.grid, defender=dfndr, attacker=atkr)
    btl = game.battlefield

    #!!!obviously for testing only.
    #The locations should be pushed to world before battle is started.
    for s in xrange(2):
        l = len(btl.squads[s])
        for x in xrange(l):
            btl.place_object(btl.squads[s][x], Loc(x, s))

    game.log['init_locs'] = game.log.init_locs()
    start_time = datetime.strptime(game.log['start_time'],
                                   "%Y-%m-%d %H:%M:%S.%f")
    ART = start_time + maxsecs  #attacker resign time
Beispiel #6
0
from binary_tactics.grid import Grid, Loc
from stores.store import get_persisted
from copy import deepcopy

addr = 'localhost', 9100
storage = ClientStorage.ClientStorage(addr)
db = DB(storage)
conn = db.open()
root = conn.root()

#assuming world_editor.py has been run first
#this pulls the battle out of ZODB, maintains the atomicity of the battle.
f = deepcopy(root['Fields']['(0, 0)'])
atkr_name, squad1 = f.battlequeue[0]
squad2 = f.get_defenders()
atkr = Player(atkr_name, [squad1])
dfndr = Player(f.owner, [squad2])
game = Game(
    grid=f.grid,
    defender=dfndr,
    attacker=atkr,
)
btl = game.battlefield

for s in btl.squads:  #location wonkiness in hex_battlefield.
    for u in s:
        u.location = Loc(None, None)
for s in range(2):
    for x in range(4):
        btl.place_object(btl.squads[s][x], Loc(x, s))
Beispiel #7
0
Created by AFD on 2010-10-14.
Copyright (c) 2010 A. Frederick Dudley. All rights reserved.
"""

from stores.mongo_store import *
from stores.store import *
from pymongo.connection import Connection
from pymongo.database import Database

from binary_tactics.player import Player
from binary_tactics.helpers import *
from binary_tactics.weapons import *
from binary_tactics.units import *
from binary_tactics.stone import *

connection = Connection(host='bt.hipeland.org')
db = Database(connection, 'binary_tactics')
db.authenticate('rix', 'fhpxguvf'.decode('rot13'))

exists = {'$exists': True}
#squads = db.binary_tactics.find({'squad': exists})
#grids  = db.binary_tactics.find({'grid': exists})

#squad   = [convert_dict(get_dict(db.binary_tactics.find({'squad.value': 1004})[0], db.binary_tactics, db))]
squad = [rand_squad()]
units = [n for n in squad[0]]
weapons = [n.weapon for n in squad[0]]
stones = [rand_comp() for n in xrange(6)]
w = Player('The World', squad, stones, units, weapons, [])