{ Damenproblem im Schach                  }
{ Autor: Dipl.-Ing. Thomas Speiser        }
{ Source from: http://Codes.TurboTools.de }

program Dame;
uses Crt;

const n = 8;
var Field: array[1..n,1..n] of 0..1;

procedure Init_Field;
var x,y: integer;

begin
for x:=1 to n do
 for y:=1 to n do
 begin
  Field[x,y]:=0;
  gotoxy(x,y);write(Field[x,y]);
 end;
end;

procedure Show_Stones;
var x,y: integer;

begin
for x:=1 to n do
 for y:=1 to n do
 begin
  gotoxy(x,y);
  if Field[x,y] = 1 then
  write(Field[x,y]);
 end;
end;

function Check_it(x,y: integer): boolean;
var a,b: integer;
begin
Check_it:=True;

{ Test Waagerecht }
for a:=x to n do
 if Field[a,y] = 1 then Check_it:=False;

for a:=1 to x-1 do
 if Field[a,y] = 1 then Check_it:=False;

{ Test Senkrecht }
for a:=y to n do
 if Field[a,y] = 1 then Check_it:=False;

for a:=1 to y-1 do
 if Field[x,a] = 1 then Check_it:=False;

{ Test Diagonal, mit Trick :-) }
for a:=1 to n do
 for b:=1 to n do
  if (x+y = a+b) or (y-x = b-a) then
    if Field[a,b] = 1 then Check_it:=False;
end;

procedure Set_Stones;
var x,y: integer;
begin
Randomize;
Field[1,random(n)+1]:=1;
for x:=2 to n do
 for y:=1 to n do
 begin
  if Check_it(x,y) then
  Field[x,y]:=1;
 end;
end;

begin
 ClrScr;
 Init_Field;
 Set_Stones;
 TextColor(red);
 Show_Stones;
 readLN;
end.