Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.55 KB | None | 0 0
  1. /*
  2. версия Alpha 3.61
  3. работает неправильно
  4. 1)игрок всегда ноmер 1
  5. 2)переделал ИИ
  6. 3)надо дебажить
  7. )хз сколько буду дорабатывать,но после доработки,это будет 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. int bestplay()
  37. {
  38. int win=0,dun=0;
  39. if(play>=3)
  40. {
  41. //вертикали
  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. if(win==2)
  51. {
  52. for(int k=0;k<3;k++)
  53. {
  54. if(pole[i][k]==0)
  55. {
  56. pole[i][k]=2;
  57. win=0;
  58. out();
  59. return 0;
  60. }
  61. }
  62. }
  63. }
  64. }
  65. //_________________________________________________________________________________________________________
  66. for(int i=0;i<3;i++)
  67. {
  68. for(int j=0;j<3;j++)
  69. {
  70. if(pole[j][i]==2)
  71. {
  72. win++;
  73. }
  74. if(win==2)
  75. {
  76. for(int k=0;k<3;k++)
  77. {
  78. if(pole[k][j]==0)
  79. {
  80. pole[k][j]=2;
  81. win=0;
  82. out();
  83. return 0;
  84. }
  85. }
  86. }
  87. }
  88. }
  89. //_________________________________________________________________________________________________________
  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. if(dun==2)
  99. {
  100. for(int k=0;k<3;k++)
  101. {
  102. if(pole[i][k]==0)
  103. {
  104. pole[i][k]=2;
  105. dun=0;
  106. out();
  107. return 0;
  108. }
  109. }
  110. }
  111. }
  112. }
  113. //_________________________________________________________________________________________________________
  114. for(int i=0;i<3;i++)
  115. {
  116. for(int j=0;j<3;j++)
  117. {
  118. if(pole[j][i]==2)
  119. {
  120. dun++;
  121. }
  122. if(dun==2)
  123. {
  124. for(int k=0;k<3;k++)
  125. {
  126. if(pole[k][j]==0)
  127. {
  128. pole[k][j]=2;
  129. dun=0;
  130. out();
  131. return 0;
  132. }
  133. }
  134. }
  135. }
  136. }
  137. }
  138. else
  139. {
  140. if(pole[1][1]==0)
  141. {
  142. pole[1][1]==2;
  143. out();
  144. return 0;
  145. }
  146. else
  147. {
  148. pole[0][2]==2;
  149. out();
  150. return 0;
  151. }
  152. }
  153. }
  154.  
  155. void input()//готово
  156. {
  157. char a;
  158. int y;
  159. int x;
  160. cin>>y>>x;
  161. pole[y][x]=1;
  162. }
  163.  
  164. void newgame()//готово
  165. {
  166.  
  167. for(int i=0;i<3;i++)
  168. {
  169. for(int j=0;j<3;j++)
  170. {
  171. pole[i][j]=0;
  172. }
  173. }
  174. out();
  175. }
  176.  
  177. int main()
  178. {
  179. srand(time(NULL));
  180. setlocale(LC_ALL,"Russian");
  181. string kom;
  182. cin>>kom;
  183. if(kom=="играть")
  184. {
  185. newgame();
  186. for(int i=0;play<9;i++)
  187. {
  188. play++;
  189. input();
  190. out();
  191. play++;
  192. bestplay();
  193. }
  194. }
  195. return 0;
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement