-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecker.m
64 lines (58 loc) · 2.12 KB
/
checker.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
cb=ChessBoard;
global WhitePawn WhiteRook WhiteKnight WhiteBishop WhiteQueen WhiteKing BlackPawn BlackRook BlackKnight BlackBishop BlackQueen BlackKing;
board=cb.Board;
%create a function to check if the king is in check. if yes, there are only
%a max of 8 other spots that the king can move. this function needs to be
%called for the whole game to check each spot after every move to see if
% the king is in check
%set is_checked equal to false because the king is not in check right now,
%but then create a loop for if is_checked is true.
%set losses and wins equal to 0
% the next part will check for if the black king piece is missing (equal to 0)
% because when the king is in check it will just disappear. then, giving
% options for what the player wants to do next
win = 0;
loss = 0;
if isempty(cb.pquery(BlackKing)) == 0
msgbox('\nYou lose!')
loss=loss+1;
msgbox('Do you want to a)play again, b)see stats, c) reset stats or d)quit?')
choice= input('a,b,c,d-','s');
switch choice
case 'a'
%reset the chessboard
cb=ChessBoard;
case 'b'
msgbox('Wins-%d\n',win,'Losses-%d\n,',loss)
pause(5)
close(msgbox)
case 'c'
win=0;
loss=0;
case 'd'
msgbox('Thanks for playing!')
pause(5)
close(msgbox)
end
elseif isempty(cb.pquery(WhiteKing))
msgbox('\nYou win!')
win=win+1;
msgbox('Do you want to a)play again, b)see stats, c) reset stats or d)quit?')
choice= input('a,b,c,d-','s');
switch choice
case 'a'
%reset the chessboard
cb=ChessBoard;
case 'b'
msgbox('Wins-%d\n',win,'Losses-%d\n,',loss)
pause(5)
close(msgbox)
case 'c'
win=0;
loss=0;
case 'd'
msgbox('Thanks for playing!')
pause(5)
close(msgbox)
end
end