-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparseBoard.m
More file actions
55 lines (52 loc) · 1.93 KB
/
parseBoard.m
File metadata and controls
55 lines (52 loc) · 1.93 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
function board = parseBoard(screen, horLines, vertLines, board)
% board values
% -2 - guessed at on previous turn, treat as water
% -1 - unrevealed
% 0 - nothing
% 1 - 1 adjacent
% 2 - 2 adjacent
% 3 - 3 adjacent
% ...
% 9 - mine
% 10 - newly discovered mine
% 11 - safe to click
% 12 - solved number
[m, n] = size(board);
tileSize = horLines(2)-horLines(1)-1;
board(board == 11) = -1;
for i = 1:m
for j = 1:n
% tiles, once identified, don't change (unless there are
% questionmarks)
if(board(i, j) < 0)
segment = screen(horLines(i):horLines(i)+tileSize, vertLines(j):vertLines(j)+tileSize, :);
[color, peakColor] = sampleColor(segment);
% Beautiful handcrafted decision tree to classify cells based on color content
if(all(peakColor > 180))
if(color(1) > 100)
if(color(2) > 100)
board(i, j) = 0; %Gray cell
else
if(color(2) < 20 && color(3) < 20)
if(color(1) > 150)
board(i, j) = 3; %3 mines adjacent
else
board(i, j) = 5; %5 mines adjacent
end
end
end
elseif(color(2) > 80 && color(3) < 40 && color(1) < 50)
board(i, j) = 2; %2 mines adjacent
else
if(color(1) < 50 && color(2) < 20 && color(3) > 100)
board(i, j) = 4; %4 mines adjacent
elseif(color(1) < 100 && color(2) < 100 && color(3) > 150)
board(i, j) = 1; %1 mine adjacent
elseif(color(1) < 40 && color(2) > 100 && color(3) > 100)
board(i, j) = 6; %6 mines adjacent
end
end
end
end
end
end