Skip to content

Commit 3018aaa

Browse files
committed
wip
1 parent 51757d9 commit 3018aaa

File tree

4 files changed

+31
-19
lines changed

4 files changed

+31
-19
lines changed

pelita/game.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -679,8 +679,8 @@ def prepare_bot_state(game_state: GameState, team_idx=None) -> TeamState | TeamI
679679
'timeout_length': game_state['timeout_length'],
680680
}
681681
return team_state_initial
682-
case "RUNNING":
683682

683+
case "RUNNING":
684684
turn = game_state['turn']
685685

686686
bot_position = game_state['bots'][turn]
@@ -728,14 +728,12 @@ def prepare_bot_state(game_state: GameState, team_idx=None) -> TeamState | TeamI
728728
'team_time': game_state['team_time'][:],
729729
'is_noisy': is_noisy,
730730
'round': game_state['round'],
731-
'turn': turn,
731+
'turn': game_state['turn'],
732732
}
733733
return bot_state
734734

735735
case "FINISHED":
736736
# Called for remote players in _exit
737-
turn = team_idx
738-
# TODO: is turn needed?
739737

740738
team_state_final: TeamStateFinished = {
741739
'bots': game_state['bots'][:],
@@ -747,10 +745,14 @@ def prepare_bot_state(game_state: GameState, team_idx=None) -> TeamState | TeamI
747745
'food': [list(team_food) for team_food in game_state['food']],
748746
'team_time': game_state['team_time'][:],
749747
'round': game_state['round'],
750-
'turn': turn,
748+
'turn': game_state['turn'],
749+
'whowins': game_state['whowins']
751750
}
752751
return team_state_final
753752

753+
case "FAILURE":
754+
raise PelitaIllegalGameState(game_state)
755+
754756
raise PelitaIllegalGameState("Got bad game_state in prepare_bot_state")
755757

756758

pelita/player/SmartEatingPlayer.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11

22
from pelita.game import apply_move, next_round_turn
33
from pelita.player import food_eating_player
4+
from pelita.spec import FullTeamState
45
from pelita.team import Bot, _ensure_list_tuples, make_bots
56

67
def simulate_move(bot: Bot, next_pos):
7-
game_state = bot._game_state
8+
game_state: FullTeamState = dict(bot._game_state)
89
game_state['bots'] = _ensure_list_tuples(game_state['bots'])
910
game_state['error_limit'] = 0
1011
game_state['gameover'] = False
@@ -14,7 +15,12 @@ def simulate_move(bot: Bot, next_pos):
1415
game_state['errors'] = [[], []]
1516
game_state['game_phase'] = 'RUNNING'
1617

18+
print(bot)
19+
print(game_state)
1720
game_state = apply_move(game_state, next_pos)
21+
if not game_state['game_phase'] == 'RUNNING':
22+
return None
23+
1824
game_state.update(next_round_turn(game_state))
1925

2026

@@ -47,8 +53,8 @@ def simulate_move(bot: Bot, next_pos):
4753

4854

4955
def smart_eating_player(bot, state):
50-
51-
print(simulate_move(bot, next_pos=bot.position))
56+
for pos in bot.legal_positions:
57+
print(simulate_move(bot, next_pos=pos))
5258

5359
# food eating player but won’t do kamikaze (although a sufficiently smart
5460
# enemy will be able to kill the bot in its next turn as it doesn’t flee)

pelita/spec.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,5 @@ class TeamStateFinished(TypedDict):
8484
round: int|None
8585
turn: int
8686

87+
class FullTeamState(TeamInitial, TeamState):
88+
pass

pelita/team.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def __init__(self, team_move: typing.Callable[[typing.Any, typing.Any], typing.T
168168
self._bot_track = [[], []]
169169

170170

171-
def set_initial(self, team_id, game_state):
171+
def set_initial(self, team_id, initial_state):
172172
""" Sets the bot indices for the team and returns the team name.
173173
Currently, we do not call _set_initial on the user side.
174174
@@ -182,24 +182,26 @@ def set_initial(self, team_id, game_state):
182182
# Reset the team state
183183
self._state.clear()
184184

185-
self._game_state = {}
186-
self._game_state.update(game_state)
185+
self._team_id = team_id
186+
187+
self._initial_state = {}
188+
self._initial_state.update(initial_state)
187189

188190
# Initialize the random number generator
189191
# with the seed that we received from game
190-
self._rng = Random(game_state['seed'])
192+
self._rng = Random(initial_state['seed'])
191193

192194
# Reset the bot tracks
193195
self._bot_track = [[], []]
194196

195197
# Store the walls, which are only transmitted once
196-
self._walls = _ensure_tuple_tuples(game_state['walls'])
198+
self._walls = _ensure_tuple_tuples(initial_state['walls'])
197199

198200
# Store the shape, which is only transmitted once
199-
self._shape = tuple(game_state['shape'])
201+
self._shape = tuple(initial_state['shape'])
200202

201-
self._team_names = tuple(game_state['team_names'])
202-
self._max_rounds = game_state['max_rounds']
203+
self._team_names = tuple(initial_state['team_names'])
204+
self._max_rounds = initial_state['max_rounds']
203205

204206
# Cache the initial positions so that we don’t have to calculate them at each step
205207
self._initial_positions = layout.initial_positions(self._walls, self._shape)
@@ -253,8 +255,8 @@ def get_move(self, game_state):
253255
rng=self._rng,
254256
graph=self._graph)
255257

256-
self._game_state.update(game_state)
257-
me._game_state = self._game_state
258+
me._game_state = dict(game_state)
259+
me._game_state.update(self._initial_state)
258260
team = me._team
259261

260262
for idx, mybot in enumerate(team):
@@ -396,7 +398,7 @@ def set_initial(self, team_id, game_state):
396398
self.request_timeout = timeout_length
397399

398400
msg_id = self.conn.send_req("set_initial", {"team_id": team_id,
399-
"game_state": game_state})
401+
"initial_state": game_state})
400402
reply = self.conn.recv_reply(msg_id, timeout_length)
401403
# reply should be None
402404

0 commit comments

Comments
 (0)