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)
def _buildCity(P):
    # print(P.i)
    # choose random
    pos = misc.getRandom(P.i)
    assert (pos != None)
    # print (pos)
    P.executeCommandP(pos)
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)
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)
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"])
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
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
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)
def _sendProduction(P):
    f = misc.getRandom(P.i)
    P.executeCommandPP(f['p'], f['param'])
Exemple #10
0
def _attack(P):
    l = P.i['attack']
    res = misc.getRandom(l)
    P.executeCommandP(res)
Exemple #11
0
def _buyUnit(P):
    #    print(P.i)
    # choose random city
    city = misc.getRandom(P.i)
    c = city["p"]
    P.executeCommandP(c)
Exemple #12
0
def _discardCard(P):
    card = misc.getRandom(P.i)
    P.executeCommandJ(card)
Exemple #13
0
def _startMove(P, selfun):
    P.visited = None
    f = misc.getRandom(P.i, selfun)
    P.executeCommandPP(f['p'], f['f'])
Exemple #14
0
def _devottoCluster(P):
    city = misc.getRandom(P.i)
    P.executeCommandPP(city['p'], city['list'])
Exemple #15
0
def _harvestResource(P):
    pair = misc.getRandom(P.i)
    P.executeCommandPP(pair["p"], pair["param"])
Exemple #16
0
def _researchTechnology(P):
    tech = misc.getRandom(P.i)
    P.executeCommandJ(tech)
Exemple #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"])
Exemple #18
0
 def __chooseCommand(self):
     comm = self.getCommands()
     return misc.getRandom(comm)
Exemple #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]})