Example #1
0
 def robberMode(self, game, tileSet):
     board = game.board
     tileValues = dict()
     for i in range(board.q):
         row = copy.copy(board.hexBoard[i])
         colCtr = 0
         while None in row:
             row.remove(None)
         firstIndex = board.hexBoard[i].index(row[0])
         rowLen = len(row)
         for j in range(rowLen): 
             tile = board.hexBoard[i][j+firstIndex]
             r, q = i, j + firstIndex
             value = 0
             for node in tile.nodes:
                 if (node.owner != None and node.owner != self):
                     value += 1
                 elif (node.owner == self):
                     value -= 1
             tileValues[(i,j)] = value
     for r, q in tileValues:
         if (Tile(r, q) not in tileSet):
             tileValues[(r, q)] = -float('inf')
     values = list(tileValues.values())
     keys = list(tileValues.keys())
     maxTile = keys[values.index(max(values))]
     for tile in tileSet:
         if (tile.pos == maxTile):
             Button.robberHandler(game, ('placeRobber', (tile, self)))
             break
Example #2
0
 def doRoadMove(self, game, roads):
     nextRoad = None
     found = False
     paths = copy.deepcopy(self.chooseBestRoad(game))
     while not found:
         if (len(paths) == 0):
             found = None
             break
         shortestPath = min(paths, key=len)
         while len(shortestPath) < 2:
             paths.remove(shortestPath)
             if (len(paths) > 0):
                 shortestPath = min(paths, key=len)
             else:
                 return
         firstNode = game.board.nodes[shortestPath[0]]
         nextNode = game.board.nodes[shortestPath[1]]
         nextRoad = firstNode.getRoadBetweenNodes(nextNode, game.board)
         if (nextRoad in roads):
             found = True
         else:
             paths.remove(shortestPath)
     if (found == None):
         nextRoad = random.choice(list(roads))
     Button.buildModeHandler(game, ('buildConfirm', (nextRoad, self)))
Example #3
0
 def doSettlementMove(self, game, settlements):
     nextSettlement = None
     maxValue = -1
     for settlement in settlements:
         value = settlement.getNodeValue(game.board)[0]
         if (value > maxValue or maxValue == -1):
             nextSettlement = settlement
             maxValue = value
     Button.buildModeHandler(game, ('buildConfirm', (nextSettlement, self)))
Example #4
0
    def doMove(self, game, listOfMoves):
        self.getBestNodeList(game)
        move, validSet = listOfMoves
        if (move == 'setup'):
            nodeIndex = self.chooseBestNode(game)
            firstNode = game.board.nodes[nodeIndex]
            Button.buildModeHandler(game, ('buildConfirm', (firstNode, self)))
            roadIDs = list(firstNode.getRoads(game.board))
            roads = []
            for roadID in roadIDs:
                roads.append(game.board.edges[roadID])
            self.doRoadMove(game, roads)
        
        elif (move == 'buildCity'):
            if (len(validSet) >= 1):
                self.doCityMove(game, validSet)

        elif (move == 'buildSettlement'):
            if (len(validSet) >= 1):
                self.doSettlementMove(game, validSet)

        elif (move == 'buildRoad'):
            if (len(validSet) >= 1):
                self.doRoadMove(game, validSet)
        
        elif (move == 'buildDevCard'):
            game.buildMode('devCard')
        
        elif (move == 'knight'):
            Button.devCardHandler(game, ('confirmDevCard', ('knight', self)))
        
        elif (move == 'yearOfPlenty'):
            Button.devCardHandler(game, ('confirmDevCard', ('yearOfPlenty', self)))
Example #5
0
 def startYearOfPlenty(self, game):
     while self.countCards() < self.discardGoal:
         values = list(self.resources.values())
         keys = list(self.resources.keys())
         minResource = keys[values.index(min(values))]
         Button.claimHandler(game, ('discard', minResource))
Example #6
0
 def startDiscard(self, game):
     while self.countCards() > self.discardGoal:
         resources = game.checkDiscardConditions(self)
         nextDiscard = random.choice(resources)
         Button.discardHandler(game, ('discard', nextDiscard))
Example #7
0
 def doCityMove(self, game, cities):
     nextCity = random.choice(list(cities))
     Button.buildModeHandler(game, ('buildConfirm', (nextCity, self)))
Example #8
0
 def stealChoice(self, game, victimSet):
     choice = game.board.players[random.choice(list(victimSet))]
     Button.stealHandler(game, ('stealConfirm', choice))