-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfncCheckStructure.m
More file actions
115 lines (91 loc) · 3.89 KB
/
fncCheckStructure.m
File metadata and controls
115 lines (91 loc) · 3.89 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
function fncCheckStructure(M)
% Maze structure integrity check
% -------------------------------------------------------------------------
%
% Function :
% fncCheckStructure(M)
%
% Inputs :
% M - Multi layer maze structure cell array
%
% -------------------------------------------------------------------------
% Author : P.C. Luteijn
% email : p.c.luteijn@gmail.com
% Date : July 2017
% Comment : Function checks the maze structure on inconsistencies and
% issues a warning when a maze is corrupted.
% -------------------------------------------------------------------------
% Size
[nr,nc,~] = size(M);
n = 0;
for i = 1:nr
for j = 1:nc
if i == 1 && j == 1 % CTL
W02 = M(1,1,2) == M(2,1,4);
W03 = M(1,1,3) == M(1,2,1);
if not(and(W02,W03))
n = n + 1;
end
elseif i == 1 && j == nc % CTR
W01 = M(1,nc,1) == M(1,nc-1,3);
W02 = M(1,nc,2) == M(2,nc,4);
if not(and(W01,W02))
n = n + 1;
end
elseif i == nr && j == 1 % CBL
W03 = M(nr,1,3) == M(nr,2,1);
W04 = M(nr,1,4) == M(nr-1,1,2);
if not(and(W03,W04))
n = n + 1;
end
elseif i == nr && j == nc % CBR
W01 = M(nr,nc,1) == M(nr,nc-1,3);
W04 = M(nr,nc,4) == M(nr-1,nc,2);
if not(and(W01,W04))
n = n + 1;
end
elseif i == 1 && ( j > 1 && j < nc ) % TOP
W01 = M(i,j,1) == M(i,j-1,3);
W02 = M(i,j,2) == M(i+1,j,4);
W03 = M(i,j,3) == M(i,j+1,1);
if not(and(W01,and(W02,W03)))
n = n + 1;
end
elseif i == nr && ( j > 1 && j < nc ) % BOTTOM
W01 = M(i,j,1) == M(i,j-1,3);
W03 = M(i,j,3) == M(i,j+1,1);
W04 = M(i,j,4) == M(i-1,j,2);
if not(and(W01,and(W03,W04)))
n = n + 1;
end
elseif ( i > 1 && i < nr ) && j == 1 % LEFT
W02 = M(i,j,2) == M(i+1,j,4);
W03 = M(i,j,3) == M(i,j+1,1);
W04 = M(i,j,4) == M(i-1,j,2);
if not(and(W02,and(W03,W04)))
n = n + 1;
end
elseif ( i > 1 && i < nr ) && j == nc % RIGHT
W01 = M(i,j,1) == M(i,j-1,3);
W02 = M(i,j,2) == M(i+1,j,4);
W04 = M(i,j,4) == M(i-1,j,2);
if not(and(W01,and(W02,W04)))
n = n + 1;
end
else % CENTER
W01 = M(i,j,1) == M(i,j-1,3);
W02 = M(i,j,2) == M(i+1,j,4);
W03 = M(i,j,3) == M(i,j+1,1);
W04 = M(i,j,4) == M(i-1,j,2);
if not(and(and(W01,W02),and(W03,W04)))
n = n + 1;
end
end
end
end
% Isue a warning when the maze structure is corrupt
if n > 0
warning(['Corrupt maze structure! A number of %i instances' ...
' have been found where neigbouring cells do not match!'],n);
end
end