1
0

start implement random action

This commit is contained in:
andrea
2025-08-01 23:49:39 +02:00
parent 8ed1bd3c4f
commit eb3b7da07a
3 changed files with 45 additions and 18 deletions

View File

@@ -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)