forked from Cryz/battle_royale_sim
debug.py now has a list of 2 actions, attack and move, and every player get a random action from this list
This commit is contained in:
40
debug.py
40
debug.py
@@ -36,6 +36,33 @@ def _end_game_debug(alive_players, day):
|
|||||||
print(msg)
|
print(msg)
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
|
def _random_action(Arena, Player_one):
|
||||||
|
_RANDOM_ACTIONS= {
|
||||||
|
1: 'attack',
|
||||||
|
2: 'move',
|
||||||
|
}
|
||||||
|
action= _rand.randint(1, len(_RANDOM_ACTIONS))
|
||||||
|
msg= ''
|
||||||
|
if action == 1:
|
||||||
|
# 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]
|
||||||
|
_dmg, msg= Player_one.attack(Player_two)
|
||||||
|
elif action == 2:
|
||||||
|
Map= Arena.get_map()
|
||||||
|
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)
|
||||||
|
x, y, direction= available_movements[0]
|
||||||
|
Player_one.move(x, y)
|
||||||
|
Map.init_map_matrix()
|
||||||
|
print(Map.get_renderized_map())
|
||||||
|
msg= f'{Player_one.get_name()} Si muove a: {direction}'
|
||||||
|
|
||||||
|
return msg
|
||||||
|
|
||||||
def play_one_day_debug(Arena):
|
def play_one_day_debug(Arena):
|
||||||
if not Arena.get_players(): return
|
if not Arena.get_players(): return
|
||||||
print(f'Giorno #{Arena.day}')
|
print(f'Giorno #{Arena.day}')
|
||||||
@@ -46,12 +73,13 @@ def play_one_day_debug(Arena):
|
|||||||
|
|
||||||
daily_events= []
|
daily_events= []
|
||||||
_rand.shuffle(alive_players)
|
_rand.shuffle(alive_players)
|
||||||
for p_one in alive_players:
|
for Player_one in alive_players:
|
||||||
if not p_one.is_alive(): continue # he could be dead during this day cycle
|
if not Player_one.is_alive(): continue # he could be dead during this day cycle
|
||||||
p_two= _rand.sample(Arena.get_alive_players(), 1)[0]
|
msg= _random_action(Arena, Player_one)
|
||||||
while p_one.get_id() == p_two.get_id():
|
#p_two= _rand.sample(Arena.get_alive_players(), 1)[0]
|
||||||
p_two= _rand.sample(Arena.get_alive_players(), 1)[0]
|
#while Player_one.get_id() == p_two.get_id():
|
||||||
_dmg, msg= p_one.attack(p_two)
|
#p_two= _rand.sample(Arena.get_alive_players(), 1)[0]
|
||||||
|
#_dmg, msg= Player_one.attack(p_two)
|
||||||
daily_events.append(msg)
|
daily_events.append(msg)
|
||||||
|
|
||||||
Arena.next_day()
|
Arena.next_day()
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ class BrSimMap():
|
|||||||
# 📦 this is an item (weapon or another item)
|
# 📦 this is an item (weapon or another item)
|
||||||
# 💀 this is icon when the player is dead
|
# 💀 this is icon when the player is dead
|
||||||
# ⛰️ this is icon for the mountain (We can prevent players from passing through the mountains and thus use them for map boundaries.)
|
# ⛰️ this is icon for the mountain (We can prevent players from passing through the mountains and thus use them for map boundaries.)
|
||||||
|
self.game_map= []
|
||||||
|
|
||||||
width= []
|
width= []
|
||||||
#mon = []
|
#mon = []
|
||||||
@@ -88,6 +89,19 @@ class BrSimMap():
|
|||||||
|
|
||||||
def get_map_matrix(self):
|
def get_map_matrix(self):
|
||||||
return self.game_map
|
return self.game_map
|
||||||
|
|
||||||
|
def get_player_available_directions(self, Player):
|
||||||
|
coord_x, coord_y= Player.get_player_coordinates()
|
||||||
|
avail_directions= []
|
||||||
|
if self.get_map_matrix()[coord_x - 1][coord_y] not in [self.mountain_sym]:
|
||||||
|
avail_directions.append((-1, 0, 'left'))
|
||||||
|
if self.get_map_matrix()[coord_x + 1][coord_y] not in [self.mountain_sym]:
|
||||||
|
avail_directions.append((1, 0, 'right'))
|
||||||
|
if self.get_map_matrix()[coord_x][coord_y - 1] not in [self.mountain_sym]:
|
||||||
|
avail_directions.append((0, -1, 'up'))
|
||||||
|
if self.get_map_matrix()[coord_x][coord_y + 1] not in [self.mountain_sym]:
|
||||||
|
avail_directions.append((0, 1, 'bottom'))
|
||||||
|
return avail_directions
|
||||||
|
|
||||||
def get_renderized_map(self):
|
def get_renderized_map(self):
|
||||||
res= ''
|
res= ''
|
||||||
|
|||||||
@@ -178,15 +178,15 @@ class BrSimPlayer():
|
|||||||
return False
|
return False
|
||||||
self.inventory.append(item)
|
self.inventory.append(item)
|
||||||
|
|
||||||
def _move(self, delta_x, delta_y):
|
def move(self, delta_x, delta_y):
|
||||||
# XXX maps limits:
|
# XXX maps limits:
|
||||||
# probably this isn't player's business
|
# probably this isn't player's business
|
||||||
# game orchestror should manage it
|
# game orchestror should manage it
|
||||||
# to avoid that the player can go out from the map
|
# to avoid that the player can go out from the map
|
||||||
# or can reach unaccessible points
|
# or can reach unaccessible points
|
||||||
# also because the player doens't know the Map (entities/gamemap.py)
|
# also because the player doens't know the Map (entities/gamemap.py)
|
||||||
self.coord_x += x
|
self.coord_x += delta_x
|
||||||
self.coord_y += y
|
self.coord_y += delta_y
|
||||||
|
|
||||||
def move_right(self):
|
def move_right(self):
|
||||||
self._move(1, 0)
|
self._move(1, 0)
|
||||||
@@ -195,10 +195,10 @@ class BrSimPlayer():
|
|||||||
self._move(-1, 0)
|
self._move(-1, 0)
|
||||||
|
|
||||||
def move_top(self):
|
def move_top(self):
|
||||||
self._move(0, 1)
|
self._move(0, -1)
|
||||||
|
|
||||||
def move_bottom(self):
|
def move_bottom(self):
|
||||||
self._move(0, -1)
|
self._move(0, 1)
|
||||||
|
|
||||||
def escape(self):
|
def escape(self):
|
||||||
# TODO It can run away from the fighting
|
# TODO It can run away from the fighting
|
||||||
|
|||||||
Reference in New Issue
Block a user