remove obsolete functions and imports, add license
parent
470223d7de
commit
ea10aac18e
22
sim.py
22
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
|
import numpy as np
|
||||||
from enum import Enum, auto
|
from enum import Enum
|
||||||
import matplotlib.pyplot as plt
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
class Direction(Enum):
|
class Direction(Enum):
|
||||||
|
@ -103,19 +105,21 @@ class Environment:
|
||||||
return np.array(pixel_data).astype(np.uint8).swapaxes(0, 1)
|
return np.array(pixel_data).astype(np.uint8).swapaxes(0, 1)
|
||||||
|
|
||||||
def eat(self, position):
|
def eat(self, position):
|
||||||
resources = self.resource_map[tuple(position)]
|
resources = self.get_resources(position)
|
||||||
self.resource_map[tuple(position)] = 0
|
self.set_resources(position, 0)
|
||||||
return resources
|
return resources
|
||||||
|
|
||||||
def cell(self, position):
|
|
||||||
x, y = tuple(position)
|
|
||||||
return self.cells[y][x]
|
|
||||||
|
|
||||||
def has_obstacle(self, position):
|
def has_obstacle(self, position):
|
||||||
return self.obstacle_map[tuple(position)] == 1
|
return self.obstacle_map[tuple(position)] == 1
|
||||||
|
|
||||||
def has_agent(self, position):
|
def has_agent(self, position):
|
||||||
return tuple(position) in {tuple(agent.position) for agent in self.agents}
|
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):
|
def register_agent(self, agent):
|
||||||
self.agents.append(agent)
|
self.agents.append(agent)
|
||||||
|
@ -262,5 +266,3 @@ class CAMSReverseAndSidestepAgent(DirectionalAgent):
|
||||||
return [255, 0, 0]
|
return [255, 0, 0]
|
||||||
else:
|
else:
|
||||||
return Colours.UNDEFINED
|
return Colours.UNDEFINED
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue