Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. /*
  2. версия Alpha 3.6
  3. работает неправильно
  4. 1)игрок всегда ноmер 1
  5. 2)начал переделывать ИИ
  6. 3)хз сколько буду дорабатывать,но после доработки,это будет Beta 1.0
  7.  
  8. */
  9. #include <string>
  10. #include <iostream>
  11. #include <ctime>
  12.  
  13. using namespace std;
  14.  
  15. int pole[3][3];
  16. /* y x
  17. a b c x
  18. 0 0 1 2
  19. 1 0 1 2
  20. 2 0 1 2
  21. y
  22. */
  23. int play=0;
  24. int y,x;
  25.  
  26. void out()//готово
  27. {
  28. cout<<"_____________________________________"<<endl;
  29. cout<<pole[0][0]<<pole[0][1]<<pole[0][2]<<endl;
  30. cout<<pole[1][0]<<pole[1][1]<<pole[1][2]<<endl;
  31. cout<<pole[2][0]<<pole[2][1]<<pole[2][2]<<endl;
  32. cout<<"_____________________________________"<<endl;
  33. }
  34.  
  35. int bestplay()
  36. {
  37. int win=0,dun=0;
  38. if(play>=3)
  39. {
  40. //вертикали
  41. for(int i=0;i<3;i++)
  42. {
  43. for(int j=0;j<3;j++)
  44. {
  45. if(pole[i][j]==2)
  46. {
  47. win++;
  48. }
  49. if(win==2)
  50. {
  51. for(int k=0;k<3;k++)
  52. {
  53. pole[k][j]==0;
  54. pole[k][j]=2;
  55. return 0;
  56. }
  57. }
  58. }
  59. }
  60. //_________________________________________________________________________________________________________
  61. for(int i=0;i<3;i++)
  62. {
  63. for(int j=0;j<3;j++)
  64. {
  65. if(pole[i][j]==2)
  66. {
  67. win++;
  68. }
  69. if(win==2)
  70. {
  71. for(int k=0;k<3;k++)
  72. {
  73. pole[k][j]==0;
  74. pole[k][j]=2;
  75. return 0;
  76. }
  77. }
  78. }
  79. }
  80.  
  81. }
  82. else
  83. {
  84. if(pole[1][1]==0)
  85. {
  86. pole[1][1]==2;
  87. return 0;
  88. }
  89. pole[0][2]==2;
  90. return 0;
  91. }
  92.  
  93. }
  94.  
  95. void input()//готово
  96. {
  97. char a;
  98. int y;
  99. int x;
  100. cin>>y>>x;
  101. pole[y][x]=1;
  102. }
  103.  
  104. void newgame()//готово
  105. {
  106.  
  107. for(int i=0;i<3;i++)
  108. {
  109. for(int j=0;j<3;j++)
  110. {
  111. pole[i][j]=0;
  112. }
  113. }
  114. out();
  115. }
  116.  
  117. int main()
  118. {
  119. srand(time(NULL));
  120. setlocale(LC_ALL,"Russian");
  121. string kom;
  122. cin>>kom;
  123. if(kom=="играть")
  124. {
  125. newgame();
  126. for(int i=0;play<9;i++)
  127. {
  128. play++;
  129. input();
  130. out();
  131. play++;
  132. bestplay();
  133. out();
  134. }
  135. }
  136. return 0;
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement