mirror of
https://github.com/illiumst/marl-factory-grid.git
synced 2025-05-23 15:26:43 +02:00
updated stuff
This commit is contained in:
parent
6eb97e20b1
commit
3c86684586
@ -31,7 +31,8 @@ class Factory(object):
|
|||||||
actions = [actions]
|
actions = [actions]
|
||||||
# level, agent 1,..., agent n,
|
# level, agent 1,..., agent n,
|
||||||
for i, a in enumerate(actions):
|
for i, a in enumerate(actions):
|
||||||
h.check_agent_move(state=self.state, dim=i+1, action=a)
|
old_pos, new_pos, valid = h.check_agent_move(state=self.state, dim=i+1, action=a)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
factory = Factory(n_agents=1)
|
factory = Factory(n_agents=1)
|
||||||
|
@ -28,6 +28,7 @@ def check_agent_move(state, dim, action):
|
|||||||
raise AssertionError('Only one agent per slice is allowed.')
|
raise AssertionError('Only one agent per slice is allowed.')
|
||||||
x, y = agent_pos[0]
|
x, y = agent_pos[0]
|
||||||
x_new, y_new = x, y
|
x_new, y_new = x, y
|
||||||
|
# Actions
|
||||||
if action == 0: # North
|
if action == 0: # North
|
||||||
x_new -= 1
|
x_new -= 1
|
||||||
elif action == 1: # East
|
elif action == 1: # East
|
||||||
@ -48,6 +49,14 @@ def check_agent_move(state, dim, action):
|
|||||||
elif action == 7: # NW
|
elif action == 7: # NW
|
||||||
x_new -= 1
|
x_new -= 1
|
||||||
y_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]
|
||||||
|
)
|
||||||
|
return (x, y), (x_new, y_new), valid
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user