def CheckLvlUp(_1, player: Ai): needed_stones = player.elevation_array[player.getLevel()] inventory = player.getInventory() for stone, nb in needed_stones: if inventory[stone] < nb: return Actions.FIND_CRYSTALS return Actions.CHECK_PLAYER
def Synchronise(client: Client, player: Ai): if Synchronise.look_id == -1: Synchronise.look_id = client.build_command( "Look", "", (player.getCoord(), player.getDir())) if Synchronise.look_id != client.last: return Actions.SYNCHRO Synchronise.look_id = -1 return Synchronise.return_func
def Drop(client: Client, player: Ai): client.build_command("Broadcast", "Drop") needed_stone = player.elevation_array[player.getLevel()] for stone, nb in needed_stone: for drop in range(nb): client.build_command("Set", stone) if player.getBroadcaster(): take_all_resources(client, player) return Actions.LVL_UP
def take_all_resources(client: Client, player: Ai): x = player.getCoord()[0] % client.mapSize[0] y = player.getCoord()[1] % client.mapSize[1] map = player.getMap() items = map[y][x].getStones() for obj, nb in items.items(): if nb > 0: while nb > 0: client.build_command("Take", obj, (x, y)) nb -= 1
def LvlUp(client: Client, player: Ai): needed_stones = player.elevation_array[player.getLevel()] if LvlUp.Synchro == -1: # client.build_command("Look", "", (player.getCoord(), player.getDir())) Synchronise_incant.return_func = Actions.LVL_UP LvlUp.Synchro = 1 LvlUp.OldLvl = player.getLevel() return Actions.SYNCHRO_INCANT LvlUp.Synchro = -1 if LvlUp.OldLvl == player.getLevel(): client.build_command("Broadcast", "Fail Incant") return Actions.LOOK
def CheckPlayer(client: Client, player: Ai): nb_player = player.elevation_player[player.getLevel()] x = player.getCoord()[0] % client.mapSize[0] y = player.getCoord()[1] % client.mapSize[1] if nb_player != player.getMap()[y][x].getPlayer(): if nb_player < player.getMap()[y][x].getPlayer(): return Actions.FORWARD if len(client.msgQueue) > 0: return Actions.FIND_IF_BROADCASTER return Actions.MAKE_FOOD_STOCK else: return Actions.TAKE_ALL
def TakeAll(client: Client, player: Ai): needed_stone = player.elevation_array[player.getLevel()] take_all_resources(client, player) for stone, nb in needed_stone: for drop in range(nb): client.build_command("Set", stone) return Actions.LVL_UP
def Forward(client: Client, player: Ai): x = player.getCoord()[0] % client.mapSize[0] y = player.getCoord()[1] % client.mapSize[1] x_forward = (x + 1) % client.mapSize[0] y_forward = (y + 1) % client.mapSize[1] shifting(client, player, [x_forward, y_forward]) return Actions.LOOK
def FindFood(client: Client, player: Ai): radar = PathFinding.radar(player.getCoord()[0], player.getCoord()[1], 9) map = player.getMap() x = player.getCoord()[0] % client.mapSize[0] y = player.getCoord()[1] % client.mapSize[1] if map[y][x].getStones()["food"] != 0: client.build_command("Take", "food", tuple((x, y))) for x, y in radar: y %= client.mapSize[1] x %= client.mapSize[0] if map[y][x].getStones()["food"] != 0: shifting(client, player, [x, y]) map[y][x].setPlayer(map[y][x].getPlayer() + 1) client.build_command("Take", "food", tuple((x, y))) return Actions.LOOK return Actions.FORWARD
def IncantBroadCast(client: Client, player: Ai): if IncantBroadCast.Synchro == -1: client.build_command("Look", "", (player.getCoord(), player.getDir())) IncantBroadCast.Synchro = 1 Synchronise_inventory.return_func = Actions.NEED_PEOPLE return Actions.SYNCHRO_INVENTORY IncantBroadCast.Synchro = -1 if player.getInventory()["food"] <= 6: return Actions.LOOK x = player.getCoord()[0] y = player.getCoord()[1] nb_player = player.elevation_player[player.getLevel()] str = "{}: Incantation Lvl {}".format(player.getId(), int(player.getLevel())) client.build_command("Broadcast", str) if nb_player == player.getMap()[y][x].getPlayer(): return Actions.DROP player.setBroadcaster(True) return Actions.NEED_PEOPLE
def FindCrystals(client: Client, player: Ai): radar = PathFinding.radar(player.getCoord()[0], player.getCoord()[1], 9) map = player.getMap() needed_stones = player.elevation_array[player.getLevel()] x = player.getCoord()[0] % client.mapSize[0] y = player.getCoord()[1] % client.mapSize[1] for stone, _ in needed_stones: if map[y][x].getStones()[stone] != 0: client.build_command("Take", stone, tuple((x, y))) for x, y in radar: for stone, _ in needed_stones: y %= client.mapSize[1] x %= client.mapSize[0] if map[y][x].getStones()[stone] != 0: shifting(client, player, [x, y]) client.build_command("Take", stone, tuple((x, y))) map[y][x].setPlayer(map[y][x].getPlayer() + 1) return Actions.LOOK return Actions.FORWARD
def shifting(client: Client, player: Ai, to_go: list): map = player.getMap() player_coord = [ player.getCoord()[0] % client.mapSize[0], player.getCoord()[1] % client.mapSize[1] ] finding_path = PathFinding(client.mapSize[1], client.mapSize[0]) map[player_coord[1]][player_coord[1]].setPlayer( map[player_coord[1]][player_coord[0]].getPlayer() - 1) try: actions, player.dir = finding_path.goToTile(player.getCoord(), to_go, player.getDir()) for move in actions: client.build_command(move) except ValueError: print(player.getDir()) player.setCoord(to_go[0], to_go[1])
def CheckingFood(client: Client, player: Ai): client.build_command("Inventory") if player.getInventory()["food"] < 5: return Actions.FIND_FOOD return Actions.CHECK_LVL_UP