-
Notifications
You must be signed in to change notification settings - Fork 0
/
rotationmouseclick.m
87 lines (83 loc) · 2.53 KB
/
rotationmouseclick.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
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
function r=rotationmouseclick(Board)
% This function converts the coordinates of the mouse clicks of the user
% for rotation into the (i,j) entries of the 9x9 Board matrix
% Format of Call: rotationmouseclick(Board)
% Returns r
% MH1401 ALGORITHMS & COMPUTING I Project
% ginput is the built in function to capture coordinates of the figure from
% mouse clicks by the user.
% Here, ginput(1) means it only allows user to capture one click. (Player
% only can rotate once).
try
[i,j]=ginput(1); % Uses ginput built in function to get coordinates
catch
return;
end
s=ceil(i/504); % Since each empty tile image is of 504x504, we take the ceiling of the coordinates/504 which will be the column of the matrix.
t=ceil(j/504); % Since each empty tile image is of 504x504, we take the ceiling of the coordinates/504 which will be the row of the matrix.
[a,b]=size(Board); % Store the size of the Board into variables
if a==6 % If Board is 6x6, then it executes an if else for 6x6's 8 Board rotations.
% The if else below takes the s and t coordinates of ginput and returns
% the corresponding rotation ID.
if s==5 && t==1
r=1;
elseif s==8 && t==4
r=2;
elseif s==8 && t==5
r=3;
elseif s==5 && t==8
r=4;
elseif s==4 && t==8
r=5;
elseif s==1 && t==5
r=6;
elseif s==1 && t==4
r=7;
elseif s==4 && t==1
r=8;
else % If r is none of the above, it recursives ginput until a valid input is captured.
r=rotationmouseclick(Board);
end
elseif b==9 % If Board is 9x9, then it executes an if else for 9x9's 18 Board rotations
% The if else below takes the s and t coordinates of ginput and returns
% the corresponding rotation ID.
if s==5 && t==1
r=1;
elseif s==7 && t==1
r=2;
elseif s==1 && t==6
r=3;
elseif s==11 && t==6
r=4;
elseif s==1 && t==7
r=5;
elseif s==1 && t==5
r=6;
elseif s==1 && t==4
r=7;
elseif s==4 && t==1
r=8;
elseif s==8 && t==1
r=9;
elseif s==11 && t==4
r=10;
elseif s==11 && t==5
r=11;
elseif s==11 && t==7
r=12;
elseif s==11 && t==8
r=13;
elseif s==8 && t==11
r=14;
elseif s==7 && t==11
r=15;
elseif s==5 && t==11
r=16;
elseif s==4 && t==11
r=17;
elseif s==1 && t==8
r=18;
else % If r is none of the above, it recursives ginput until a valid input is captured.
r=rotationmouseclick(Board);
end
end