uses graph,crt; type figTips = set of 'A'..'Z'; laukums=array[-1..10,-1..10]of integer; const figuras: figTips=['B','L','T','K','D','Z']; var xb,xm,yb,ym,i,j:integer; ii,jj:integer; a:laukums; numuri:array['B'..'Z']of integer; function sti(x:integer):string; var syss:string; begin str(x,syss); sti:=syss; end; function absX(x:integer):integer; begin if x<0 then absX:=-x else absX:=x; end; {---------------------------------------------} function peska_white_sit(lauk:laukums; x,y:integer):boolean; begin peska_white_sit:=false; y:=y+1; x:=x-1; if lauk[x,y]=22 then peska_white_sit:=true; x:=x+2; if lauk[x,y]=22 then peska_white_sit:=true; end; function peska_black_sit(lauk:laukums; x,y:integer):boolean; begin peska_black_sit:=false; y:=y-1; x:=x-1; if lauk[x,y]=11 then peska_black_sit:=true; x:=x+2; if lauk[x,y]=11 then peska_black_sit:=true; end; function zirgs_white_sit(lauk:laukums; x,y:integer):boolean; var x1,y1,z:integer; begin z:=22; zirgs_white_sit:=false; y1:=y+2; x1:=x+1; if lauk[x1,y1]=z then zirgs_white_sit:=true; x1:=x-1; if lauk[x1,y1]=z then zirgs_white_sit:=true; y1:=y+1; x1:=x+2; if lauk[x1,y1]=z then zirgs_white_sit:=true; x1:=x-2; if lauk[x1,y1]=z then zirgs_white_sit:=true; y1:=y-2; x1:=x+1; if lauk[x1,y1]=z then zirgs_white_sit:=true; x1:=x-1; if lauk[x1,y1]=z then zirgs_white_sit:=true; y1:=y-1; x1:=x+2; if lauk[x1,y1]=z then zirgs_white_sit:=true; x1:=x-2; if lauk[x1,y1]=z then zirgs_white_sit:=true; end; function zirgs_black_sit(lauk:laukums; x,y:integer):boolean; var x1,y1,z:integer; begin z:=11; zirgs_black_sit:=false; y1:=y+2; x1:=x+1; if lauk[x1,y1]=z then zirgs_black_sit:=true; x1:=x-1; if lauk[x1,y1]=z then zirgs_black_sit:=true; y1:=y+1; x1:=x+2; if lauk[x1,y1]=z then zirgs_black_sit:=true; x1:=x-2; if lauk[x1,y1]=z then zirgs_black_sit:=true; y1:=y-2; x1:=x+1; if lauk[x1,y1]=z then zirgs_black_sit:=true; x1:=x-1; if lauk[x1,y1]=z then zirgs_black_sit:=true; y1:=y-1; x1:=x+2; if lauk[x1,y1]=z then zirgs_black_sit:=true; x1:=x-2; if lauk[x1,y1]=z then zirgs_black_sit:=true; end; function laidnis_sit(lauk:laukums; x,y,xk,yk:integer):boolean; var dif,dif1,i,j:integer; sit:boolean; begin laidnis_sit:=false; sit:=false; dif:=absX(x-xk); dif1:=absX(y-yk); if dif=dif1 then begin laidnis_sit:=true; sit:=true; if (xk>x)and(yk>y) then while ((xk-1>x) and sit) do begin x:=x+1; y:=y+1; if lauk[x,y]<>0 then sit:=false; end else if (xk>x)and(ykx) and sit) do begin x:=x+1; y:=y-1; if lauk[x,y]<>0 then sit:=false; end else if (xk0 then sit:=false; end else if (xky) then while ((xk+10 then sit:=false; end; end; laidnis_sit:=sit; end; function tornis_sit(lauk:laukums; x,y,xk,yk:integer):boolean; var sit:boolean; begin tornis_sit:=false; sit:=false; if (x=xk)or(y=yk) then begin tornis_sit:=true; sit:=true; if yk>y then while ((yk-1>y) and sit) do begin y:=y+1; if lauk[x,y]<>0 then sit:=false; end; if xk>x then while ((xk-1>x) and sit) do begin x:=x+1; if lauk[x,y]<>0 then sit:=false; end; if yk0 then sit:=false; end; if xk0 then sit:=false; end; end; tornis_sit:=sit; end; function dama_sit(lauk:laukums; x,y,xk,yk:integer):boolean; begin if laidnis_sit(lauk,x,y,xk,yk) or tornis_sit(lauk,x,y,xk,yk) then dama_sit:=true else dama_sit:=false; end; function lauka_parbaude(lauk:laukums; x,y,xb,yb,xm,ym:integer):boolean; begin lauka_parbaude:=false; if lauk[x,y]=1 then if peska_white_sit(lauk,x,y) then lauka_parbaude:=true; if lauk[x,y]=2 then if peska_black_sit(lauk,x,y) then lauka_parbaude:=true; if lauk[x,y]=3 then if zirgs_white_sit(lauk,x,y) then lauka_parbaude:=true; if lauk[x,y]=6 then if zirgs_black_sit(lauk,x,y) then lauka_parbaude:=true; if lauk[x,y]=5 then if laidnis_sit(lauk,x,y,xm,ym) then lauka_parbaude:=true; if lauk[x,y]=10 then if laidnis_sit(lauk,x,y,xb,yb) then lauka_parbaude:=true; if lauk[x,y]=7 then if tornis_sit(lauk,x,y,xm,ym) then lauka_parbaude:=true; if lauk[x,y]=14 then if tornis_sit(lauk,x,y,xb,yb) then lauka_parbaude:=true; if lauk[x,y]=9 then if dama_sit(lauk,x,y,xm,ym) then lauka_parbaude:=true; if lauk[x,y]=18 then if dama_sit(lauk,x,y,xb,yb) then lauka_parbaude:=true; end; function ir_sahs(lauk:laukums; xb,yb,xm,ym:integer):boolean; var sahs:boolean; i,j:integer; begin i:=1; j:=1; repeat j:=1; repeat sahs:=lauka_parbaude(lauk,i,j,xb,yb,xm,ym); j:=j+1; until (j>8)or(sahs); i:=i+1; until (i>8)or(sahs); ir_sahs:=sahs end; {---------------------------------------------} procedure grafika; var i,j,d,m,yoX,yoY,w:integer; x,y:integer; q:char; tabs,movement:boolean; stiga:string; begin numuri['B']:=1; numuri['Z']:=3; numuri['L']:=5; numuri['T']:=7; numuri['D']:=9; numuri['K']:=11; d:=0; m:=0; initgraph(d,m,''); rectangle(46,46,449,449); for i:=1 to 8 do for j:=1 to 8 do begin if (i+j) mod 2=0 then setfillstyle(1,7) else setfillstyle(1,8); bar(50*i,50*j,50*i+45,50*j+45); rectangle(50*i,50*j,50*i+45,50*j+45); a[i,j]:=0; end; for i:=1 to 8 do begin outtextxy(35,50*i+20,char(57-i)); outtextxy(50*i+20,455,char(64+i)); end; x:=1; y:=1; yoX:=50; yoY:=50; w:=10; tabs:=true; setfillstyle(1,8); bar(470,yoY,630,yoY+40); rectangle(470,yoY,630,yoY+40); setfillstyle(1,15);setcolor(8); bar(GetMaxX-60-yox, 10+yoy, GetMaxX-40-yox, 30+yoy); rectangle(GetMaxX-60-yox, 10+yoy, GetMaxX-40-yox, 30+yoy); setfillstyle(1,0);setcolor(7); bar(GetMaxX-30-yox, 10+yoy, GetMaxX-10-yox, 30+yoy); rectangle(GetMaxX-30-yox, 10+yoy, GetMaxX-10-yox, 30+yoy); setlinestyle(0,0,3);setcolor(2); settextJustify(righttext,centertext); setcolor(7); setfillstyle(1,8); bar(470,90+w,630,290+w); setcolor(15); setlinestyle(0,0,1); rectangle(470,90+w,630,290+w); outtextxy(620,100+w,'Bandinieks - B'); outtextxy(620,120+w,'Zirgs - Z'); outtextxy(620,140+w,'Laidnis - L'); outtextxy(620,160+w,'Tornis - T'); outtextxy(620,180+w,'Dama - D'); outtextxy(620,200+w,'Karalis - K'); outtextxy(620,220+w,'------------------'); outtextxy(620,240+w,'Mainit krasu - Tab'); outtextxy(620,260+w,'Dzest figuru - Del'); outtextxy(620,280+w,'Iziet - Esc'); line(565,176+w,569,176+w); line(509,236+w,513,236+w); line(549,236+w,553,236+w); line(549,256+w,553,256+w); line(493,256+w,497,256+w); settextJustify(righttext,centertext); settextstyle(0,0,3); xb:=9;xm:=9;yb:=17;ym:=17; settextJustify(centertext,centertext); repeat settextJustify(centertext,bottomtext); setfillstyle(1,1); setlinestyle(0,0,1); setcolor(15); settextstyle(0,0,2); bar(GetMaxX-10,GetMaxY-33,GetMaxX-170,GetMaxY-170); rectangle(GetMaxX-10,GetMaxY-33,GetMaxX-170,GetMaxY-170); if ir_sahs(a,xb,9-yb,xm,9-ym) then begin setcolor(10); setlinestyle(0,0,3); line(GetMaxX-92,GetMaxY-115,GetMaxX-95,GetMaxY-118); line(GetMaxX-92,GetMaxY-115,GetMaxX-89,GetMaxY-118); outtextxy(GetMaxX-90,GetMaxY-95,'IR SAHS') end else begin setcolor(12); setlinestyle(0,0,3); line(GetMaxX-84,GetMaxY-115,GetMaxX-87,GetMaxY-118); line(GetMaxX-84,GetMaxY-115,GetMaxX-81,GetMaxY-118); outtextxy(GetMaxX-90,GetMaxY-95, 'NAV SAHS'); end; settextstyle(0,0,3); settextJustify(centertext,centertext); setlinestyle(0,0,2);setcolor(12); rectangle(50*x-2,50*y-2,50*x+47,50*y+47); setlinestyle(0,0,3);setcolor(2); if not tabs then rectangle(GetMaxX-35-yox, 5+yoy, GetMaxX-5-yox, 35+yoy) else rectangle(GetMaxX-65-yox, 5+yoy, GetMaxX-35-yox, 35+yoy); q:=readkey; movement:=false; if q=#0 then begin q:=readkey; movement:=true; end; setlinestyle(0,0,2);setcolor(0); rectangle(50*x-2,50*y-2,50*x+47,50*y+47); setlinestyle(0,0,3);setcolor(8); rectangle(GetMaxX-35-yox, 5+yoy, GetMaxX-5-yox, 35+yoy); rectangle(GetMaxX-65-yox, 5+yoy, GetMaxX-35-yox, 35+yoy); q:=upcase(q); if movement then case ord(q) of 72: dec(y); 75: dec(x); 80: inc(y); 77: inc(x); 83: begin if a[x,9-y]=11 then begin xb:=9; yb:=17; end; if a[x,9-y]=22 then begin xm:=9; ym:=17; end; a[x,9-y]:=0; if (x+y) mod 2=0 then setfillstyle(1,7) else setfillstyle(1,8); bar(50*x+2,50*y+2,50*x+43,50*y+43); end; end else begin if q in figuras then begin if (x+y) mod 2=0 then setfillstyle(1,7) else setfillstyle(1,8); if tabs then setcolor(15) else setcolor(0); if(q<>'K')or(tabs and(xb=9)and((absX(x-xm)>1)or(absX(y-ym)>1)or((x=xm)and(y=ym))))or ((not tabs)and(xm=9)and((absX(x-xb)>1)or(absX(y-yb)>1)or((x=xb)and(y=yb)))) then begin if a[x,9-y]=11 then begin xb:=9;yb:=17;end; if a[x,9-y]=22 then begin xm:=9;ym:=17;end; bar(50*x+2,50*y+2,50*x+43,50*y+43); outtextxy(50*x+24,50*y+24,q); if q='K' then if tabs then begin xb:=x;yb:=y;end else begin xm:=x;ym:=y;end; a[x,9-y]:=numuri[q]; if not tabs then a[x,9-y]:=2*a[x,9-y]; end; end else if q=#9 then tabs:=not tabs; end; x:=(x+7) mod 8+1; y:=(y+7) mod 8+1; until q=#27; closegraph; end; begin grafika; end.