-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstep.m
More file actions
40 lines (40 loc) · 1.36 KB
/
Copy pathstep.m
File metadata and controls
40 lines (40 loc) · 1.36 KB
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
function n = step(n)
% generate field
field = num2field(n);
% find options
left_options = conv2(field,[1,1,-1],'same') == 3;
right_options = conv2(field,[-1,1,1],'same') == 3;
up_options = conv2(field,[1;1;-1],'same') == 3;
down_options = conv2(field,[-1;1;1],'same') == 3;
% merge options
[left_r, left_c] = ind2sub(size(field),find(left_options));
[right_r, right_c] = ind2sub(size(field),find(right_options));
[up_r, up_c] = ind2sub(size(field),find(up_options));
[down_r, down_c] = ind2sub(size(field),find(down_options));
options = [
[left_r, left_c, 1+zeros(size(left_r))];
[right_r, right_c, 2+zeros(size(right_r))];
[up_r, up_c, 3+zeros(size(up_r))];
[down_r, down_c, 4+zeros(size(down_r))];
];
options_num = size(options,1);
n = zeros(options_num,1);
% process options
for i=1:options_num
r_selected = options(i,1);
c_selected = options(i,2);
d_selected = options(i,3);
field_option = field;
switch d_selected
case 1
field_option(r_selected,c_selected+[-1 0 1]) = [1 -1 -1];
case 2
field_option(r_selected,c_selected+[-1 0 1]) = [-1 -1 1];
case 3
field_option(r_selected+[-1 0 1],c_selected) = [1 -1 -1];
case 4
field_option(r_selected+[-1 0 1],c_selected) = [-1 -1 1];
endswitch
n(i) = field2num(field_option);
endfor
endfunction