49 lines
1.8 KiB
Text
49 lines
1.8 KiB
Text
(subscriptrange, stringrange, stringsize):
|
|
flip: procedure options (main);
|
|
declare n fixed binary;
|
|
|
|
put skip list ('This is the bit-flipping game. What size of board do you want?');
|
|
get list (n);
|
|
put skip list
|
|
('Your task is to change your board so as match the board on the right (the objective)');
|
|
|
|
begin;
|
|
declare initial(n,n) bit (1), objective(n,n) bit (1);
|
|
declare (i, j, k, move) fixed binary;
|
|
declare ch character(1);
|
|
declare alphabet character (26) initial ('abcdefghijklmnopqrstuvwxyz');
|
|
|
|
on subrg
|
|
begin; put skip list ('Your row or column ' || trim(ch) || ' is out of range'); stop; end;
|
|
|
|
initial, objective = iand(random()*99, 1) = 1;
|
|
|
|
/* Set up the objective array: */
|
|
do i = 1 to n-1;
|
|
j = random()*n+1; objective(j,*) = ^objective(j,*);
|
|
j = random()*n+1; objective(*,j) = ^objective(*,j);
|
|
end;
|
|
|
|
do move = 0 by 1;
|
|
put skip edit ( center('You', n*3), center('The objective', 3*n+4) ) (x(3), a);
|
|
put skip edit ( (substr(alphabet, i, 1) do i = 1 to n) ) (x(5), (n) a(3));
|
|
put edit ( (substr(alphabet, i, 1) do i = 1 to n) ) (x(3), (n) a(3));
|
|
do i = 1 to n;
|
|
put skip edit (i, initial(i,*), objective(i,*)) ((n+1) f(3), x(3), (n) F(3));
|
|
end;
|
|
|
|
if all(initial = objective) then leave;
|
|
|
|
put skip(2) list
|
|
('Please type a row number or column letter whose bits you want to flip: ');
|
|
get edit (ch) (L); put edit (ch) (a);
|
|
k = index(alphabet, ch);
|
|
if k > 0 then
|
|
initial(*, k) = ^initial(*,k); /* Flip column k */
|
|
else
|
|
initial(ch,*) = ^initial(ch,*); /* Flip row ch */
|
|
end;
|
|
put skip(2) list ('Congratulations. You solved it in ' || trim(move) || ' moves.');
|
|
end;
|
|
|
|
end flip;
|