Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. char table[3][3][3];
  7.  
  8.  
  9. struct Field{
  10. int index;
  11.  
  12. int x(){
  13. return index %3;
  14. }
  15. int y(){
  16. return (index/3)%3;
  17. }
  18. int z(){
  19. return index/3;
  20. }
  21.  
  22. int Value(){
  23. switch(table[x()][y()][z()]){
  24. case 'o' : return 2;
  25. case 'x' : return 1;
  26. default : return 0;
  27. }
  28. }
  29.  
  30. void setValue(char c){
  31. table[x()][y()][z()] =c;
  32. }
  33. };
  34.  
  35. vector <Field> fields(27);
  36.  
  37. struct Triple{
  38. Field first;
  39. Field second;
  40.  
  41. Field Third(){
  42. Field f;
  43. f.index = (second.index+first.index)/2;
  44. }
  45.  
  46. int AdaPoints(){
  47. int a = 0;
  48. if (first.Value()==1) a++;
  49. if (second.Value()==1) a++;
  50. if (Third().Value()==1) a++;
  51. return a;
  52. }
  53.  
  54. int VinitPoints(){
  55. int a = 0;
  56. if (first.Value()==2) a++;
  57. if (second.Value()==2) a++;
  58. if (Third().Value()==2) a++;
  59. return a;
  60. }
  61.  
  62. bool Finished(){
  63. if (AdaPoints()+VinitPoints()==3)
  64. return true;
  65. return false;
  66. }
  67.  
  68. int Winner(){
  69. if (Finished()) return 0;
  70. if (AdaPoints()==2) return 1;
  71. if (VinitPoints()==2) return 2;
  72. return 0;
  73. }
  74.  
  75. void toString(){
  76. cout << "(" << first.index << " " << second.index << " )";
  77. }
  78.  
  79. int findEmpty(){
  80. if (first.Value()=='.')
  81. return first.index;
  82. if (second.Value()=='.')
  83. return second.index;
  84. return Third().index;
  85. }
  86. };
  87.  
  88.  
  89.  
  90. vector <Triple> allTriples;
  91. vector <vector <Triple> > triplesContainingField(27);
  92.  
  93. bool makingTriple(int a, int b){
  94. return ((fields[a].x()+fields[b].x())%2==0 && (fields[a].y()+fields[b].y())%2==0 && (fields[a].z()+fields[b].z())%2 == 0);
  95. }
  96.  
  97. void showGame(){
  98. for (int i=0; i<3; i++)
  99. for (int j = 0; j<3; j++){
  100. for (int k = 0; k<3; k++)
  101. cout << table[i][j][k] << " ";
  102. cout << endl;
  103. }
  104. }
  105.  
  106. void FirstTurn(bool AdasTurn, int * criticalField){
  107. if (AdasTurn){
  108. for (int i=0; i<allTriples.size(); i++)
  109. if (allTriples[i].Winner()==1){
  110. cout << "Ada" << endl;
  111. return;
  112. }
  113. int minInd = 27;
  114. int maxInd = -1;
  115. for (int i=0; i<allTriples.size(); i++){
  116. if (allTriples[i].Winner()==2){
  117. int i = allTriples[i].findEmpty();
  118. if (i>maxInd) maxInd = i;
  119. if (i<minInd) minInd = i;
  120. }
  121. }
  122. if (maxInd == minInd){
  123. fields[maxInd].setValue('x');
  124. *criticalField = maxInd;
  125. }
  126. else if (maxInd < 27 && maxInd!=minInd){
  127. cout << "Vinit" << endl;
  128. return;
  129. }
  130. }
  131. else{
  132. for (int i=0; i<allTriples.size(); i++)
  133. if (allTriples[i].Winner()==2){
  134. cout << "Vinit" << endl;
  135. return;
  136. }
  137. int minInd = 27;
  138. int maxInd = -1;
  139. for (int i=0; i<allTriples.size(); i++){
  140. if (allTriples[i].Winner()==1){
  141. int i = allTriples[i].findEmpty();
  142. if (i>maxInd) maxInd = i;
  143. if (i<minInd) minInd = i;
  144. }
  145. }
  146. if (maxInd == minInd){
  147. fields[maxInd].setValue('o');
  148. *criticalField = maxInd;
  149. }
  150. else if (maxInd < 27 && maxInd!=minInd){
  151. cout << "Ada" << endl;
  152. return;
  153. }
  154. }
  155. }
  156.  
  157.  
  158. void Game(){
  159. int dif = 0;
  160. int fieldsLeft = 0;
  161. for (int i=0; i<3; i++)
  162. for (int j = 0; j<3; j++)
  163. for (int k = 0; k<3; k++){
  164. cin >> table[i][j][k];
  165. if (table[i][j][k] =='x') dif++;
  166. if (table[i][j][k]=='o') dif--;
  167. if (table[i][j][k] =='.') fieldsLeft++;
  168. }
  169.  
  170. bool AdasTurn;
  171. if (dif==0)
  172. AdasTurn = true;
  173. else
  174. AdasTurn = false;
  175.  
  176. int criticalField = -1;
  177. FirstTurn(AdasTurn, &criticalField);
  178. if (criticalField ==-1)
  179. return;
  180. }
  181. int main(){
  182. /* for (int i=0; i<27; i++)
  183. fields[i].index = i;
  184.  
  185. Triple t;
  186. for (int i=0; i<27; i++)
  187. for (int j = i+1; j<27; j++){
  188. if (makingTriple(i,j)){
  189. t = {fields[i], fields[j]};
  190. allTriples.push_back(t);
  191. triplesContainingField[i].push_back(t);
  192. triplesContainingField[(i+j)/2].push_back(t);
  193. triplesContainingField[j].push_back(t);
  194. }
  195.  
  196.  
  197. Game();
  198. showGame();*/
  199. cout << "Hello world";
  200. return 0;
  201. }
  202.  
  203. for (int i=0; i<s.size(); i++)
  204. if (s[i].Winner()==1){
  205. cout << "Ada" << endl;
  206. return;
  207. }
  208. int minInd = 27;
  209. int maxInd = -1;
  210. for (int i=0; i<s.size(); i++){
  211. if (s[i].Winner()==2){
  212. int i = s[i].findEmpty();
  213. if (i>maxInd) maxInd = i;
  214. if (i<minInd) minInd = i;
  215. }
  216. }
  217. if (maxInd == minInd){
  218. fields[maxInd].setValue('x');
  219. s = triplesContainingField[maxInd];
  220. }
  221. else if (maxInd < 27 && maxInd!=minInd){
  222. cout << "Vinit" << endl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement