Advertisement
Glenpl

Untitled

Oct 25th, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 27.18 KB | None | 0 0
  1. // tic tac toe v2.0
  2. // autor jakub molinski
  3.  
  4. #include <iostream>
  5. #include <conio.h>
  6. #include <time.h>
  7. #include <cstdlib>
  8. #include <windows.h>
  9.  
  10. using namespace std;
  11.  
  12. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  13. int table[9] = {49, 50, 51, 52, 53, 54, 55, 56, 57};
  14. string gracz;
  15. string ak_gracz;
  16. int pole;
  17. const string cross = "Krzyzyk";
  18. const string circle = "Kolko";
  19. bool koniec = false;
  20. bool remis = false;
  21. bool puste = false;
  22. char wybor;
  23. int wybrane_pole;
  24. int ktora_kwestia = 0;
  25. char znak_kompa;
  26. string kto_wygral;
  27. bool pierwszy_raz = true;
  28. int przegrane;
  29. int wygrane;
  30. int remisy;
  31. bool pierwszy_ruch = false;
  32.  
  33. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  34. void inicjuj_gre();
  35.  
  36. void rysuj_plansze();
  37.  
  38. bool zmien_pole(int);
  39.  
  40. void ruch_mkika();
  41.  
  42. bool sprawdz_kto_wygral();
  43.  
  44. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  45. int main()
  46. {
  47.     for (;;)
  48.     {
  49.         inicjuj_gre();
  50.         if (pierwszy_raz == true)
  51.         {
  52.             cout << "Jestem MKiK, czyli Mistrzem gry Kolko i Krzyzyk!" << endl;
  53.             cout << "Chcialbym z Toba zagrac!" << endl;
  54.             cout << "Mam nadzieje, ze moje komentarze nie beda Ci przeszkadzaly..." << endl << endl;
  55.             Sleep(3000);
  56.             cout << "Zaczynajmy!";
  57.             Sleep(2000);
  58.             pierwszy_raz = false;
  59.         }
  60.         while ((koniec == false)&&(remis == false))
  61.         {
  62.             if(pierwszy_ruch == true)
  63.             {
  64.                 ktora_kwestia = 1;
  65.                 rysuj_plansze();
  66.                 ruch_mkika();
  67.                 Sleep(1500);
  68.                 ktora_kwestia = 2;
  69.                 rysuj_plansze();
  70.                 Sleep(1000);
  71.                 ktora_kwestia = 0;
  72.                 pierwszy_ruch = false;
  73.             }
  74.             else
  75.             {
  76.                 rysuj_plansze();
  77.             }
  78.  
  79.             for (;;)
  80.             {
  81.                 do
  82.                 {
  83.                     rysuj_plansze();
  84.                     pole = getch();
  85.                     if ((pole > (char)48)&&(pole < (char)58))
  86.                     {
  87.                         puste = zmien_pole(pole);
  88.                         if (puste == false)
  89.                         {
  90.                             cout << endl << endl << "Pole zajete!";
  91.                             getch();
  92.                             rysuj_plansze();
  93.                         }
  94.                     }
  95.                     else
  96.                     {
  97.                         cout << endl << endl << "Bledny numer pola!";
  98.                         puste = false;
  99.                         getch();
  100.                     }
  101.                 }
  102.                 while (puste == false);
  103.  
  104.                 sprawdz_kto_wygral();
  105.                 if ((koniec == true)||(remis == true)) break;
  106.  
  107.                 ktora_kwestia = 1;
  108.                 rysuj_plansze();
  109.                 ruch_mkika();
  110.                 Sleep(1500);
  111.                 ktora_kwestia = 2;
  112.                 rysuj_plansze();
  113.                 Sleep(1000);
  114.                 ktora_kwestia = 0;
  115.  
  116.                 sprawdz_kto_wygral();
  117.                 if ((koniec == true)||(remis == true)) break;
  118.             }
  119.         }
  120.         for (;;)
  121.         {
  122.             rysuj_plansze();
  123.             wybor = getch();
  124.             if ((wybor == 't')||
  125.                     (wybor == 'T'))
  126.             {
  127.                 inicjuj_gre();
  128.                 break;
  129.             }
  130.             if ((wybor == 'n')||
  131.                     (wybor == 'N'))
  132.             {
  133.                 break;
  134.             }
  135.         }
  136.         if ((wybor == 'n')||
  137.                 (wybor == 'N'))
  138.         {
  139.             break;
  140.         }
  141.     }
  142.     return 0;
  143. }
  144.  
  145. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  146. void inicjuj_gre()
  147. {
  148.     srand(time(NULL));
  149.     if ((rand()%2) == 0)
  150.     {
  151.         ak_gracz = cross;
  152.         gracz = ak_gracz;
  153.         znak_kompa = 'O';
  154.     }
  155.     else
  156.     {
  157.         ak_gracz = circle;
  158.         gracz = ak_gracz;
  159.         znak_kompa = 'X';
  160.         pierwszy_ruch = true;
  161.     }
  162.  
  163.     for (int i = 0; i < 9; i++)
  164.     {
  165.         table[i] = 49+i;
  166.     }
  167.     kto_wygral = "";
  168.     koniec = false;
  169.     remis = false;
  170. }
  171.  
  172. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  173. void rysuj_plansze()
  174. {
  175.     system("cls");
  176.     cout << "                                " << "KOLKO I KRZYZYK" << endl;
  177.     if (ktora_kwestia == 0)
  178.     {
  179.         cout << endl << endl << endl << endl;
  180.     }
  181.     else if (ktora_kwestia == 1)
  182.     {
  183.         cout << endl << endl;
  184.         cout << "MKiK: Daj mi pomyslec...";
  185.         cout << endl << endl;
  186.     }
  187.     else if (ktora_kwestia == 2)
  188.     {
  189.         cout << endl << endl;
  190.         cout << "MKiK: Wybieram pole numer: " << wybrane_pole;
  191.         cout << endl << endl;
  192.     }
  193.     cout << "                                   " << (char)table[0] << " | " << (char)table[1] << " | " << (char)table[2] << endl;
  194.     cout << "                                   " << "--+---+--" << endl;
  195.     cout << "                                   " << (char)table[3] << " | " << (char)table[4] << " | " << (char)table[5] << endl;
  196.     cout << "                                   " << "--+---+--" << endl;
  197.     cout << "                                   " << (char)table[6] << " | " << (char)table[7] << " | " << (char)table[8] << endl;
  198.     cout << endl << endl << endl;
  199.  
  200.     if ((koniec == false)&&(remis == false))
  201.     {
  202.         cout << "Twoj znak: " << ak_gracz << endl;
  203.         cout << "Znak MKiK'a: ";
  204.         if (ak_gracz == cross) cout << circle << endl;
  205.         else cout << cross << endl;
  206.     }
  207.     cout << endl;
  208.     cout << "Wygrane: " << wygrane << endl;
  209.     cout << "Przegrane: " << przegrane << endl;
  210.     cout << "Remisy: " << remisy;
  211.  
  212.     cout << endl << endl << endl;
  213.  
  214.     cout << "Wybierz pole: ";
  215.  
  216.     if (koniec == true)
  217.     {
  218.         cout << endl;
  219.         if (kto_wygral == "user")
  220.         {
  221.             cout << "Brawo!!! Wygrales!" << endl << endl;
  222.             wygrane++;
  223.         }
  224.         if (kto_wygral == "komp")
  225.         {
  226.             cout << "Niestety! Wygral MKiK!" << endl << endl;
  227.             przegrane++;
  228.         }
  229.  
  230.         cout << "Czy chcesz zagrac jeszcze raz? (T/N)";
  231.     }
  232.  
  233.     if (remis == true)
  234.     {
  235.         cout << endl;
  236.         cout << "Gra zakonczyla sie remisem!" << endl << endl;
  237.         cout << "Czy chcesz zagrac jeszcze raz? (T/N)";
  238.         remisy++;
  239.     }
  240.  
  241. }
  242.  
  243. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  244. bool zmien_pole(int pole)
  245. {
  246.     switch(pole)
  247.     {
  248.     case 49:
  249.         if (table[0] == 49)
  250.         {
  251.             if (ak_gracz == cross) table[0] = 88;
  252.             else table[0] = 79;
  253.             return true;
  254.         }
  255.         else return false;
  256.     case 50:
  257.         if (table[1] == 50)
  258.         {
  259.             if (ak_gracz == cross) table[1] = 88;
  260.             else table[1] = 79;
  261.             return true;
  262.         }
  263.         else return false;
  264.     case 51:
  265.         if (table[2] == 51)
  266.         {
  267.             if (ak_gracz == cross) table[2] = 88;
  268.             else table[2] = 79;
  269.             return true;
  270.         }
  271.         else return false;
  272.     case 52:
  273.         if (table[3] == 52)
  274.         {
  275.             if (ak_gracz == cross) table[3] = 88;
  276.             else table[3] = 79;
  277.             return true;
  278.         }
  279.         else return false;
  280.     case 53:
  281.         if (table[4] == 53)
  282.         {
  283.             if (ak_gracz == cross) table[4] = 88;
  284.             else table[4] = 79;
  285.             return true;
  286.         }
  287.         else return false;
  288.     case 54:
  289.         if (table[5] == 54)
  290.         {
  291.             if (ak_gracz == cross) table[5] = 88;
  292.             else table[5] = 79;
  293.             return true;
  294.         }
  295.         else return false;
  296.     case 55:
  297.         if (table[6] == 55)
  298.         {
  299.             if (ak_gracz == cross) table[6] = 88;
  300.             else table[6] = 79;
  301.             return true;
  302.         }
  303.         else return false;
  304.     case 56:
  305.         if (table[7] == 56)
  306.         {
  307.             if (ak_gracz == cross) table[7] = 88;
  308.             else table[7] = 79;
  309.             return true;
  310.         }
  311.         else return false;
  312.     case 57:
  313.         if (table[8] == 57)
  314.         {
  315.             if (ak_gracz == cross) table[8] = 88;
  316.             else table[8] = 79;
  317.             return true;
  318.         }
  319.         else return false;
  320.     }
  321.     return true;
  322. }
  323.  
  324. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  325. bool sprawdz_kto_wygral()
  326. {
  327.     if (
  328.         ((table[0] == table[1])&&(table[0] == table[2])&&(static_cast<char>(table[0]) == znak_kompa))||
  329.         ((table[3] == table[4])&&(table[3] == table[5])&&(static_cast<char>(table[3]) == znak_kompa))||
  330.         ((table[6] == table[7])&&(table[6] == table[8])&&(static_cast<char>(table[6]) == znak_kompa))||
  331.         ((table[0] == table[3])&&(table[0] == table[6])&&(static_cast<char>(table[0]) == znak_kompa))||
  332.         ((table[1] == table[4])&&(table[1] == table[7])&&(static_cast<char>(table[1]) == znak_kompa))||
  333.         ((table[2] == table[5])&&(table[2] == table[8])&&(static_cast<char>(table[2]) == znak_kompa))||
  334.         ((table[0] == table[4])&&(table[0] == table[8])&&(static_cast<char>(table[0]) == znak_kompa))||
  335.         ((table[2] == table[4])&&(table[2] == table[6])&&(static_cast<char>(table[2]) == znak_kompa))
  336.     )
  337.     {
  338.         koniec = true;
  339.         kto_wygral = "komp";
  340.         return true;
  341.     }
  342.  
  343.     if (
  344.         (table[0] == table[1])&&(table[0] == table[2])||
  345.         (table[3] == table[4])&&(table[3] == table[5])||
  346.         (table[6] == table[7])&&(table[6] == table[8])||
  347.         (table[0] == table[3])&&(table[0] == table[6])||
  348.         (table[1] == table[4])&&(table[1] == table[7])||
  349.         (table[2] == table[5])&&(table[2] == table[8])||
  350.         (table[0] == table[4])&&(table[0] == table[8])||
  351.         (table[2] == table[4])&&(table[2] == table[6])
  352.     )
  353.     {
  354.         koniec = true;
  355.         kto_wygral = "user";
  356.         return true;
  357.     }
  358.  
  359.     if ((table[0] != 49)&&
  360.             (table[1] != 50)&&
  361.             (table[2] != 51)&&
  362.             (table[3] != 52)&&
  363.             (table[4] != 53)&&
  364.             (table[5] != 54)&&
  365.             (table[6] != 55)&&
  366.             (table[7] != 56)&&
  367.             (table[8] != 57))
  368.     {
  369.         remis = true;
  370.     }
  371.     return true;
  372. }
  373.  
  374. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  375. void ruch_mkika()
  376. {
  377.     ////////////// zacznij
  378.  
  379.     if(pierwszy_ruch == true)
  380.     {
  381.         int d = rand()%18;
  382.         if (d == 0)
  383.         {
  384.             if(table[0] == 49)
  385.             {
  386.                 if (ak_gracz == cross) table[0] = 79;
  387.                 else table[0] = 88;
  388.                 wybrane_pole = 1;
  389.                 return;
  390.             }
  391.         }
  392.         if (d == 1)
  393.         {
  394.             if(table[1] == 50)
  395.             {
  396.                 if (ak_gracz == cross) table[1] = 79;
  397.                 else table[1] = 88;
  398.                 wybrane_pole = 2;
  399.                 return;
  400.             }
  401.         }
  402.         if (d == 2)
  403.         {
  404.             if(table[2] == 51)
  405.             {
  406.                 if (ak_gracz == cross) table[2] = 79;
  407.                 else table[2] = 88;
  408.                 wybrane_pole = 3;
  409.                 return;
  410.             }
  411.         }
  412.         if (d == 3)
  413.         {
  414.             if(table[3] == 52)
  415.             {
  416.                 if (ak_gracz == cross) table[3] = 79;
  417.                 else table[3] = 88;
  418.                 wybrane_pole = 4;
  419.                 return;
  420.             }
  421.         }
  422.         if (d == 4)
  423.         {
  424.             if(table[5] == 54)
  425.             {
  426.                 if (ak_gracz == cross) table[5] = 79;
  427.                 else table[5] = 88;
  428.                 wybrane_pole = 6;
  429.                 return;
  430.             }
  431.         }
  432.         if (d == 5)
  433.         {
  434.             if(table[6] == 55)
  435.             {
  436.                 if (ak_gracz == cross) table[6] = 79;
  437.                 else table[6] = 88;
  438.                 wybrane_pole = 7;
  439.                 return;
  440.             }
  441.         }
  442.         if (d == 6)
  443.         {
  444.             if(table[7] == 56)
  445.             {
  446.                 if (ak_gracz == cross) table[7] = 79;
  447.                 else table[7] = 88;
  448.                 wybrane_pole = 8;
  449.                 return;
  450.             }
  451.         }
  452.         if (d == 7)
  453.         {
  454.             if(table[8] == 57)
  455.             {
  456.                 if (ak_gracz == cross) table[8] = 79;
  457.                 else table[8] = 88;
  458.                 wybrane_pole = 9;
  459.                 return;
  460.             }
  461.         }
  462.         else
  463.         {
  464.             if(table[4] == 53)
  465.             {
  466.                 if (ak_gracz == cross) table[4] = 79;
  467.                 else table[4] = 88;
  468.                 wybrane_pole = 5;
  469.                 return;
  470.             }
  471.         }
  472.     }
  473.  
  474.     //////////// atak
  475.     if((table[0] == table[2])&&(static_cast<char>(table[0]) == znak_kompa)&&(table[1] == 50))
  476.     {
  477.         if (ak_gracz == cross) table[1] = 79;
  478.         else table[1] = 88;
  479.         wybrane_pole = 2;
  480.         return;
  481.     }
  482.  
  483.     if((table[3] == table[5])&&(static_cast<char>(table[3]) == znak_kompa)&&(table[4] == 53))
  484.     {
  485.         if (ak_gracz == cross) table[4] = 79;
  486.         else table[4] = 88;
  487.         wybrane_pole = 5;
  488.         return;
  489.     }
  490.  
  491.     if((table[6] == table[8])&&(static_cast<char>(table[6]) == znak_kompa)&&(table[7] == 56))
  492.     {
  493.         if (ak_gracz == cross) table[7] = 79;
  494.         else table[7] = 88;
  495.         wybrane_pole = 8;
  496.         return;
  497.     }
  498.  
  499.     if((table[0] == table[6])&&(static_cast<char>(table[0]) == znak_kompa)&&(table[3] == 52))
  500.     {
  501.         if (ak_gracz == cross) table[3] = 79;
  502.         else table[3] = 88;
  503.         wybrane_pole = 3;
  504.         return;
  505.     }
  506.  
  507.     if((table[1] == table[7])&&(static_cast<char>(table[1]) == znak_kompa)&&(table[4] == 53))
  508.     {
  509.         if (ak_gracz == cross) table[4] = 79;
  510.         else table[4] = 88;
  511.         wybrane_pole = 5;
  512.         return;
  513.     }
  514.  
  515.     if((table[2] == table[8])&&(static_cast<char>(table[2]) == znak_kompa)&&(table[5] == 54))
  516.     {
  517.         if (ak_gracz == cross) table[5] = 79;
  518.         else table[5] = 88;
  519.         wybrane_pole = 6;
  520.         return;
  521.     }
  522.  
  523.     if((table[0] == table[8])&&(static_cast<char>(table[0]) == znak_kompa)&&(table[4] == 53))
  524.     {
  525.         if (ak_gracz == cross) table[4] = 79;
  526.         else table[4] = 88;
  527.         wybrane_pole = 5;
  528.         return;
  529.     }
  530.  
  531.     if((table[2] == table[6])&&(static_cast<char>(table[2]) == znak_kompa)&&(table[4] == 53))
  532.     {
  533.         if (ak_gracz == cross) table[4] = 79;
  534.         else table[4] = 88;
  535.         wybrane_pole = 5;
  536.         return;
  537.     }
  538.  
  539.     if((table[0] == table[1])&&(static_cast<char>(table[0]) == znak_kompa)&&(table[2] == 51))
  540.     {
  541.         if (ak_gracz == cross) table[2] = 79;
  542.         else table[2] = 88;
  543.         wybrane_pole = 3;
  544.         return;
  545.     }
  546.  
  547.     if((table[1] == table[2])&&(static_cast<char>(table[1]) == znak_kompa)&&(table[0] == 49))
  548.     {
  549.         if (ak_gracz == cross) table[0] = 79;
  550.         else table[0] = 88;
  551.         wybrane_pole = 1;
  552.         return;
  553.     }
  554.  
  555.     if((table[3] == table[4])&&(static_cast<char>(table[3]) == znak_kompa)&&(table[5] == 54))
  556.     {
  557.         if (ak_gracz == cross) table[5] = 79;
  558.         else table[5] = 88;
  559.         wybrane_pole = 6;
  560.         return;
  561.     }
  562.  
  563.     if((table[4] == table[5])&&(static_cast<char>(table[4]) == znak_kompa)&&(table[3] == 52))
  564.     {
  565.         if (ak_gracz == cross) table[3] = 79;
  566.         else table[3] = 88;
  567.         wybrane_pole = 4;
  568.         return;
  569.     }
  570.  
  571.     if((table[6] == table[7])&&(static_cast<char>(table[6]) == znak_kompa)&&(table[8] == 57))
  572.     {
  573.         if (ak_gracz == cross) table[8] = 79;
  574.         else table[8] = 88;
  575.         wybrane_pole = 9;
  576.         return;
  577.     }
  578.  
  579.     if((table[7] == table[8])&&(static_cast<char>(table[7]) == znak_kompa)&&(table[6] == 55))
  580.     {
  581.         if (ak_gracz == cross) table[6] = 79;
  582.         else table[6] = 88;
  583.         wybrane_pole = 7;
  584.         return;
  585.     }
  586.  
  587.     if((table[0] == table[3])&&(static_cast<char>(table[0]) == znak_kompa)&&(table[6] == 55))
  588.     {
  589.         if (ak_gracz == cross) table[6] = 79;
  590.         else table[6] = 88;
  591.         wybrane_pole = 7;
  592.         return;
  593.     }
  594.  
  595.     if((table[1] == table[4])&&(static_cast<char>(table[1]) == znak_kompa)&&(table[7] == 56))
  596.     {
  597.         if (ak_gracz == cross) table[7] = 79;
  598.         else table[7] = 88;
  599.         wybrane_pole = 8;
  600.         return;
  601.     }
  602.  
  603.     if((table[2] == table[5])&&(static_cast<char>(table[2]) == znak_kompa)&&(table[8] == 57))
  604.     {
  605.         if (ak_gracz == cross) table[8] = 79;
  606.         else table[8] = 88;
  607.         wybrane_pole = 9;
  608.         return;
  609.     }
  610.  
  611.     if((table[3] == table[6])&&(static_cast<char>(table[3]) == znak_kompa)&&(table[0] == 49))
  612.     {
  613.         if (ak_gracz == cross) table[0] = 79;
  614.         else table[0] = 88;
  615.         wybrane_pole = 1;
  616.         return;
  617.     }
  618.  
  619.     if((table[4] == table[7])&&(static_cast<char>(table[4]) == znak_kompa)&&(table[1] == 50))
  620.     {
  621.         if (ak_gracz == cross) table[1] = 79;
  622.         else table[1] = 88;
  623.         wybrane_pole = 2;
  624.         return;
  625.     }
  626.  
  627.     if((table[5] == table[8])&&(static_cast<char>(table[5]) == znak_kompa)&&(table[2] == 51))
  628.     {
  629.         if (ak_gracz == cross) table[2] = 79;
  630.         else table[2] = 88;
  631.         wybrane_pole = 3;
  632.         return;
  633.     }
  634.  
  635.     if((table[2] == table[4])&&(static_cast<char>(table[2]) == znak_kompa)&&(table[6] == 55))
  636.     {
  637.         if (ak_gracz == cross) table[6] = 79;
  638.         else table[6] = 88;
  639.         wybrane_pole = 7;
  640.         return;
  641.     }
  642.  
  643.     if((table[6] == table[4])&&(static_cast<char>(table[6]) == znak_kompa)&&(table[2] == 51))
  644.     {
  645.         if (ak_gracz == cross) table[2] = 79;
  646.         else table[2] = 88;
  647.         wybrane_pole = 3;
  648.         return;
  649.     }
  650.  
  651.     if((table[4] == table[8])&&(static_cast<char>(table[4]) == znak_kompa)&&(table[0] == 49))
  652.     {
  653.         if (ak_gracz == cross) table[0] = 79;
  654.         else table[0] = 88;
  655.         wybrane_pole = 1;
  656.         return;
  657.     }
  658.  
  659.     if((table[0] == table[4])&&(static_cast<char>(table[0]) == znak_kompa)&&(table[8] == 57))
  660.     {
  661.         if (ak_gracz == cross) table[8] = 79;
  662.         else table[8] = 88;
  663.         wybrane_pole = 9;
  664.         return;
  665.     }
  666.  
  667.     ///////////// obrona
  668.     if((table[0] == table[2])&&(table[1] == 50))
  669.     {
  670.         if (ak_gracz == cross) table[1] = 79;
  671.         else table[1] = 88;
  672.         wybrane_pole = 2;
  673.         return;
  674.     }
  675.  
  676.     if((table[3] == table[5])&&(table[4] == 53))
  677.     {
  678.         if (ak_gracz == cross) table[4] = 79;
  679.         else table[4] = 88;
  680.         wybrane_pole = 5;
  681.         return;
  682.     }
  683.  
  684.     if((table[6] == table[8])&&(table[7] == 56))
  685.     {
  686.         if (ak_gracz == cross) table[7] = 79;
  687.         else table[7] = 88;
  688.         wybrane_pole = 8;
  689.         return;
  690.     }
  691.  
  692.     if((table[0] == table[6])&&(table[3] == 52))
  693.     {
  694.         if (ak_gracz == cross) table[3] = 79;
  695.         else table[3] = 88;
  696.         wybrane_pole = 4;
  697.         return;
  698.     }
  699.  
  700.     if((table[1] == table[7])&&(table[4] == 53))
  701.     {
  702.         if (ak_gracz == cross) table[4] = 79;
  703.         else table[4] = 88;
  704.         wybrane_pole = 5;
  705.         return;
  706.     }
  707.  
  708.     if((table[2] == table[8])&&(table[5] == 54))
  709.     {
  710.         if (ak_gracz == cross) table[5] = 79;
  711.         else table[5] = 88;
  712.         wybrane_pole = 6;
  713.         return;
  714.     }
  715.  
  716.     if((table[0] == table[8])&&(table[4] == 53))
  717.     {
  718.         if (ak_gracz == cross) table[4] = 79;
  719.         else table[4] = 88;
  720.         wybrane_pole = 5;
  721.         return;
  722.     }
  723.  
  724.     if((table[2] == table[6])&&(table[4] == 53))
  725.     {
  726.         if (ak_gracz == cross) table[4] = 79;
  727.         else table[4] = 88;
  728.         wybrane_pole = 5;
  729.         return;
  730.     }
  731.  
  732.     if((table[0] == table[1])&&(table[2] == 51))
  733.     {
  734.         if (ak_gracz == cross) table[2] = 79;
  735.         else table[2] = 88;
  736.         wybrane_pole = 3;
  737.         return;
  738.     }
  739.  
  740.     if((table[1] == table[2])&&(table[0] == 49))
  741.     {
  742.         if (ak_gracz == cross) table[0] = 79;
  743.         else table[0] = 88;
  744.         wybrane_pole = 1;
  745.         return;
  746.     }
  747.  
  748.     if((table[3] == table[4])&&(table[5] == 54))
  749.     {
  750.         if (ak_gracz == cross) table[5] = 79;
  751.         else table[5] = 88;
  752.         wybrane_pole = 6;
  753.         return;
  754.     }
  755.  
  756.     if((table[4] == table[5])&&(table[3] == 52))
  757.     {
  758.         if (ak_gracz == cross) table[3] = 79;
  759.         else table[3] = 88;
  760.         wybrane_pole = 4;
  761.         return;
  762.     }
  763.  
  764.     if((table[6] == table[7])&&(table[8] == 57))
  765.     {
  766.         if (ak_gracz == cross) table[8] = 79;
  767.         else table[8] = 88;
  768.         wybrane_pole = 9;
  769.         return;
  770.     }
  771.  
  772.     if((table[7] == table[8])&&(table[6] == 55))
  773.     {
  774.         if (ak_gracz == cross) table[6] = 79;
  775.         else table[6] = 88;
  776.         wybrane_pole = 7;
  777.         return;
  778.     }
  779.  
  780.     if((table[0] == table[3])&&(table[6] == 55))
  781.     {
  782.         if (ak_gracz == cross) table[6] = 79;
  783.         else table[6] = 88;
  784.         wybrane_pole = 7;
  785.         return;
  786.     }
  787.  
  788.     if((table[1] == table[4])&&(table[7] == 56))
  789.     {
  790.         if (ak_gracz == cross) table[7] = 79;
  791.         else table[7] = 88;
  792.         wybrane_pole = 8;
  793.         return;
  794.     }
  795.  
  796.     if((table[2] == table[5])&&(table[8] == 57))
  797.     {
  798.         if (ak_gracz == cross) table[8] = 79;
  799.         else table[8] = 88;
  800.         wybrane_pole = 9;
  801.         return;
  802.     }
  803.  
  804.     if((table[3] == table[6])&&(table[0] == 49))
  805.     {
  806.         if (ak_gracz == cross) table[0] = 79;
  807.         else table[0] = 88;
  808.         wybrane_pole = 1;
  809.         return;
  810.     }
  811.  
  812.     if((table[4] == table[7])&&(table[1] == 50))
  813.     {
  814.         if (ak_gracz == cross) table[1] = 79;
  815.         else table[1] = 88;
  816.         wybrane_pole = 2;
  817.         return;
  818.     }
  819.  
  820.     if((table[5] == table[8])&&(table[2] == 51))
  821.     {
  822.         if (ak_gracz == cross) table[2] = 79;
  823.         else table[2] = 88;
  824.         wybrane_pole = 3;
  825.         return;
  826.     }
  827.  
  828.     if((table[2] == table[4])&&(table[6] == 55))
  829.     {
  830.         if (ak_gracz == cross) table[6] = 79;
  831.         else table[6] = 88;
  832.         wybrane_pole = 7;
  833.         return;
  834.     }
  835.  
  836.     if((table[6] == table[4])&&(table[2] == 51))
  837.     {
  838.         if (ak_gracz == cross) table[2] = 79;
  839.         else table[2] = 88;
  840.         wybrane_pole = 3;
  841.         return;
  842.     }
  843.  
  844.     if((table[4] == table[8])&&(table[0] == 49))
  845.     {
  846.         if (ak_gracz == cross) table[0] = 79;
  847.         else table[0] = 88;
  848.         wybrane_pole = 1;
  849.         return;
  850.     }
  851.  
  852.     if((table[0] == table[4])&&(table[8] == 57))
  853.     {
  854.         if (ak_gracz == cross) table[8] = 79;
  855.         else table[8] = 88;
  856.         wybrane_pole = 9;
  857.         return;
  858.     }
  859.  
  860.     ///////////////// poczatek gry
  861.  
  862.     // zaczyna na srodku
  863.     if(
  864.         (table[4] != 53)&&
  865.         (table[0] == 49)&&
  866.         (table[1] == 50)&&
  867.         (table[2] == 51)&&
  868.         (table[3] == 52)&&
  869.         (table[5] == 54)&&
  870.         (table[6] == 55)&&
  871.         (table[7] == 56)&&
  872.         (table[8] == 57)
  873.     )
  874.     {
  875.         int d = rand()%4;
  876.         if (d == 0)
  877.         {
  878.             if (ak_gracz == cross) table[0] = 79;
  879.             else table[0] = 88;
  880.             wybrane_pole = 1;
  881.         }
  882.         else if (d == 1)
  883.         {
  884.             if (ak_gracz == cross) table[2] = 79;
  885.             else table[2] = 88;
  886.             wybrane_pole = 3;
  887.         }
  888.         else if (d == 2)
  889.         {
  890.             if (ak_gracz == cross) table[6] = 79;
  891.             else table[6] = 88;
  892.             wybrane_pole = 7;
  893.         }
  894.         else if (d == 3)
  895.         {
  896.             if (ak_gracz == cross) table[8] = 79;
  897.             else table[8] = 88;
  898.             wybrane_pole = 9;
  899.         }
  900.         return;
  901.     }
  902.  
  903.     // zaczyna w innym miejscu
  904.     if(
  905.         (table[4] == 53)&&
  906.         (
  907.             (table[0] != 49)||
  908.             (table[1] != 50)||
  909.             (table[2] != 51)||
  910.             (table[3] != 52)||
  911.             (table[5] != 54)||
  912.             (table[6] != 55)||
  913.             (table[7] != 56)||
  914.             (table[8] != 57)
  915.         )
  916.     )
  917.     {
  918.         if (ak_gracz == cross) table[4] = 79;
  919.         else table[4] = 88;
  920.         wybrane_pole = 5;
  921.         return;
  922.     }
  923.  
  924.     else
  925.     {
  926.         for(;;)
  927.         {
  928.             int d = rand()%9;
  929.             if (d == 0)
  930.             {
  931.                 if(table[0] == 49)
  932.                 {
  933.                     if (ak_gracz == cross) table[0] = 79;
  934.                     else table[0] = 88;
  935.                     wybrane_pole = 1;
  936.                     return;
  937.                 }
  938.             }
  939.             if (d == 1)
  940.             {
  941.                 if(table[1] == 50)
  942.                 {
  943.                     if (ak_gracz == cross) table[1] = 79;
  944.                     else table[1] = 88;
  945.                     wybrane_pole = 2;
  946.                     return;
  947.                 }
  948.             }
  949.             if (d == 2)
  950.             {
  951.                 if(table[2] == 51)
  952.                 {
  953.                     if (ak_gracz == cross) table[2] = 79;
  954.                     else table[2] = 88;
  955.                     wybrane_pole = 3;
  956.                     return;
  957.                 }
  958.             }
  959.             if (d == 3)
  960.             {
  961.                 if(table[3] == 52)
  962.                 {
  963.                     if (ak_gracz == cross) table[3] = 79;
  964.                     else table[3] = 88;
  965.                     wybrane_pole = 4;
  966.                     return;
  967.                 }
  968.             }
  969.             if (d == 4)
  970.             {
  971.                 if(table[4] == 53)
  972.                 {
  973.                     if (ak_gracz == cross) table[4] = 79;
  974.                     else table[4] = 88;
  975.                     wybrane_pole = 5;
  976.                     return;
  977.                 }
  978.             }
  979.             if (d == 5)
  980.             {
  981.                 if(table[5] == 54)
  982.                 {
  983.                     if (ak_gracz == cross) table[5] = 79;
  984.                     else table[5] = 88;
  985.                     wybrane_pole = 6;
  986.                     return;
  987.                 }
  988.             }
  989.             if (d == 6)
  990.             {
  991.                 if(table[6] == 55)
  992.                 {
  993.                     if (ak_gracz == cross) table[6] = 79;
  994.                     else table[6] = 88;
  995.                     wybrane_pole = 7;
  996.                     return;
  997.                 }
  998.             }
  999.             if (d == 7)
  1000.             {
  1001.                 if(table[7] == 56)
  1002.                 {
  1003.                     if (ak_gracz == cross) table[7] = 79;
  1004.                     else table[7] = 88;
  1005.                     wybrane_pole = 8;
  1006.                     return;
  1007.                 }
  1008.             }
  1009.             if (d == 8)
  1010.             {
  1011.                 if(table[8] == 57)
  1012.                 {
  1013.                     if (ak_gracz == cross) table[8] = 79;
  1014.                     else table[8] = 88;
  1015.                     wybrane_pole = 9;
  1016.                     return;
  1017.                 }
  1018.             }
  1019.         }
  1020.         return;
  1021.     }
  1022. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement