-
Notifications
You must be signed in to change notification settings - Fork 1
/
playbingo.m
33 lines (29 loc) · 1.09 KB
/
playbingo.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
function numturns=playbingo(numcards,sidelength,delta,freespace)
% plays a single game of bingo with numcards cards of size
% sidelength x sidelength, with each column i randomly choosing sidelength
% numbers between (i-1)*delta+1 and i*delta, with or without a free space in
% the middle
if ~exist('numcards','var'), numcards = 1; end
if ~exist('sidelength','var'), sidelength = []; end
if ~exist('delta','var'), delta = []; end
if ~exist('freespace','var'), freespace = []; end
[sidelength,delta,freespace] = ...
bingocarddefaults(sidelength,delta,freespace);
maxnum = sidelength*delta;
callseq = randperm(maxnum);
wins = 0;
numturns = 0;
for i = 1:numcards
cards{i} = makebingocard(sidelength,delta,freespace);
end
while(~wins)
numturns = numturns+1;
for i = 1:numcards
cards{i} = updatebingocard(cards{i},callseq(numturns));
wins = wins || checkbingocard(cards{i});
% Next line: slightly more efficient but awfully inelegant
% if(wins) break;
% I could also change the for loop to a while loop and separately
% increment i, but I also find that inelegant
end
end