1
0

fix movements

This commit is contained in:
andrea
2025-08-02 09:52:20 +02:00
parent 3cc6966d86
commit 2550f0b262
2 changed files with 15 additions and 10 deletions

View File

@@ -38,6 +38,7 @@ def _random_action(Arena, Player_one):
elif 2 in avail_actions: elif 2 in avail_actions:
Map= Arena.get_map() Map= Arena.get_map()
available_movements= Map.get_player_available_directions(Player_one) available_movements= Map.get_player_available_directions(Player_one)
print(f'{Player_one.get_name()}:{Player_one.get_coordinates()}, avail_movements: {available_movements}')
if not available_movements: if not available_movements:
# XXX probably should skip this action and look for another action # XXX probably should skip this action and look for another action
return f'{Player_one.get_name()} Pensa a Guarino tutto il giorno' return f'{Player_one.get_name()} Pensa a Guarino tutto il giorno'

View File

@@ -13,8 +13,8 @@ class BrSimMap():
def __init__(self, players= None, items= None): def __init__(self, players= None, items= None):
self.players= players or [] self.players= players or []
self.items= items or [] self.items= items or []
self.world_width= 10 #seems a reasonable width for smartphones larger maps would go on a new line self.world_width= 5 #seems a reasonable width for smartphones larger maps would go on a new line
self.world_height= 10 self.world_height= 5
self.game_map= [] self.game_map= []
self.field_sym= _bot_syms.MAP_UTF8_FIELD self.field_sym= _bot_syms.MAP_UTF8_FIELD
self.player_male_sym= _bot_syms.MAP_UTF8_PLAYER_MALE self.player_male_sym= _bot_syms.MAP_UTF8_PLAYER_MALE
@@ -105,14 +105,18 @@ class BrSimMap():
coord_x, coord_y= Player.get_coordinates() coord_x, coord_y= Player.get_coordinates()
avail_directions= [] avail_directions= []
#XXX for now move only on available cells, no over other players/items #XXX for now move only on available cells, no over other players/items
if coord_x > 0 and not self.get_map_matrix()[coord_x - 1][coord_y]: for shift in [-1, 1]:
avail_directions.append((-1, 0, 'sinistra')) x= coord_x + shift
if coord_x < self.world_width -1 and not self.get_map_matrix()[coord_x + 1][coord_y]: if x < 0 or x > self.world_width -1: continue
avail_directions.append((1, 0, 'destra')) resource= self.get_map_matrix()[coord_y][x]
if coord_y > 0 and not self.get_map_matrix()[coord_x][coord_y - 1]: direction= shift == -1 and 'sinistra' or 'destra'
avail_directions.append((0, -1, 'su')) if not resource: avail_directions.append((shift, 0, direction))
if coord_y < self.world_height -1 and not self.get_map_matrix()[coord_x][coord_y + 1]: for shift in [-1, 1]:
avail_directions.append((0, 1, 'giu\'')) y= coord_y + shift
if y < 0 or y > self.world_height -1: continue
resource= self.get_map_matrix()[y][coord_x]
direction= shift == -1 and 'su' or 'giu\''
if not resource: avail_directions.append((0, shift, direction))
return avail_directions return avail_directions
def check_near_players(self, Player): def check_near_players(self, Player):