主题:迷宫源代码
program lx;
const
b:array[0..3] of integer = (-79, 79, 1, -1);
var
a:array[0..1816] of boolean;
i:integer;
procedure m(p:integer);
var
i, d : byte;
begin
a[p]:=true;
repeat
d:=0;
if (p>158) and not a[p-158] then inc(d, 1);
if (p<1659) and not a[p+158] then inc(d, 2);
if (p mod 79<>77) and not a[p + 2] then inc(d, 4);
if (p mod 79<>1) and not a[p - 2] then inc(d, 8);
if d <> 0 then begin
repeat
i:=random(4);
until boolean(d and(1 shl i));
a[p + b[i]] := true;
m(p + 2 * b[i]);
end;
until d = 0;
end;
begin
randomize;
fillchar(a, sizeof(a), false);
m(80);
For i:=0 to 1816 do begin
if i mod 79 = 0 then writeln;
if a[i] then write(#32) else write(#219);
end;
end.
const
b:array[0..3] of integer = (-79, 79, 1, -1);
var
a:array[0..1816] of boolean;
i:integer;
procedure m(p:integer);
var
i, d : byte;
begin
a[p]:=true;
repeat
d:=0;
if (p>158) and not a[p-158] then inc(d, 1);
if (p<1659) and not a[p+158] then inc(d, 2);
if (p mod 79<>77) and not a[p + 2] then inc(d, 4);
if (p mod 79<>1) and not a[p - 2] then inc(d, 8);
if d <> 0 then begin
repeat
i:=random(4);
until boolean(d and(1 shl i));
a[p + b[i]] := true;
m(p + 2 * b[i]);
end;
until d = 0;
end;
begin
randomize;
fillchar(a, sizeof(a), false);
m(80);
For i:=0 to 1816 do begin
if i mod 79 = 0 then writeln;
if a[i] then write(#32) else write(#219);
end;
end.