Advertisement
Guest User

Untitled

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