Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. cout << "CPU takes its turn...n";
  2.  
  3. if (box[2] == box[3] || box[4] == box[7] ||
  4. box[5] == box[9] && box[1] != 'X' || box[1] != 'O') return 1;
  5.  
  6. if (box[1] == box[3] || box[5] == box[8] && box[2] != 'X' || box[2] != 'O') return 2;
  7.  
  8. if (box[1] == box[2] || box[6] == box[9] && box[3] != 'X' || box[3] != 'O') return 3;
  9.  
  10. if (box[1] == box[7] || box[5] == box[6] && box[4] != 'X' || box[4] != 'O') return 4;
  11.  
  12. if (box[1] == box[9] || box[4] == box[6] ||
  13. box[2] == box[8] || box[3] == box[7] && box[5] != 'X' || box[5] != 'O') return 5;
  14.  
  15. if (box[3] == box[9] || box[4] == box[5] && box[6] != 'X' || box[6] != 'O') return 6;
  16.  
  17. if (box[1] == box[4] || box[8] == box[9] ||
  18. box[3] == box[5] && box[7] != 'X' || box[7] != 'O') return 7;
  19.  
  20. if (box[7] == box[9] || box[2] == box[5] && box[8] != 'X' || box[8] != 'O') return 8;
  21.  
  22. if (box[1] == box[5] || box[7] == box[8] ||
  23. box[3] == box[6] && box[9] != 'X' || box[9] != 'O') return 9;
  24.  
  25. else {
  26.  
  27. }
  28. }
  29.  
  30. #include <iostream>
  31. #include <cstdlib>
  32. using namespace std;
  33.  
  34. char box[10] = {'v','1','2','3','4','5','6','7','8','9'};
  35.  
  36. int checkwin();
  37. void board();
  38. int CPUmove();
  39.  
  40.  
  41. int main()
  42. {
  43. bool exit = true;
  44. while (exit){
  45. box[0] = 'v';
  46. box[1] = '1';
  47. box[2] = '2';
  48. box[3] = '3';
  49. box[4] = '4';
  50. box[5] = '5';
  51. box[6] = '6';
  52. box[7] = '7';
  53. box[8] = '8';
  54. box[9] = '9';
  55. int player = 1, i, choice,intexit;
  56. char mark;
  57. srand(time(0));
  58.  
  59. do
  60. {
  61. board();
  62. player = (player % 2) ? 1 : 2;
  63.  
  64. if (player == 1){
  65. cout << "Enter the number of the box you want to choose: ";
  66. cin >> choice;
  67. }
  68.  
  69. else if (player == 2) choice = CPUmove();
  70.  
  71. mark = (player == 1) ? 'X' : 'O';
  72.  
  73. if (box[choice] == (char)(((int)'0')+choice))
  74. box[choice] = mark;
  75.  
  76. else
  77. {
  78. cout << "Invalid move ";
  79. player--;
  80. cin.ignore();
  81. cin.get();
  82. }
  83.  
  84. i = checkwin();
  85. player++;
  86.  
  87. } while(i == -1);
  88.  
  89. board();
  90. if (i == 1) cout << "==>aPlayer " << --player << " wins!";
  91. else cout << "==>aTie game, you both stink.";
  92. cout<<"do you want to play an other game: press 1 else: press 2: ";
  93. cin>>intexit;
  94. if (intexit==2)
  95. exit = false;
  96. cin.ignore();
  97. cin.get();
  98. }
  99.  
  100. return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement