player prepares a list of data necessary for decision making, weapon getters used
This commit is contained in:
parent
d5b132290c
commit
00356fde40
@ -32,31 +32,40 @@ class Player(Creature):
|
|||||||
self.__listOfChests = list_of_chests
|
self.__listOfChests = list_of_chests
|
||||||
self.__actionsCollection = []
|
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):
|
def melee_attack(self, opponent):
|
||||||
attack_value = self.strength + roll_the_dice(6)
|
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
|
damage = attack_value - defense_value
|
||||||
if damage > 0:
|
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):
|
def range_attack(self, opponent):
|
||||||
attack_value = self.agility + roll_the_dice(6)
|
attack_value = self.agility + roll_the_dice(6)
|
||||||
defense_value = opponent.agility
|
defense_value = opponent.agility
|
||||||
damage = attack_value - defense_value
|
damage = attack_value - defense_value
|
||||||
if (damage > 0) and (damage + self.weapon2.damage - opponent.armor.defence > 0):
|
if (damage > 0) and (damage + self.weapon2.get_damage() - opponent.armor.get_defence() > 0):
|
||||||
opponent.health = opponent.health - (damage + self.weapon2.damage - opponent.armor.defence)
|
opponent.health = opponent.health - (damage + self.weapon2.get_damage() - opponent.armor.get_defence())
|
||||||
|
|
||||||
def magic_attack(self, opponent):
|
def magic_attack(self, opponent):
|
||||||
attack_value = self.wisdom + roll_the_dice(6)
|
attack_value = self.wisdom + roll_the_dice(6)
|
||||||
defense_value = opponent.wisdom
|
defense_value = opponent.wisdom
|
||||||
damage = attack_value - defense_value
|
damage = attack_value - defense_value
|
||||||
if (damage > 0) and (damage + self.weapon3.damage - opponent.armor.mag_protection > 0):
|
if (damage > 0) and (damage + self.weapon3.get_damage() - opponent.armor.get_mag_protection() > 0):
|
||||||
opponent.health = opponent.health - (damage + self.weapon3.damage - opponent.armor.mag_protection)
|
opponent.health = opponent.health - (damage + self.weapon3.get_damage() - opponent.armor.get_mag_protection())
|
||||||
|
|
||||||
def fight_or_flight(self, opponent):
|
def fight_or_flight(self, opponent):
|
||||||
combat = True
|
combat = True
|
||||||
while combat:
|
while combat:
|
||||||
choice = roll_the_dice(4)
|
choice = roll_the_dice(4)
|
||||||
|
#TODO: choice będzie się równał decyzji zwróconej przez R
|
||||||
print("roll_the_dice rolled:", choice)
|
print("roll_the_dice rolled:", choice)
|
||||||
if choice == 1:
|
if choice == 1:
|
||||||
running_speed = self.agility + roll_the_dice(6)
|
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.model.grid.move_agent(self, (new_state.get_x(), new_state.get_y()))
|
||||||
self.direction = new_state.get_direction()
|
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])
|
cellmates = self.model.grid.get_cell_list_contents([self.pos])
|
||||||
if len(cellmates) > 1:
|
if len(cellmates) > 1:
|
||||||
@ -193,8 +202,11 @@ class Player(Creature):
|
|||||||
else:
|
else:
|
||||||
opponent = cellmates[0]
|
opponent = cellmates[0]
|
||||||
print("Fighting")
|
print("Fighting")
|
||||||
|
testcase=self.prepare_data(opponent)
|
||||||
|
print(testcase)
|
||||||
|
#TODO: get all data, nominalize, pass to R
|
||||||
self.fight_or_flight(opponent)
|
self.fight_or_flight(opponent)
|
||||||
# print("HP: " + str(self.health) + " / " + str(self.maxHealth))
|
# print("HP: " + str(self.health) + " / " + str(self.maxHealth))
|
||||||
print("Gold: " + str(self.gold))
|
#print("Gold: " + str(self.gold))
|
||||||
else:
|
else:
|
||||||
print("HP: 0 / " + str(self.maxHealth))
|
print("HP: 0 / " + str(self.maxHealth))
|
||||||
|
@ -8,7 +8,7 @@ from src.agent.model.creature import Creature
|
|||||||
|
|
||||||
from src.agent.model.box import Box
|
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.time import RandomActivation
|
||||||
from mesa.space import MultiGrid
|
from mesa.space import MultiGrid
|
||||||
|
|
||||||
@ -17,8 +17,8 @@ from mesa.space import MultiGrid
|
|||||||
x = 10
|
x = 10
|
||||||
y = 10
|
y = 10
|
||||||
step_counter = 0
|
step_counter = 0
|
||||||
boxes_number = 4
|
boxes_number = 5
|
||||||
creatures_number = 5
|
creatures_number = 25
|
||||||
|
|
||||||
|
|
||||||
class GameMap(Model):
|
class GameMap(Model):
|
||||||
@ -29,7 +29,6 @@ class GameMap(Model):
|
|||||||
self.boxes_number = boxes_number
|
self.boxes_number = boxes_number
|
||||||
self.creatures_number = creatures_number
|
self.creatures_number = creatures_number
|
||||||
self.running = True
|
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.player = Player(1000, self, "Janusz", 3, 3, 3, 20, 20, WM1, A1, 0, WR1, S1, self.listOfChests)
|
||||||
self.schedule.add(self.player)
|
self.schedule.add(self.player)
|
||||||
x = self.random.randrange(self.grid.width)
|
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
|
self.boxes_number + self.creatures_number): # taki range, żeby każdy agent miał poprawne unique_id
|
||||||
# creature = Creature(i, self)
|
# creature = Creature(i, self)
|
||||||
creature = Creature(i, self, "Goblin", 1, 1, 1, 1, 1, WM2, A2, roll_the_dice(6))
|
creature = Creature(i, self, "Goblin", 1, 1, 1, 1, 1, WM2, A2, roll_the_dice(6))
|
||||||
|
|
||||||
x = self.random.randrange(self.grid.width)
|
x = self.random.randrange(self.grid.width)
|
||||||
y = self.random.randrange(self.grid.height)
|
y = self.random.randrange(self.grid.height)
|
||||||
if self.grid.is_cell_empty((x, y)):
|
if self.grid.is_cell_empty((x, y)):
|
||||||
|
@ -18,12 +18,44 @@ class Creature(Agent):
|
|||||||
self.isCreature = True
|
self.isCreature = True
|
||||||
self.isPlayer = False
|
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):
|
def melee_attack(self, opponent):
|
||||||
attack_value = self.strength + roll_the_dice(6)
|
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
|
damage = attack_value - defense_value
|
||||||
if damage > 0:
|
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):
|
def range_attack(self, opponent):
|
||||||
attack_value = self.agility + roll_the_dice(6)
|
attack_value = self.agility + roll_the_dice(6)
|
||||||
@ -36,13 +68,13 @@ class Creature(Agent):
|
|||||||
attack_value = self.wisdom + roll_the_dice(6)
|
attack_value = self.wisdom + roll_the_dice(6)
|
||||||
defense_value = opponent.wisdom
|
defense_value = opponent.wisdom
|
||||||
damage = attack_value - defense_value
|
damage = attack_value - defense_value
|
||||||
if (damage > 0) and (damage + self.weapon1.damage - opponent.armor.mag_protection > 0):
|
if (damage > 0) and (damage + self.weapon1.get_damage() - opponent.armor.get_mag_protection() > 0):
|
||||||
opponent.health = opponent.health - (damage + self.weapon1.damage - opponent.armor.mag_protection)
|
opponent.health = opponent.health - (damage + self.weapon1.get_damage() - opponent.armor.get_mag_protection())
|
||||||
|
|
||||||
def default_attack(self, opponent):
|
def default_attack(self, opponent):
|
||||||
if self.weapon1.type == "Meele":
|
if self.weapon1.get_type() == "Meele":
|
||||||
self.melee_attack(opponent)
|
self.melee_attack(opponent)
|
||||||
elif self.weapon1.type == "Range":
|
elif self.weapon1.get_type() == "Range":
|
||||||
self.range_attack(opponent)
|
self.range_attack(opponent)
|
||||||
else:
|
else:
|
||||||
self.magic_attack(opponent)
|
self.magic_attack(opponent)
|
||||||
|
@ -103,7 +103,7 @@ class BFS:
|
|||||||
self.__agent.model.grid.get_cell_list_contents(
|
self.__agent.model.grid.get_cell_list_contents(
|
||||||
[(new_state[1].get_x(), new_state[1].get_y())])]):
|
[(new_state[1].get_x(), new_state[1].get_y())])]):
|
||||||
if new_state[0] == 0:
|
if new_state[0] == 0:
|
||||||
monster = 10
|
monster = -1
|
||||||
p = manhattan(new_state[1], goal_state) + tmp_node.get_cost() + monster + 1
|
p = manhattan(new_state[1], goal_state) + tmp_node.get_cost() + monster + 1
|
||||||
|
|
||||||
r = 0
|
r = 0
|
||||||
|
Loading…
Reference in New Issue
Block a user