program osm_dam;                              {$U+,A-}
type pole=array[1..20,1..20] of byte;
var sach:pole;
    uloz:array[1..100] of pole;
 i,j,k,q:byte;
      tx:string[80];
     tx2:string[3];
  hotovo:boolean;
  cisdam:byte;
      fv:text;
procedure pis_sach;
var i,j:byte;
begin
gotoxy(1,10);for i:=1 to 8 do begin for j:=1 to 8 do write(sach[i,j],' ');
                                    writeln
                                    end;
writeln('           ',cisdam)
end;
procedure odtrid(ra,sl:byte);
var i:byte;
begin
for i:=1 to 8 do begin
  sach[i,sl]:=sach[i,sl]-1;
  sach[ra,i]:=sach[ra,i]-1;
  if ((i+sl-ra>0) and (i+sl-ra<9)) then sach[i,i+sl-ra]:=sach[i,i+sl-ra]-1;
  if ((ra+sl-i>0) and (ra+sl-i<9)) then sach[i,ra+sl-i]:=sach[i,ra+sl-i]-1
  end;
sach[ra,sl]:=0;
end;
procedure zatrid(ra,sl:byte);
var i:byte;
begin
for i:=1 to 8 do begin
  sach[i,sl]:=sach[i,sl]+1;
  sach[ra,i]:=sach[ra,i]+1;
  if ((i+sl-ra>0) and (i+sl-ra<9)) then sach[i,i+sl-ra]:=sach[i,i+sl-ra]+1;
  if ((ra+sl-i>0) and (ra+sl-i<9)) then sach[i,ra+sl-i]:=sach[i,ra+sl-i]+1
  end;
sach[ra,sl]:=5;
end;

procedure dalsi_dama;
var i,j:byte;
begin
if cisdam=9 then begin uloz[q]:=sach;q:=q+1 end;
i:=cisdam;
for j:=1 to 8 do if not(hotovo) then if sach[i,j]=0 then begin
  zatrid(i,j);cisdam:=cisdam+1;
  {pis_sach;}if cisdam<6 then begin
    gotoxy(5,10+cisdam);write(i,'  ',j,'  ',8*i-8+j);
    gotoxy(5,20);write('Moznosti : ',q)
    end;
  dalsi_dama;
  cisdam:=cisdam-1;
  if not(hotovo) then odtrid(i,j)
  end
  end;
begin
q:=1;clrscr;for i:=1 to 5 do begin gotoxy(1,10+i);write(' ',i,'.') end;
hotovo:=false;cisdam:=1;
for i:=1 to 8 do for j:=1 to 8 do sach[i,j]:=0;
dalsi_dama;writeln;writeln;
for k:=1 to q do begin
  writeln;writeln(k,'-ta moznost:');
  for i:=1 to 8 do begin for j:=1 to 8 do if uloz[k][i,j]=5 then write('D  ')
                                                            else write('+  ');
                         writeln
                         end;
{  repeat until bdos(6,$0ff)>0  }
  end;
  assign(fv,'osmdam.vys');
  rewrite(fv);
  for i:=1 to q do if i/3=trunc(i/3) then begin for k:=1 to 8 do begin
    str(i-2,tx);tx:=tx+'.  ';
    if k>1 then tx:='    ';
    if (i>9) and (k>1) then tx:=tx+' ';
    for j:=1 to 8 do if uloz[i-2][k,j]=5 then tx:=tx+'D ' else tx:=tx+'+ ';
    tx:=tx+'        ';
    if k=1 then begin str(i-1,tx2);tx:=tx+tx2+'.  ' end else tx:=tx+'    ';
    if (i>9) and (k>1) then tx:=tx+' ';
    for j:=1 to 8 do if uloz[i-1][k,j]=5 then tx:=tx+'D ' else tx:=tx+'+ ';
    tx:=tx+'        ';
    if k=1 then begin str(i,tx2);tx:=tx+tx2+'.  ' end else tx:=tx+'    ';
    if (i>9) and (k>1) then tx:=tx+' ';
    for j:=1 to 8 do if uloz[i][k,j]=5 then tx:=tx+'D ' else tx:=tx+'+ ';
    writeln(fv,tx)
    end;
                                                tx:='';writeln(fv,tx)
                                                end;
  close(fv);
end.
