Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 10.66 KB | None | 0 0
  1. program warcaby2222;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   windows,
  7.   SysUtils;
  8.  
  9. const
  10. n=8;
  11.  
  12. var
  13.   t: array[1..n,1..n] of integer;
  14.   w: array[1..2]of integer;
  15.   x1,x2,y1,y2,p,p1,p2,s:integer;
  16.   x3:char;
  17.  
  18.   procedure gotoxy(x,y:integer);
  19.     var
  20.       hnd: Thandle;
  21.       pos: COORD;
  22.       count: Cardinal;
  23.     begin
  24.     hnd:=getStdHandle(STD_OUTPUT_HANDLE);
  25.     pos.X:=y+1;
  26.     pos.Y:=x+1;
  27.     SetConsoleCursorPosition(hnd,pos);
  28.     end;
  29.  
  30. {procedura rysująca ramkę}
  31.   procedure rysuje_ramke(x1,y1,x2,y2:integer);
  32.   var i:integer;
  33.     begin
  34.     for i:=(x1) to (x2-1) do
  35.       begin
  36.       gotoxy(i,y1);
  37.       write('ş');
  38.       gotoxy(i,y2);
  39.       write('ş');
  40.       end;
  41.     for i:=(y1) to (y2-1) do
  42.       begin
  43.       gotoxy(x1,i);
  44.       write('Í');
  45.       gotoxy(x2,i);
  46.       write('Í');
  47.       end;
  48.     gotoxy(x1,y1);
  49.     write('É');
  50.     gotoxy(x2,y1);
  51.     write('Č');
  52.     gotoxy(x1,y2);
  53.     write('»');
  54.     gotoxy(x2,y2);
  55.     write('Ľ');  
  56.     end;
  57.  
  58. {procedura rysująca aktualny stan planszy}
  59.   procedure plansza;
  60.     var
  61.       a:char;
  62.       i,j:integer;
  63.     begin
  64.     a:='A';
  65.     for i:=1 to 8 do
  66.       begin
  67.       gotoxy(-1,i);
  68.       write(i);
  69.       gotoxy(10,i);
  70.       write(i);
  71.       gotoxy(i,-1);
  72.       write(a);      
  73.       gotoxy(i,10);
  74.       write(a);
  75.       inc(a);
  76.       end;
  77.     for i:=1 to 8 do
  78.       for j:=1 to 8 do
  79.         begin
  80.         gotoxy(i,j);
  81.         if ((i-j) mod 2 =0) then
  82.           begin
  83.           if (i<4) then
  84.             begin
  85.             write('o');
  86.             t[i,j]:=2;
  87.             end;
  88.           if (i>5) then
  89.             begin
  90.             write('x');
  91.             t[i,j]:=3;
  92.             end;
  93.           if(i>=4) and (i<=5) then
  94.             begin
  95.             write(' ');
  96.             t[i,j]:=1;
  97.             end;
  98.           end
  99.         else t[i,j]:=0; write('±');
  100.  
  101.         end;
  102.     end;
  103.  
  104. {funkcja sprawdzająca poprawnosc ruchu - analiza 0-ruch niemożliwy, 1-ruch, 2-bicie, 3-ruch damką, 4-bicie damką}
  105.   function pop3(g,x1,x2,y1,y2:integer):integer;
  106.     var
  107.       x,y,a:integer;
  108.     begin
  109.     a:=0;
  110.     x:=x2-x1;
  111.     y:=y2-y1;
  112.     if t[x1,y1]=2 then
  113.       if x=1 then pop3:=1
  114.       else
  115.        iF ((x=2) or (x=-2)) and ((t[((x1+x2)div 2),((y1+y2) div 2)]=3) or (t[(x1+x2) div 2,(y1+y2) div 2]=5)) then pop3:=2
  116.        else pop3:=0;
  117.     if t[x1,y1]=3 then
  118.       if x=-1 then pop3:=1
  119.       else
  120.        if ((x=2) or (x=-2)) and ((t[(x1+x2) div 2,(y1+y2)div 2]=2) or (t[(x1+x2)div 2,(y1+y2)div 2]=4)) then pop3:=2
  121.        else pop3:=0;
  122.     if t[x1,y1]=4 then
  123.       if x>0 then
  124.         if y>0 then
  125.           begin
  126.           x:=1;
  127.             repeat
  128.             if t[x1+x,y1+x]=1 then a:=3
  129.             else
  130.               if x=y-1 then
  131.                 if (t[x1+x,y1+x]=3) or (t[x1+x,y1+x]=5) then a:=4;
  132.               x:=x+1;
  133.             until (x=y-1) or (a=4);
  134.           end
  135.         else
  136.           begin
  137.           x:=1;
  138.             repeat
  139.             if t[x1+x,y1-x]=1 then a:=3
  140.             else
  141.               if x=-y-1 then
  142.                 if (t[x1+x,y1-x]=3) or (t[x1+x,y1-x]=5) then a:=4;
  143.               x:=x+1;
  144.             until (x=-y-1) or (a=4);
  145.           end
  146.       else
  147.         if y>0 then
  148.           begin
  149.           x:=1;
  150.             repeat
  151.             if t[x1-x,y1+x]=1 then a:=3
  152.             else
  153.               if x=y-1 then
  154.                 if (t[x1-x,y1+x]=3) or (t[x1-x,y1+x]=5) then a:=4;
  155.               x:=x+1;
  156.             until (x=y-1) or (a=4);
  157.           end
  158.     else
  159.       begin
  160.       x:=1;
  161.         repeat
  162.         if t[x1-x,y1-x]=1 then a:=3
  163.         else
  164.           if x=-y-1 then
  165.             if (t[x1-x,y1-x]=3) or (t[x1-x,y1-x]=5) then a:=4;
  166.           x:=x+1;
  167.         until (x=-y-1) or (a=4);
  168.       end ;
  169.  
  170.     if t[x1,y1]=5 then
  171.       if x>0 then
  172.         if y>0 then
  173.           begin
  174.           x:=1;
  175.             repeat
  176.             if t[x1+x,y1+x]=1 then a:=3
  177.             else
  178.               if x=y-1 then
  179.                 if (t[x1+x,y1+x]=2) or (t[x1+x,y1+x]=4) then a:=4;
  180.               x:=x+1;
  181.             until (x=y-1) or (a=4);
  182.           end
  183.         else
  184.           begin
  185.           x:=1;
  186.             repeat
  187.             if t[x1+x,y1-x]=1 then a:=3
  188.             else
  189.               if x=-y-1 then
  190.                 if (t[x1+x,y1-x]=2) or (t[x1+x,y1-x]=4) then a:=4;
  191.               x:=x+1;
  192.             until (x=-y-1) or (a=4);
  193.           end
  194.       else
  195.         if y>0 then
  196.           begin
  197.           x:=1;
  198.             repeat
  199.             if t[x1-x,y1+x]=1 then a:=3
  200.             else
  201.               if x=y-1 then
  202.                 if (t[x1-x,y1+x]=2) or (t[x1-x,y1+x]=4) then a:=4;
  203.               x:=x+1;
  204.             until (x=y-1) or (a=4);
  205.           end
  206.         else
  207.           begin
  208.           x:=1;
  209.             repeat
  210.             if t[x1-x,y1-x]=1 then a:=3
  211.             else
  212.               if x=-y-1 then
  213.                 if (t[x1-x,y1-x]=2) or (t[x1-x,y1-x]=4) then a:=4;
  214.               x:=x+1;
  215.             until (x=-y-1) or (a=4);
  216.           end ;
  217.     if a=4 then pop3:=4
  218.     else
  219.     if a=3 then pop3:=3;
  220.     end;
  221.  
  222.   procedure rysuj(x1,x2,y1,y2,g,s:integer);
  223.     var
  224.       x,y,i,j:integer;
  225.     begin
  226.     t[x2,y2]:=t[x1,y1];
  227.     gotoxy(x2,y2);
  228.     if t[x2,y2]=2 then
  229.       if (x2=8) and ((y2=2) or (y2=4) or (y2=6) or (y2=8)) then t[x2,y2]:=4
  230.       else Write('o');
  231.     if t[x2,y2]=3 then
  232.       if (x2=1) and ((y2=1) or (y2=3) or (y2=5) or (y2=7)) then t[x2,y2]:=5
  233.       else Write('x');
  234.     if t[x2,y2]=4 then Write('O');
  235.     if t[x2,y2]=5 then Write('X');
  236.     if s=2 then
  237.       begin
  238.       gotoxy((x1+x2)div 2,(y1+y2)div 2);
  239.       Write(' ');
  240.       t[(x1+x2)div 2,(y1+y2)div 2]:=1;
  241.       end;
  242.     if s=4 then
  243.       begin
  244.       x:=x2-x1;
  245.       y:=y2-y1;
  246.       if x>0 then
  247.         begin
  248.         i:=1;
  249.           if y>0 then j:=1
  250.           else j:=-1;
  251.         end
  252.       else
  253.         begin
  254.         i:=-1;
  255.           if y>0 then j:=1
  256.           else j:=-1;
  257.         end;
  258.       gotoxy(x2-i,y2-j);
  259.       writeln(' ');
  260.       t[x2-i,y2-j]:=1;
  261.       end;
  262.     gotoxy(x1,y1);
  263.     write(' ');
  264.     t[x1,y1]:=1;
  265.     end;
  266.  
  267. {funkcja czytajaca pierwsza wspolrzedna pola: char->integer}
  268.   function czyt(x3:char):integer;
  269.     begin
  270.     if (x3>='A') and (x3<='H') then
  271.       czyt:=ord(x3)-64
  272.     else
  273.       czyt:=ord(x3)-96;
  274.     end;
  275.  
  276. {funkcja sprawdzajaca poprawnosc (punkt 1) - czy istnieje takie pole na planszy,
  277. czy znajduje sie na nim twoj pionek,czy ten pionek nie jest zablokowany}
  278.     function pop1(var p,x1,y1:integer):boolean;
  279.     begin
  280.     pop1:=false;
  281.       if (((t[x1,y1]=p+1) or (t[x1,y1]=p+3))) and (x1>=1) and (x1<=8) and (y1>=1) and (y1<=8)  then
  282.         begin
  283.           if  ((t[x1,y1]=2) and (((t[x1+1,y1+1]=1) or (t[x1+1,y1-1]=1)) or
  284.                                 ((t[x1+2,y1+2]=1) and ((t[x1+1,y1+1]=3) or (t[x1+1,y1+1]=5))) or
  285.                                 ((t[x1-2,y1+2]=1) and ((t[x1-1,y1+1]=3) or (t[x1-1,y1+1]=5))) or
  286.                                 ((t[x1+2,y1-2]=1) and ((t[x1+1,y1-1]=3) or (t[x1+1,y1-1]=5))) or
  287.                                 ((t[x1-2,y1-2]=1) and ((t[x1-1,y1-1]=3) or (t[x1-1,y1-1]=5))))) or
  288.               ((t[x1,y1]=3) and (((t[x1-1,y1+1]=1) or (t[x1-1,y1-1]=1)) or
  289.                                 ((t[x1+2,y1+2]=1) and ((t[x1+1,y1+1]=2) or (t[x1+1,y1+1]=4))) or
  290.                                 ((t[x1-2,y1+2]=1) and ((t[x1-1,y1+1]=2) or (t[x1-1,y1+1]=4))) or
  291.                                 ((t[x1+2,y1-2]=1) and ((t[x1+1,y1-1]=2) or (t[x1+1,y1-1]=4))) or
  292.                                 ((t[x1-2,y1-2]=1) and ((t[x1-1,y1-1]=2) or (t[x1-1,y1-1]=4))))) or
  293.                                 (t[x1,y1]=4) or (t[x1,y1]=5) then
  294.           pop1:=true;
  295.         end
  296.       else pop1:=false;
  297.     end;
  298.  
  299. {funkcja sprawdzajaca poprawnosc (punkt 2) - sprawdza czy ruch odbywa sie po przekatnej,
  300. czy istnieje na planszy takie pole, czy wybrane pole jest puste }   {!}
  301.   function pop2(g,x1,x2,y1,y2:integer):boolean;
  302.     var
  303.       x,y:integer;
  304.     begin
  305.     x:=x2-x1;
  306.     y:=y2-y1;
  307.     if t[x2,y2]<>1 then pop2:=false
  308.     else
  309.       begin
  310.       if not((x-y=0) or (x+y=0)) and (x2>=1) and (x2<=8) and (y2>=1) and (y2<=8) then pop2:=false
  311.       else pop2:=true;
  312.       end;
  313.     end;
  314.  
  315. {funkcja sprawdzajaca czy mozliwe jest 2 bicie}
  316.   function spr2bicie(x1,x2,y1,y2:integer):boolean;
  317.   var
  318.   i,j:integer;
  319.     begin
  320.     x1:=x2;
  321.     y1:=y2;
  322.       if((t[x1,y1]=2) and(((t[x1+2,y1+2]=1) and ((t[x1+1,y1+1]=3) or (t[x1+1,y1+1]=5))) or
  323.                           ((t[x1-2,y1+2]=1) and ((t[x1-1,y1+1]=3) or (t[x1-1,y1+1]=5))) or
  324.                           ((t[x1+2,y1-2]=1) and ((t[x1+1,y1-1]=3) or (t[x1+1,y1-1]=5))) or
  325.                           ((t[x1-2,y1-2]=1) and ((t[x1-1,y1-1]=3) or (t[x1-1,y1-1]=5))))) or
  326.         ((t[x1,y1]=3) and(((t[x1+2,y1+2]=1) and ((t[x1+1,y1+1]=2) or (t[x1+1,y1+1]=4))) or
  327.                           ((t[x1-2,y1+2]=1) and ((t[x1-1,y1+1]=2) or (t[x1-1,y1+1]=4))) or
  328.                           ((t[x1+2,y1-2]=1) and ((t[x1+1,y1-1]=2) or (t[x1+1,y1-1]=4))) or
  329.                           ((t[x1-2,y1-2]=1) and ((t[x1-1,y1-1]=2) or (t[x1-1,y1-1]=4))))) then
  330.       spr2bicie:=true;
  331.     end;
  332.  
  333.  
  334. begin
  335. plansza;
  336. rysuje_ramke(0,0,9,9);
  337. p1:=0;
  338. P2:=0;
  339. p:=1;
  340.   repeat
  341.     repeat
  342.     gotoxy(14,0);
  343.     writeln('Gracz nr ',p);
  344.     writeln('Podaj wspolrzedne pionka ktorym chesz wykonac ruch');
  345.     gotoxy(16,-1);
  346.     writeln('            ');
  347.       repeat
  348.       {$I-}gotoxy(16,0);
  349.       read(x3);{$I+}
  350.       until (IOResult=0) and (x3 in ['a'..'h','A'..'H']);
  351.       repeat
  352.       {$I-}gotoxy(16,4);
  353.       read(y1);{$I+}
  354.       until IOResult=0;
  355.     x1:=czyt(x3);
  356.     until pop1(p,x1,y1);
  357.   write('Podaj wspolrzedne pola na ktore chcesz sie przemiescic');
  358.  {!!!!!!}
  359.  
  360.  
  361.  repeat
  362.     repeat
  363.     gotoxy(18,-1);
  364.     writeln('            ');
  365.       repeat
  366.       {$I-}gotoxy(18,0);
  367.       read(x3);{$I+}
  368.       until (IOResult=0) and (x3 in ['a'..'h','A'..'H']);
  369.       repeat
  370.       {$I-}gotoxy(18,4);
  371.       read(y2);{$I+}
  372.       until IOResult=0;
  373.     x2:=czyt(x3);
  374.     s:=pop3(p,x1,x2,y1,y2);
  375.     until ((pop2(p,x1,x2,y1,y2)) and (S<>0));
  376.   rysuj(x1,x2,y1,y2,p,S);
  377.   if (s=2) or (s=4) then w[p]:=w[p]+1;
  378.   if (s=2) and (spr2bicie(x1,x2,y1,y2)) then
  379.     begin
  380.     gotoxy(16,0);
  381.     writeln(x2);
  382.     gotoxy(16,4);
  383.     writeln(y2);
  384.     x1:=x2;
  385.     y1:=y2;
  386.     end;
  387.   until spr2bicie(x1,x2,y1,y2)=false;
  388.  {!!!!!}
  389.  
  390.   p:=P+1 ;
  391.   if p>2 then p:=p mod 2;
  392.   rysuje_ramke(2,35,6,53);
  393.   rysuje_ramke(0,45,2,53);
  394.   gotoxy(1,46);
  395.   writeln('PUNKTY');
  396.   gotoxy(3,37);
  397.   writeln('Gracz nr 1: ',w[1]);
  398.   gotoxy(5,37);
  399.   writeln('Gracz nr 2: ',w[2]);
  400.   until (w[1]=12) or (w[2]=12);
  401. gotoxy(18,25);
  402. if w[2]=12 then
  403. writeln('Gratulacje wygrał gracz 2!')
  404. else
  405. writeln('Gratulacje wygrał gracz 1!');
  406. readln;
  407. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement