-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathactionfunction.py
35 lines (27 loc) · 1.03 KB
/
actionfunction.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from constants import *
def perform_action(action, reachable_boxes, boxes, explored, board, agent, rewards):
# update previous agent location on board
if rewards[agent] == GOAL_REWARD:
board[agent] = GOAL
else:
board[agent] = SPACE
new_box_position = 0
agent = action[0] # return
oldbox_p = action[0]
move = action[1]
if move == UP:
new_box_position = (oldbox_p[0] - 1, oldbox_p[1])
if move == DOWN:
new_box_position = (oldbox_p[0] + 1, oldbox_p[1])
if move == LEFT:
new_box_position = (oldbox_p[0], oldbox_p[1] - 1)
if move == RIGHT:
new_box_position = (oldbox_p[0], oldbox_p[1] + 1)
boxes = [new_box_position if box == action[0] else box for box in boxes] # return
explored += reachable_boxes[agent][move] # return
board[agent] = AGENT
if rewards[new_box_position] == GOAL_REWARD:
board[new_box_position] = BOX_ON_GOAL
else:
board[new_box_position] = BOX
return agent, boxes, explored, new_box_position, board