From f60a9ca9e734b02388bb235f28b4a3f450976dfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Killian=20Mah=C3=A9?= Date: Fri, 1 Oct 2021 23:14:13 -0400 Subject: [PATCH] Update main code --- .idea/agent-aspirateur.iml | 2 +- vacuum-agent/__main__.py | 15 +++++++++------ vacuum-agent/environment.py | 1 - 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.idea/agent-aspirateur.iml b/.idea/agent-aspirateur.iml index c4b5840..c025632 100644 --- a/.idea/agent-aspirateur.iml +++ b/.idea/agent-aspirateur.iml @@ -4,7 +4,7 @@ - + diff --git a/vacuum-agent/__main__.py b/vacuum-agent/__main__.py index 99f0c2b..55358f4 100644 --- a/vacuum-agent/__main__.py +++ b/vacuum-agent/__main__.py @@ -30,21 +30,24 @@ def __init__(self, agent, environment): def run(self): stored_state = self.environment.map() stored_sequence = None - action_id = 0 percept_timer = 1 + while self.agent.alive: + percept_timer -= 1 current_state = self.environment.map() + if percept_timer <= 0 and current_state[1::] != stored_state[1::] and len(current_state) > 1: stored_state = current_state stored_sequence = self.agent(self.environment.percept()) - action_id = 0 - if stored_sequence and action_id < len(stored_sequence): - self.environment.execute_action(stored_sequence[action_id], True) - action_id += 1 + + if stored_sequence: + self.environment.execute_action(stored_sequence.pop(0), True) + if percept_timer <= 0: percept_timer = 5 - sleep(0.05) + + sleep(0.2) def convert_position(position: Position): diff --git a/vacuum-agent/environment.py b/vacuum-agent/environment.py index fcbcb21..e601654 100644 --- a/vacuum-agent/environment.py +++ b/vacuum-agent/environment.py @@ -259,7 +259,6 @@ def __init__(self): Thing.__init__(self) SimpleProblemSolvingAgentProgram.__init__(self) self.alive = True - self.performance = 0 def update_state(self, state: State, percept) -> State: """