-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandleConflict.m
47 lines (40 loc) · 1.32 KB
/
handleConflict.m
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 [ output_args ] = handleConflict( src,event,h,row_i,col_j )
%% Read my Sudokugui
sudokugui = get(h,'UserData');
for ii = 1:9
for jj= 1:9
string_ij = get(sudokugui.X(ii,jj),'string');
if(isempty(string_ij))
A(ii,jj) = 0;
else
A(ii,jj) = str2double(string_ij);
end
end
end
%% handle any sort of invalid cells
for ii = 1:9
for jj = 1:9
if(A(ii,jj)>9 || A(ii,jj)<0 || isnan(A(ii,jj)))
set(sudokugui.status,'string','Invalid entry',...
'foregroundcolor',[0.69,0,0.125],...
'fontsize',14);
set(sudokugui.X(ii,jj),'backgroundcolor','r');
return
end
end
end
%% Handle any type of conflics
for ii = 1:9
for jj = 1:9
if (A(ii,jj)~=0)
if ConflictAdvanceTest(A,row_i,col_j)
set(sudokugui.status,'string','Conflicts',...
'foregroundcolor',[0.69,0,0.125],...
'fontsize',14);
set(sudokugui.X(ii,jj),'backgroundcolor','r');
return
end
end
end
end
end