diff --git a/src/agent/hero.py b/src/agent/hero.py index 368c312..2bfed6a 100644 --- a/src/agent/hero.py +++ b/src/agent/hero.py @@ -32,31 +32,40 @@ class Player(Creature): self.__listOfChests = list_of_chests self.__actionsCollection = [] + def prepare_data(self, opponent): + return [self.get_strength(), self.get_agility(), self.get_wisdom(), self.get_health(), + self.get_melee_damage(), self.get_ranged_damage(), self.get_magic_damage(), + self.get_armor_defence(), self.get_armor_magic_protection(), + opponent.get_strength(), opponent.get_agility(), opponent.get_wisdom(), opponent.get_health(), + opponent.get_damage(), opponent.get_armor_defence(), opponent.get_armor_magic_protection(), + opponent.get_attack_type().upper(), "PASS"] + def melee_attack(self, opponent): attack_value = self.strength + roll_the_dice(6) - defense_value = opponent.strength + opponent.armor.defence + defense_value = opponent.strength + opponent.armor.get_defence() damage = attack_value - defense_value if damage > 0: - opponent.health = opponent.health - (damage + self.weapon1.damage) + opponent.health = opponent.health - (damage + self.weapon1.get_damage()) def range_attack(self, opponent): attack_value = self.agility + roll_the_dice(6) defense_value = opponent.agility damage = attack_value - defense_value - if (damage > 0) and (damage + self.weapon2.damage - opponent.armor.defence > 0): - opponent.health = opponent.health - (damage + self.weapon2.damage - opponent.armor.defence) + if (damage > 0) and (damage + self.weapon2.get_damage() - opponent.armor.get_defence() > 0): + opponent.health = opponent.health - (damage + self.weapon2.get_damage() - opponent.armor.get_defence()) def magic_attack(self, opponent): attack_value = self.wisdom + roll_the_dice(6) defense_value = opponent.wisdom damage = attack_value - defense_value - if (damage > 0) and (damage + self.weapon3.damage - opponent.armor.mag_protection > 0): - opponent.health = opponent.health - (damage + self.weapon3.damage - opponent.armor.mag_protection) + if (damage > 0) and (damage + self.weapon3.get_damage() - opponent.armor.get_mag_protection() > 0): + opponent.health = opponent.health - (damage + self.weapon3.get_damage() - opponent.armor.get_mag_protection()) def fight_or_flight(self, opponent): combat = True while combat: choice = roll_the_dice(4) + #TODO: choice będzie się równał decyzji zwróconej przez R print("roll_the_dice rolled:", choice) if choice == 1: running_speed = self.agility + roll_the_dice(6) @@ -184,7 +193,7 @@ class Player(Creature): self.model.grid.move_agent(self, (new_state.get_x(), new_state.get_y())) self.direction = new_state.get_direction() - print("moved to - ", [new_state.get_x(), new_state.get_y()]) + #print("moved to - ", [new_state.get_x(), new_state.get_y()]) cellmates = self.model.grid.get_cell_list_contents([self.pos]) if len(cellmates) > 1: @@ -193,8 +202,11 @@ class Player(Creature): else: opponent = cellmates[0] print("Fighting") + testcase=self.prepare_data(opponent) + print(testcase) + #TODO: get all data, nominalize, pass to R self.fight_or_flight(opponent) # print("HP: " + str(self.health) + " / " + str(self.maxHealth)) - print("Gold: " + str(self.gold)) + #print("Gold: " + str(self.gold)) else: print("HP: 0 / " + str(self.maxHealth)) diff --git a/src/agent/map/gameMap.py b/src/agent/map/gameMap.py index fd5a904..06b60a8 100644 --- a/src/agent/map/gameMap.py +++ b/src/agent/map/gameMap.py @@ -8,7 +8,7 @@ from src.agent.model.creature import Creature from src.agent.model.box import Box -from src.items.armory import WM1, A1, WR1, S1, WM2, A2 +from src.items.armory import *#WM1, A1, WR1, S1, WM2, A2 from mesa.time import RandomActivation from mesa.space import MultiGrid @@ -17,8 +17,8 @@ from mesa.space import MultiGrid x = 10 y = 10 step_counter = 0 -boxes_number = 4 -creatures_number = 5 +boxes_number = 5 +creatures_number = 25 class GameMap(Model): @@ -29,7 +29,6 @@ class GameMap(Model): self.boxes_number = boxes_number self.creatures_number = creatures_number self.running = True - # player = Player(1000, self) self.player = Player(1000, self, "Janusz", 3, 3, 3, 20, 20, WM1, A1, 0, WR1, S1, self.listOfChests) self.schedule.add(self.player) x = self.random.randrange(self.grid.width) @@ -51,6 +50,7 @@ class GameMap(Model): self.boxes_number + self.creatures_number): # taki range, żeby każdy agent miał poprawne unique_id # creature = Creature(i, self) creature = Creature(i, self, "Goblin", 1, 1, 1, 1, 1, WM2, A2, roll_the_dice(6)) + x = self.random.randrange(self.grid.width) y = self.random.randrange(self.grid.height) if self.grid.is_cell_empty((x, y)): diff --git a/src/agent/model/creature.py b/src/agent/model/creature.py index c6b8d3d..b68c80a 100644 --- a/src/agent/model/creature.py +++ b/src/agent/model/creature.py @@ -18,12 +18,44 @@ class Creature(Agent): self.isCreature = True self.isPlayer = False + def get_strength(self): + return self.strength + + def get_agility(self): + return self.agility + + def get_wisdom(self): + return self.wisdom + + def get_health(self): + return self.health + + def get_damage(self): + return self.weapon1.get_damage() + + def get_melee_damage(self): + return self.weapon1.get_damage() + + def get_ranged_damage(self): + return self.weapon2.get_damage() + + def get_magic_damage(self): + return self.weapon3.get_damage() + + def get_armor_defence(self): + return self.armor.get_defence() + + def get_armor_magic_protection(self): + return self.armor.get_mag_protection() + + def get_attack_type(self): + return self.weapon1.get_type() def melee_attack(self, opponent): attack_value = self.strength + roll_the_dice(6) - defense_value = opponent.strength + opponent.armor.defence + defense_value = opponent.strength + opponent.armor.get_defence() damage = attack_value - defense_value if damage > 0: - opponent.health = opponent.health - (damage + self.weapon1.damage) + opponent.health = opponent.health - (damage + self.weapon1.get_damage()) def range_attack(self, opponent): attack_value = self.agility + roll_the_dice(6) @@ -36,13 +68,13 @@ class Creature(Agent): attack_value = self.wisdom + roll_the_dice(6) defense_value = opponent.wisdom damage = attack_value - defense_value - if (damage > 0) and (damage + self.weapon1.damage - opponent.armor.mag_protection > 0): - opponent.health = opponent.health - (damage + self.weapon1.damage - opponent.armor.mag_protection) + if (damage > 0) and (damage + self.weapon1.get_damage() - opponent.armor.get_mag_protection() > 0): + opponent.health = opponent.health - (damage + self.weapon1.get_damage() - opponent.armor.get_mag_protection()) def default_attack(self, opponent): - if self.weapon1.type == "Meele": + if self.weapon1.get_type() == "Meele": self.melee_attack(opponent) - elif self.weapon1.type == "Range": + elif self.weapon1.get_type() == "Range": self.range_attack(opponent) else: self.magic_attack(opponent) diff --git a/src/treesearch/bfs.py b/src/treesearch/bfs.py index fdf930b..0d4e337 100644 --- a/src/treesearch/bfs.py +++ b/src/treesearch/bfs.py @@ -103,7 +103,7 @@ class BFS: self.__agent.model.grid.get_cell_list_contents( [(new_state[1].get_x(), new_state[1].get_y())])]): if new_state[0] == 0: - monster = 10 + monster = -1 p = manhattan(new_state[1], goal_state) + tmp_node.get_cost() + monster + 1 r = 0