-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_check_for_win.m
48 lines (40 loc) · 1.74 KB
/
test_check_for_win.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
while true
rows = randi(10);
columns = randi(10);
how_many_to_connect = randi(min(rows,columns));
direction = randi(4);
fprintf ("%d %d %d %d\n",rows, columns, how_many_to_connect, direction);
grid = zeros(rows, columns);
if direction == 1 % vertical
start_row = randi(rows-how_many_to_connect+1);
stop_row = start_row+how_many_to_connect-1;
column = randi(columns);
grid(start_row:stop_row,column)=1;
column_just_played = column;
elseif direction == 2 % horizontal
start_column = randi(columns-how_many_to_connect+1);
stop_column = start_column+how_many_to_connect-1;
row = randi(rows);
grid(row,start_column:stop_column)=1;
column_just_played = randi([start_column,stop_column]);
elseif direction == 3 % backslash
start_row = randi(rows-how_many_to_connect+1);
stop_row = start_row+how_many_to_connect-1;
start_column = randi(columns-how_many_to_connect+1);
stop_column = start_column+how_many_to_connect-1;
grid(start_row:stop_row,start_column:stop_column)=eye(how_many_to_connect);
column_just_played = randi([start_column,stop_column]);
else % forwardslash
start_row = randi(rows-how_many_to_connect+1);
stop_row = start_row+how_many_to_connect-1;
start_column = randi(columns-how_many_to_connect+1);
stop_column = start_column+how_many_to_connect-1;
grid(start_row:stop_row,start_column:stop_column)=fliplr(eye(how_many_to_connect));
column_just_played = randi([start_column,stop_column]);
end
if ~check_for_win(grid,column_just_played,how_many_to_connect)
grid
column_just_played
error('Broken');
end
end