Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.78 KB | None | 0 0
  1. /*
  2.     версия Alpha 3.0
  3.     работает неправильно
  4.     1)игрок всегда ноmер 1
  5.     2)описал ИИ
  6.     3)в следующий раз буду дебажить а потом интерфейс
  7. */
  8. #include <string>
  9. #include <iostream>
  10. #include <ctime>
  11.  
  12. using namespace std;
  13.  
  14. int pole[3][3];
  15. /*        y x
  16.       a b c  x
  17.     0 0 1 2
  18.     1 0 1 2
  19.     2 0 1 2
  20.     y
  21. */
  22. int play=0;
  23. int y,x;
  24.  
  25. void out()//готово
  26. {
  27.     cout<<"_____________________________________"<<endl;
  28.     cout<<pole[0][0]<<pole[0][1]<<pole[0][2]<<endl;
  29.     cout<<pole[1][0]<<pole[1][1]<<pole[1][2]<<endl;
  30.     cout<<pole[2][0]<<pole[2][1]<<pole[2][2]<<endl;
  31.     cout<<"_____________________________________"<<endl;
  32. }
  33.  
  34. void bestplay()
  35. {
  36.    
  37.     if(play>=3)
  38.     {
  39.         int win=0,dun=0;
  40.         for(int i=0;i<3;i++)
  41.         {
  42.         for(int j=0;j<3;j++)
  43.         {
  44.             if(pole[i][j]==2)
  45.             {
  46.                 win++;  
  47.             }
  48.         }
  49.         if(win==2)
  50.         {
  51.             for(int j=0;j<3;j++)
  52.             {
  53.                 if (pole[i][j]==0)
  54.                 {
  55.                     pole[i][j]=2;
  56.                     break;
  57.                 }
  58.             }
  59.             break;
  60.         }
  61.     }
  62.         win=0;
  63.         dun=0;
  64.         for(int i=0;i<3;i++)
  65.         {
  66.             for(int j=0;j<3;j++)
  67.             {
  68.                 if(pole[j][i]==2)
  69.                 {
  70.                     win++;  
  71.                 }
  72.             }
  73.             if(win==2)
  74.             {
  75.                 for(int j=0;j<3;j++)
  76.                 {
  77.                     if (pole[j][i]==0)
  78.                     {
  79.                         pole[j][i]=2;
  80.                         break;
  81.                     }
  82.                 }
  83.                 break;
  84.             }      
  85.         }
  86.    
  87.        
  88.         win=0;
  89.         dun=0;
  90.         for(int i=0;i<3;i++)
  91.         {
  92.         for(int j=0;j<3;j++)
  93.         {
  94.             if(pole[i][j]==1)
  95.             {
  96.                 dun++;  
  97.             }
  98.         }
  99.         if(dun==2)
  100.         {
  101.             for(int j=0;j<3;j++)
  102.             {
  103.                 if (pole[i][j]==0)
  104.                 {
  105.                     pole[i][j]=2;
  106.                     break;
  107.                 }
  108.             }
  109.             break;
  110.         }
  111.     }
  112.         win=0;
  113.         dun=0;
  114.         for(int i=0;i<3;i++)
  115.         {
  116.         for(int j=0;j<3;j++)
  117.         {
  118.             if(pole[j][i]==1)
  119.             {
  120.                 dun++;  
  121.             }
  122.         }
  123.         if(dun==2)
  124.         {
  125.             for(int j=0;j<3;j++)
  126.             {
  127.                 if (pole[j][i]==0)
  128.                 {
  129.                     pole[j][i]=2;
  130.                     break;
  131.                 }
  132.             }
  133.             break;
  134.         }
  135.     }
  136.         win=0;
  137.         dun=0;
  138.        
  139.     }
  140.         else
  141.         {
  142.             if(pole[1][1]==0)
  143.             {
  144.                 pole[1][1]=2;
  145.             }
  146.                 else
  147.                 {
  148.                     if(pole[0][2]==0)
  149.                     {
  150.                         pole[0][2]=2;
  151.                     }
  152.                 }
  153.         }
  154. }
  155.  
  156. void input()//готово
  157. {
  158.     char a;
  159.     int y;
  160.     int x;
  161.     cin>>y>>x;
  162.     pole[y][x]=1;
  163. }
  164.  
  165.  
  166.  
  167. void newgame()//готово
  168. {
  169.    
  170.     for(int i=0;i<3;i++)
  171.     {
  172.         for(int j=0;j<3;j++)
  173.         {
  174.             pole[i][j]=0;
  175.         }
  176.     }
  177.    out();
  178. }
  179.  
  180. int main()
  181. {
  182.     srand(time(NULL));
  183.     setlocale(LC_ALL,"Russian");
  184.    
  185.     string kom;
  186.     cin>>kom;
  187.     if(kom=="играть")
  188.     {
  189.         newgame();
  190.         for(int i=0;play<9;i++)
  191.         {
  192.             play++;
  193.             input();
  194.             out();
  195.             play++;
  196.             bestplay();
  197.             out();
  198.         }
  199.     }
  200.     return 0;
  201. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement