From 3cc6966d8604f03f41afe33bdbc15d7f0447c4a448b0730759940dbf89f63e10 Mon Sep 17 00:00:00 2001 From: andrea Date: Sat, 2 Aug 2025 09:33:06 +0200 Subject: [PATCH] fix merge regression and exlude death player from attackable players --- debug.py | 15 +++++++++------ entities/gamemap.py | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/debug.py b/debug.py index a7d1d0b..c642079 100644 --- a/debug.py +++ b/debug.py @@ -23,16 +23,19 @@ def _random_action(Arena, Player_one): 1: 'attack', 2: 'move', } - action= _rand.randint(1, len(_RANDOM_ACTIONS)) + Map= Arena.get_map() + avail_actions= Map.get_player_available_actions(Player_one) + print(f'{Player_one.get_name()}:{Player_one.get_coordinates()}, avail_actions: {avail_actions}') msg= '' - if action == 1: + 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] - while Player_one.get_id() == Player_two.get_id(): - 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() and not Player_two.is_alive(): + Player_two= _rand.sample(preys, 1)[0] _dmg, msg= Player_one.attack(Player_two) - elif action == 2: + elif 2 in avail_actions: Map= Arena.get_map() available_movements= Map.get_player_available_directions(Player_one) if not available_movements: diff --git a/entities/gamemap.py b/entities/gamemap.py index e27b22e..e3bd722 100644 --- a/entities/gamemap.py +++ b/entities/gamemap.py @@ -126,12 +126,12 @@ class BrSimMap(): x= coord_x + shift if x < 0 or x >= self.world_width -1: continue resource= self.get_map_matrix()[coord_y][x] - if resource and resource.is_player(): attackable_players.append(resource) + if resource and resource.is_player() and resource.is_alive(): 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()[y][coord_x] - if resource and resource.is_player(): attackable_players.append(resource) + if resource and resource.is_player() and resource.is_alive(): attackable_players.append(resource) return attackable_players