diff --git a/debug.py b/debug.py index 8a19f71..0e59028 100644 --- a/debug.py +++ b/debug.py @@ -41,17 +41,22 @@ def _random_action(Arena, Player_one): 1: 'attack', 2: 'move', } - action= _rand.randint(1, len(_RANDOM_ACTIONS)) + #action= _rand.randint(1, len(_RANDOM_ACTIONS)) msg= '' - if action == 1: + Map= Arena.get_map() + avail_actions= Map.get_player_available_actions(Player_one) + #actions= list(avail_actions.keys()) + #_rand.shuffle(actions) + #action= actions[0] + if 1 in avail_actions: # XXX maybe in future this action is available only if you are near to another player # so Player_two is no more random, but will be a random near player - Player_two= _rand.sample(Arena.get_alive_players(), 1)[0] + preys= avail_actions[1] + Player_two= _rand.sample(preys, 1)[0] while Player_one.get_id() == Player_two.get_id(): - Player_two= _rand.sample(Arena.get_alive_players(), 1)[0] + Player_two= _rand.sample(preys, 1)[0] _dmg, msg= Player_one.attack(Player_two) - elif action == 2: - Map= Arena.get_map() + elif 2 in avail_actions: available_movements= Map.get_player_available_directions(Player_one) if not available_movements: return f'{Player_one.get_name()} Pensa a Guarino tutto il giorno' # XXX probably should skip this action and look for another action _rand.shuffle(available_movements) diff --git a/entities/gamemap.py b/entities/gamemap.py index 2ec92cf..19aaa1c 100644 --- a/entities/gamemap.py +++ b/entities/gamemap.py @@ -115,25 +115,47 @@ class BrSimMap(): avail_directions.append((0, 1, 'giu\'')) return avail_directions - def check_near_players(self): + def check_near_players(self, Player): # TODO Implement me - return True + # 1. range weapons like arch can attack from distance + # 2. knife, sword and punch can attack only on immediate near cell - def check_near_items(self): + coord_x, coord_y= Player.get_coordinates() + attackable_players= [] + for shift in [-1, 1]: + x= coord_x + shift + if x < 0 or x >= self.world_width -1: continue + resource= self.get_map_matrix()[x][coord_y] + if resource and resource.is_player(): attackable_players.append(resource) + for shift in [-1, 1]: + y= coord_y + shift + if y < 0 or y >= self.world_height -1: continue + resource= self.get_map_matrix()[coord_x][y] + if resource and resource.is_player(): attackable_players.append(resource) + + return attackable_players + + def check_near_items(self, Player): # TODO Implement me - return False + return [] def get_player_available_actions(self, Player): # TODO: define actions list coord_x, coord_y= Player.get_coordinates() - avail_actions= [] - - if self.check_near_players(Player): - avail_actions.append(1) #XXX replace with attack action (or maybe other actions on players) + avail_actions= {} + + attack= self.check_near_players(Player) + if attack: + print(f'{Player.get_name()} can attack {[a.get_name() for a in attack]}') + #avail_actions.append(1) #XXX replace with attack action (or maybe other actions on players) + avail_actions[1]= attack #XXX replace with attack action (or maybe other actions on players) if self.get_player_available_directions(Player): - avail_actions.append(2) #XXX replace with action move - if self.check_near_items(Items): - avail_actions.append(3) #XXX replace with get item action + avail_actions[2]= True #XXX replace with action move + items= self.check_near_items(Player) + if items: + avail_actions[3]= items #XXX replace with get item action + + return avail_actions def get_renderized_map(self): res= '' diff --git a/entities/player.py b/entities/player.py index 2e63c4d..be6b5bd 100644 --- a/entities/player.py +++ b/entities/player.py @@ -9,7 +9,7 @@ class BrSimPlayer(_resource.BrSimResource): self.id= str(_uuid.uuid4()) self.name= name self.stats= '' - self.health= _random.randint(1,3) + self.health= _random.randint(1,1) self.inventory= inventory or [] self.damage= _random.randint(1,2) # this is the punch damage amount self.max_weight= 5 # this is the max inventory weight