From ea10aac18e6c31bb8bc705f597182aafeed11dec Mon Sep 17 00:00:00 2001 From: Nekkowe! Date: Sun, 1 Oct 2023 13:01:55 +0200 Subject: [PATCH] remove obsolete functions and imports, add license --- sim.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/sim.py b/sim.py index 5d4575a..3bb8695 100644 --- a/sim.py +++ b/sim.py @@ -1,6 +1,8 @@ +# By Nekkowe 2023-10-01 +# nekkowe.com / nekkowe@gmail.com +# Released under CC-BY-NC https://creativecommons.org/licenses/by-nc/4.0/deed.en import numpy as np -from enum import Enum, auto -import matplotlib.pyplot as plt +from enum import Enum from dataclasses import dataclass class Direction(Enum): @@ -103,19 +105,21 @@ class Environment: return np.array(pixel_data).astype(np.uint8).swapaxes(0, 1) def eat(self, position): - resources = self.resource_map[tuple(position)] - self.resource_map[tuple(position)] = 0 + resources = self.get_resources(position) + self.set_resources(position, 0) return resources - def cell(self, position): - x, y = tuple(position) - return self.cells[y][x] - def has_obstacle(self, position): return self.obstacle_map[tuple(position)] == 1 def has_agent(self, position): return tuple(position) in {tuple(agent.position) for agent in self.agents} + + def get_resources(self, position): + return self.resource_map[tuple(position)] + + def set_resources(self, position, resources): + self.resource_map[tuple(position)] = 0 def register_agent(self, agent): self.agents.append(agent) @@ -262,5 +266,3 @@ class CAMSReverseAndSidestepAgent(DirectionalAgent): return [255, 0, 0] else: return Colours.UNDEFINED - -