From 020288fd552d0dad5a8ee48b429e35dafbbc47c1 Mon Sep 17 00:00:00 2001 From: romue Date: Fri, 7 May 2021 14:04:59 +0200 Subject: [PATCH] fix validity check --- environments/factory/factory_cleaning.py | 1 + environments/helpers.py | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/environments/factory/factory_cleaning.py b/environments/factory/factory_cleaning.py index 8b35167..158595d 100644 --- a/environments/factory/factory_cleaning.py +++ b/environments/factory/factory_cleaning.py @@ -32,6 +32,7 @@ class Factory(object): # level, agent 1,..., agent n, for i, a in enumerate(actions): old_pos, new_pos, valid = h.check_agent_move(state=self.state, dim=i+1, action=a) + print(old_pos, new_pos, valid) if __name__ == '__main__': diff --git a/environments/helpers.py b/environments/helpers.py index 87abc56..bbb839a 100644 --- a/environments/helpers.py +++ b/environments/helpers.py @@ -50,10 +50,11 @@ def check_agent_move(state, dim, action): x_new -= 1 y_new -= 1 # Check validity - valid = (x_new < 0 or y_new < 0 - or x_new >= agent_slice.shape[0] - or y_new >= agent_slice.shape[0] - ) + valid = not ( + x_new < 0 or y_new < 0 + or x_new >= agent_slice.shape[0] + or y_new >= agent_slice.shape[0] + ) # if agent tried to leave the grid return (x, y), (x_new, y_new), valid