-
Notifications
You must be signed in to change notification settings - Fork 0
/
move.m
35 lines (34 loc) · 777 Bytes
/
move.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
function [ board, lastMove] = move( board, cap, lastMove, isHuman )
if lastMove==0
if isHuman
newSquare=input('Which larger square?');
else
newSquare=ceil(9*rand());
end
else
newSquare=mod(lastMove-1,9)+1;
end
if cap(newSquare)~=0
if isHuman
newSquare=input('Which larger square?');
else
newSquare=ceil(9*rand());
while cap(newSquare)~=0
newSquare=ceil(9*rand());
end
end
end
if isHuman
move=input('Which square?');
while board((newSquare-1)*9+move)~=0
move=input('Invald move. Which square?');
end
else
move=ceil(9*rand());
while board((newSquare-1)*9+move)~=0
move=ceil(9*rand());
end
end
board((newSquare-1)*9+move)=1;
lastMove=move;
end