Skip to content
Snippets Groups Projects
Commit 094502c8 authored by Fabian Heinrich's avatar Fabian Heinrich
Browse files

Fixed world border collision

parent 0d0805bd
No related branches found
No related tags found
1 merge request!38Resolve "Finalize coordinate system"
Pipeline #45034 failed
......@@ -5,5 +5,5 @@ W__________I
#__A_____A_D
C__________E
C__________G
#__________#
#___________
#P#S+#X##S+#
\ No newline at end of file
......@@ -162,6 +162,9 @@ class Environment:
self.free_positions,
) = self.parse_layout_file()
self.world_borders_x = [-0.5, self.kitchen_width - 0.5]
self.world_borders_y = [-0.5, self.kitchen_height - 0.5]
progress_counter_classes = list(
filter(
lambda cl: hasattr(cl, "progress"),
......@@ -315,14 +318,10 @@ class Environment:
free_positions.append(np.array([current_x, current_y]))
current_x += 1
# if current_x > self.kitchen_width:
# self.kitchen_width = current_x
current_y += 1
# self.kitchen_width -= 0.5
self.kitchen_width: float = len(lines[0])
self.kitchen_height = len(lines)
self.kitchen_width: float = len(lines[0]) + 2
self.kitchen_height = len(lines) + 2
self.counter_factory.post_counter_setup(counters)
return counters, designated_player_positions, free_positions
......@@ -565,9 +564,13 @@ class Environment:
Returns: True if the player touches the world bounds, False if not.
"""
collisions_lower = any((player.pos - (player.radius)) < 0)
collisions_lower = any(
(player.pos - (player.radius))
< [self.world_borders_x[0], self.world_borders_y[0]]
)
collisions_upper = any(
(player.pos + (player.radius)) > [self.kitchen_width, self.kitchen_height]
(player.pos + (player.radius))
> [self.world_borders_x[1], self.world_borders_y[1]]
)
return collisions_lower or collisions_upper
......@@ -586,21 +589,21 @@ class Environment:
counter.progress(passed_time=passed_time, now=self.env_time)
self.order_and_score.progress(passed_time=passed_time, now=self.env_time)
# def get_state(self):
# """Get the current state of the game environment. The state here is accessible by the current python objects.
#
# Returns: Dict of lists of the current relevant game objects.
#
# """
# return {
# "players": self.players,
# "counters": self.counters,
# "score": self.order_and_score.score,
# "orders": self.order_and_score.open_orders,
# "ended": self.game_ended,
# "env_time": self.env_time,
# "remaining_time": max(self.env_time_end - self.env_time, timedelta(0)),
# }
def get_state(self):
"""Get the current state of the game environment. The state here is accessible by the current python objects.
Returns: Dict of lists of the current relevant game objects.
"""
return {
"players": self.players,
"counters": self.counters,
"score": self.order_and_score.score,
"orders": self.order_and_score.open_orders,
"ended": self.game_ended,
"env_time": self.env_time,
"remaining_time": max(self.env_time_end - self.env_time, timedelta(0)),
}
def get_json_state(self, player_id: str = None):
state = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment