Пример #1
0
 def applyHeuristic(self, game: Game) -> Game:
     """
         the actions taken are:
             1. place all bonus army in my city with minimum number of soldiers
             2. attack enemy city with minimum number of soldiers that can be attacked
     """
     myCities = game.citiesOf(self.isRedPlayer)
     myMinArmyCityId = self.minArmyCityId(game, myCities)
     game.placeBonusSoldiers(myMinArmyCityId,
                             game.bonusSoldiers(self.isRedPlayer))
     bestUId, bestVId = self.hisMinArmyCityToAttack(game, myCities)
     if bestUId != -1 and bestVId != -1:
         game.move(bestUId, bestVId, game.cityList[bestVId].armyCount + 1)
     return game
Пример #2
0
 def applyHeuristic(self, game: Game) -> Game:
     cityListId = game.citiesOf(self.isRedPlayer)
     bonusArmy = game.bonusSoldiers(self.isRedPlayer)
     maxCity = self.calculateMaxCity(cityListId, game)
     if maxCity != None:
         game.addSoldiersToCity(maxCity.id, bonusArmy)
     # attack all neighbour cities with most armies
     for cityId in cityListId:
         for neighbourId in game.map.graph[cityId]:
             neighbour = game.cityList[neighbourId]
             city = game.cityList[cityId]
             if neighbour.armyCount < city.armyCount - 1 and neighbour.isRedArmy != city.isRedArmy:
                 game.move(city.id, neighbour.id, city.armyCount - 1)
     return game
Пример #3
0
 def apply(self, game: Game):
     self.defenders = game.cityList[self.toId].armyCount
     game.move(self.fromId, self.toId, self.attackers)