From b6461cd87ce91dc496a8f41a4990257b423deca0 Mon Sep 17 00:00:00 2001
From: u229589 <christian.baumberger@sbb.ch>
Date: Tue, 5 Nov 2019 13:58:16 +0100
Subject: [PATCH] include improvements suggested by A. Egli

---
 flatland/envs/agent_utils.py | 8 +-------
 flatland/envs/rail_env.py    | 2 +-
 flatland/utils/editor.py     | 3 ++-
 3 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/flatland/envs/agent_utils.py b/flatland/envs/agent_utils.py
index bcc0fcc6..dd639997 100644
--- a/flatland/envs/agent_utils.py
+++ b/flatland/envs/agent_utils.py
@@ -63,19 +63,13 @@ class EnvAgent:
 
     def reset(self):
         self.position = None
+        # TODO: set direction to None: https://gitlab.aicrowd.com/flatland/flatland/issues/280
         self.direction = self.initial_direction
         self.status = RailAgentStatus.READY_TO_DEPART
         self.old_position = None
         self.old_direction = None
         self.moving = False
 
-    def move(self, new_pos: Tuple[int, int], new_dir: Tuple[int, int] = None):
-        self.old_position = self.position
-        self.position = new_pos
-        if new_dir is not None:
-            self.old_direction = self.direction
-            self.direction = new_dir
-
     def to_agent(self) -> Agent:
         return Agent(initial_position=self.initial_position, initial_direction=self.initial_direction,
                      direction=self.direction, target=self.target, moving=self.moving, speed_data=self.speed_data,
diff --git a/flatland/envs/rail_env.py b/flatland/envs/rail_env.py
index f6537274..0dd58813 100644
--- a/flatland/envs/rail_env.py
+++ b/flatland/envs/rail_env.py
@@ -338,7 +338,7 @@ class RailEnv(Environment):
         if optionals and 'distance_map' in optionals:
             self.distance_map.set(optionals['distance_map'])
 
-        if regenerate_schedule or regenerate_rail or len(self.agents) == 0:
+        if regenerate_schedule or regenerate_rail or self.get_num_agents() == 0:
             agents_hints = None
             if optionals and 'agents_hints' in optionals:
                 agents_hints = optionals['agents_hints']
diff --git a/flatland/utils/editor.py b/flatland/utils/editor.py
index eadea813..2a77c960 100644
--- a/flatland/utils/editor.py
+++ b/flatland/utils/editor.py
@@ -701,7 +701,8 @@ class EditorModel(object):
             else:
                 # Move the selected agent to this cell
                 agent = self.env.agents[self.selected_agent]
-                agent.move(cell_row_col)
+                agent.position = cell_row_col
+                agent.old_position = cell_row_col
         else:
             # Yes
             # Have they clicked on the agent already selected?
-- 
GitLab