{ Turm - Simulation                       }
{ Autor: Dipl.-Ing. Thomas Speiser        }
{ Source from: http://Codes.TurboTools.de }

program turm;
{$S-}
uses Crt;
const n = 15;
var schach: array[1..n,1..n] of 0..1;
    feld: array[1..n] of 1..n;
    ya: integer;
    x,y,i,a: integer;
    turm_anzahl: integer;

procedure schach_brett_fuellen;

procedure nicht_schlagen;
label l1;
begin
l1:
ya:=random(n)+1;
for i:=1 to a do if feld[i] = ya then goto l1;
inc(a); feld[a]:=ya;
end;

begin
a:=0;
for i:=1 to n do feld[i]:=1;
randomize;
for x:=1 to n do begin
nicht_schlagen;
for y:=1 to n do begin
if ya = y then schach[x,y]:=1 else schach[x,y]:=0;
gotoxy(x,y);write(schach[x,y]); end; end;
end;

procedure n_anzahl_ueberpruefen;
begin
for x:=1 to n do
for y:=1 to n do
if schach[x,y] = 1 then inc(turm_anzahl);
gotoxy(1,20);write('Turmanzahl: ',turm_anzahl);
end;

begin
ClrScr;
turm_anzahl:=0;
repeat
schach_brett_fuellen;
n_anzahl_ueberpruefen;
delay(1000);
until keypressed;
readLN;
end.