-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_action.m
More file actions
47 lines (39 loc) · 931 Bytes
/
Copy pathfind_action.m
File metadata and controls
47 lines (39 loc) · 931 Bytes
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
36
37
38
39
40
41
42
43
44
45
46
47
function [action_arr] = find_action(curr_state)
load('cliffinit.mat');
% find possible next actions
% if next action is possible, then fill array with index
% if next aciton is impossible, then fill array with 0
action_arr = [];
% up (1)
% if state is at upper border of maze
if ( mod(curr_state, 4) == 1 )
action_arr(:,1) = 0;
% if next state is valid
else
action_arr(:,1) = curr_state-1;
end
% down (2)
% if state is at lower border of maze
if ( mod(curr_state, 4) == 0 )
action_arr(:,2) = 0;
% if next state is valid
else
action_arr(:,2) = curr_state+1;
end
% left (3)
% if state is at left border of maze
if ( curr_state <= 4 )
action_arr(:,3) = 0;
% if next state is valid
else
action_arr(:,3) = curr_state-4;
end
% right (4)
% if state is at lower border of maze
if ( curr_state > goal-4 )
action_arr(:,4) = 0;
% if next state is valid
else
action_arr(:,4) = curr_state+4;
end
end