Example #1
0
 def unregisterToken(self):
     if self.tokena: C.unregisterG(self.tokena)
     if self.tokenb: C.unregisterG(self.tokenb)
Example #2
0
 def deleteGame(self):
     self.unregisterToken()
     C.deleteGame(self.gameid)
Example #3
0
 def registerSingleGame(self, civ):
     a = C.singlePlayerGame(civ)
     self.tokena = a[0]
     self.gameid = a[1]
Example #4
0
 def registerTwoGames(self, civs):
     self.tokena = C.twoPlayersGameWithAutom(civs)
     (self.tokenb, self.gameid) = misc.joinGame()
Example #5
0
 def playSingleCommand(self, co, selfun=None, selfun1=None, param=None):
     self.co = co
     logging.info(_getCiv(self) + " " + str(co))
     if co == CO.Command.ENDOFMOVE or co == CO.Command.PLAYUNIT or co == CO.Command.PLAYUNITIRON or co == CO.Command.ENDBATTLE:
         self.i = []
     else:
         self.i = C.itemizeCommand(self.token, CO.toS(self.co))
     if self.co == CO.Command.SETCAPITAL:
         _buildCity(self)
         return True
     if self.co == CO.Command.SETSCOUT or self.co == CO.Command.SETARMY or self.co == CO.Command.BUYSCOUT or self.co == CO.Command.BUYARMY:
         _deployFigure(self)
         return True
     if self.co == CO.Command.BUYAIRCRAFT or self.co == CO.Command.BUYARTILLERY or self.co == CO.Command.BUYINFANTRY or self.co == CO.Command.BUYMOUNTED:
         _buyUnit(self)
         return True
     if self.co == CO.Command.STARTMOVE:
         _startMove(self, selfun)
         return True
     if self.co == CO.Command.MOVE or self.co == CO.Command.EXPLOREHUT:
         _move(self, selfun)
         return True
     if self.co == CO.Command.ENDOFMOVE:
         _endOfMove(self)
         return True
     if self.co == CO.Command.REVEALTILE:
         _revealTile(self)
         return True
     if self.co == CO.Command.ENDOFPHASE:
         _endOfPhase(self)
         return True
     if self.co == CO.Command.RESEARCH:
         _researchTechnology(self)
         return True
     if self.co == CO.Command.HARVESTRESOURCE:
         _harvestResource(self)
         return True
     if self.co == CO.Command.SENDPRODUCTION:
         _sendProduction(self)
         return True
     if self.co == CO.Command.BUYBUILDING:
         _buyBuilding(self, "building", selfun, selfun1)
         return True
     if self.co == CO.Command.BUYWONDER:
         _buyBuilding(self, "wonder", selfun, selfun1)
         return True
     if self.co == CO.Command.GREATPERSONPUT or self.co == CO.Command.GREATPERSONPUTNOW:
         _buyBuilding(self, "greatperson", selfun, selfun1)
         return True
     if self.co == CO.Command.DEVOUTTOCULTURE:
         _devottoCluster(self)
         return True
     if self.co == CO.Command.ADVANCECULTURE or self.co == CO.Command.GREATPERSONPUTNOWRESIGN:
         _doAction(self)
         return True
     if self.co == CO.Command.SPENDTRADE:
         _spendTrade(self, selfun, param)
         return True
     if self.co == CO.Command.DISCARDCARD:
         _discardCard(self)
         return True
     if self.co == CO.Command.CURRENCYACTION:
         _currencyAction(self)
         return True
     if self.co == CO.Command.USESILKFORTRADE9:
         _useSilkAction9(self)
         return True
     if self.co == CO.Command.ATTACK:
         _attack(self)
         return True
     if self.co == CO.Command.PLAYUNIT or self.co == CO.Command.PLAYUNITIRON:
         _playUnit(self)
         return True
     if self.co == CO.Command.ENDBATTLE:
         self.executeCommandJ(_winnerLoot(self))
         return True
     return False
Example #6
0
 def deployTwoGame(self, board, civ):
     a = C.postsingleGame(board, civ).split(',')
     self.tokena = a[0]
     self.tokenb = a[1]
     self.gameid = a[2]
Example #7
0
 def doCommand(self, co, row=-1, col=-1, jsparam=None):
     C.executeCommand(self.token, CO.toS(co), row, col, jsparam)
Example #8
0
 def readBoard(self):
     b = C.getBoard(self.token)
     # can be empty if nothing has changed
     # leave the previous board
     self.bchanged = b != None
     if b: self.b = b
Example #9
0
def registerNewGame():
    return C.twoPlayersGameWithAutom("China,Rome")
Example #10
0
 def doCommandS(self, cos, row=-1, col=-1, jsparam=None):
     C.executeCommand(self.token, cos, row, col, jsparam)
Example #11
0
def joinGame():
    (token, _) = misc.joinGame()
    return token


def chooseCommand(b):
    commands = b['board']['you']['commands']
    if len(commands) == 0: return None
    i = random.randrange(0, len(commands))
    return commands[i]['command']


if __name__ == '__main__':
    random.seed()
    try:
        C.registerAutom()
        tokenp = registerNewGame()
        print(tokenp)
        tokena = joinGame()
        print(tokena)
        b = C.getBoard(tokenp)
        print(b)
        y = b['board']['you']
        print(y)
        co = y['commands']
        print(co)
        comm = chooseCommand(b)
        print(comm)
        item = C.itemizeCommand(tokena, comm)
        print(item)
    except Exception as e:
Example #12
0
def joinGame():
    gameid = C.getGameid()
    games = C.getWaitingGames()
    civwaiting = C.findGame(games, gameid)
    token = C.joinGame(gameid, civwaiting).split(',')[0]
    return (token, gameid)
Example #13
0
'''
Created on 6 lut 2019

@author: civ
'''
from com.civ.rest import CivRest as C

if __name__ == '__main__':
    C.postsingleGame("China", "aaaaaaaaaaaaa")
Example #14
0
@author: civ
'''

from com.civ.rest import CivRest as C
import random
from com.civ.play import misc
from com.civ.play.Play import Play


def registerNewGame():
    return C.twoPlayersGameWithAutom("China,Rome")


def play(P):
    P.readBoard()
    while P.playCommand():
        P.readBoard()


if __name__ == '__main__':
    random.seed()
    try:
        C.registerAutom()
        tokena = registerNewGame()
        tokenb = misc.joinGame()
        PA = Play(tokena)
        PB = Play(tokenb)
        play(PA)
    except Exception as e:
        print(e)
def startTest() :
    C.registerAutom()
    C.clearWaitingList()
    logging.basicConfig(level=logging.INFO)