Ejemplo n.º 1
0
def _selectResource(P, resource):
    rs = RE.toS(resource)
    # select hut and resource
    m = _selectHV(P, RE.HV.HUT, rs)
    res = misc.getRandom(m)
    if res: return res
    # market
    res = _selectMarketRes(P, resource)
    if res: return res
    # select village
    m = _selectHV(P, RE.HV.VILLAGE, rs)
    return misc.getRandom(m)
Ejemplo n.º 2
0
def _buildCity(P):
    # print(P.i)
    # choose random
    pos = misc.getRandom(P.i)
    assert (pos != None)
    # print (pos)
    P.executeCommandP(pos)
Ejemplo n.º 3
0
def _deployFigure(P):
    #    print(P.i)
    # choose random city and point
    city = misc.getRandom(P.i)
    # get random square
    c = city["p"]
    point = city["param"]
    P.executeCommandPP(c, point)
Ejemplo n.º 4
0
def _spendTrade(P, selfun, param):
    city = misc.getRandom(P.i, selfun)
    if param == None:
        # calculate random
        no = int(getPlayerTrade(P) / _getPlayerTradeForProd(P))
        # int() calculates prod
        param = misc.getRandomNo(no) + 1
        # calculate random from 0 to no
    P.executeCommandPP(city['p'], param)
Ejemplo n.º 5
0
def playSuspend(P):
    # suspend or anul
    ra = misc.getRandomNo(2)
    # 50 %
    if ra == 0:
        P.doCommand(CO.Command.LETSUSPENDEDGO)
        return
    # anul action
    su = getSuspend(P)
    li = su["list"]
    # list of action to use
    ac = misc.getRandom(li)
    P.doCommandS(ac["command"])
Ejemplo n.º 6
0
def _playUnit(P):
    ba = getBattle(P)
    at = ba['attacker']
    de = ba['defender']
    # turn in attacker and defender excludes themselves
    if at['turn']: am = at
    else: am = de
    if not am['you']: return False
    # am - army making attack now
    (_, fro) = misc.getRandomI(am['waiting']['list'])
    # get random unit from standing units
    f = am['front']
    # list of empty slots
    slots = list(filter(lambda x: f[x] == None, list(range(0, len(f)))))
    to = misc.getRandom(slots)
    P.co = CO.Command.PLAYUNIT
    P.executeCommand(fro, to)
    return True
Ejemplo n.º 7
0
def _winnerLoot(P):
    l = getBattle(P)['winnerloot']
    loottotake = l['loot']
    li = l['list']
    loot = []
    while True:
        # collect list of loots affordable (list of indexes)
        alist = list(
            filter(lambda i: li[i]['loot'] <= loottotake,
                   list(range(0, len(li)))))
        if len(alist) == 0: break
        # take random loot
        ll = misc.getRandom(alist)
        # add to list
        loot.append(li[ll])
        # decrease the loot
        loottotake = loottotake - li[ll]['loot']
        li.pop(ll)
        # next loot
    return loot
Ejemplo n.º 8
0
def _move(P, selfun):
    if P.visited == None: P.visited = []

    moved = []
    key = 'moves'
    if P.co == CO.Command.EXPLOREHUT: key = "explore"
    list = P.i[key]
    if len(list) == 1:
        moved.append(list[0])
    else:
        for i in list:
            if not onList(i, P.visited):
                moved.append(i)

    if len(moved) == 0:
        _endOfMove(P)
        return

    m = misc.getRandom(moved, selfun)
    P.visited.append(m)
    P.executeCommandP(m)
Ejemplo n.º 9
0
def _sendProduction(P):
    f = misc.getRandom(P.i)
    P.executeCommandPP(f['p'], f['param'])
Ejemplo n.º 10
0
def _attack(P):
    l = P.i['attack']
    res = misc.getRandom(l)
    P.executeCommandP(res)
Ejemplo n.º 11
0
def _buyUnit(P):
    #    print(P.i)
    # choose random city
    city = misc.getRandom(P.i)
    c = city["p"]
    P.executeCommandP(c)
Ejemplo n.º 12
0
def _discardCard(P):
    card = misc.getRandom(P.i)
    P.executeCommandJ(card)
Ejemplo n.º 13
0
def _startMove(P, selfun):
    P.visited = None
    f = misc.getRandom(P.i, selfun)
    P.executeCommandPP(f['p'], f['f'])
Ejemplo n.º 14
0
def _devottoCluster(P):
    city = misc.getRandom(P.i)
    P.executeCommandPP(city['p'], city['list'])
Ejemplo n.º 15
0
def _harvestResource(P):
    pair = misc.getRandom(P.i)
    P.executeCommandPP(pair["p"], pair["param"])
Ejemplo n.º 16
0
def _researchTechnology(P):
    tech = misc.getRandom(P.i)
    P.executeCommandJ(tech)
Ejemplo n.º 17
0
def _revealTile(P):
    l = P.i["tiles"]
    # can be more then 1 tile to reveal
    r = misc.getRandom(l)
    P.executeCommandPP(r["p"], r["orientation"])
Ejemplo n.º 18
0
 def __chooseCommand(self):
     comm = self.getCommands()
     return misc.getRandom(comm)
Ejemplo n.º 19
0
def _buyBuilding(P, key, selfun, selfun1):
    city = misc.getRandom(P.i, selfun)
    building = misc.getRandom(city["list"], selfun1)
    P.executeCommandPP(city['p'], {"p": building["p"], key: building[key]})