Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. cout<<"enter choice.1 or 2";
  2. cin>>choice;
  3.  
  4. player=(player%2)?1:2;
  5.  
  6. mark=(player == 1) ? 'X' : 'O';
  7.  
  8. char square[10] = {'o','1','2','3','4','5','6','7','8','9'};
  9. int checkwin();
  10. void board();
  11.  
  12. int main()
  13. {
  14. int player = 1,i,choice;
  15. char mark;
  16. clrscr();
  17. do
  18. {
  19. board();
  20. player=(player%2)?1:2; //<<--- This part I don't understand
  21. cout << "Player " << player << ", enter a number: ";
  22. cin >> choice;
  23. mark=(player == 1) ? 'X' : 'O'; //<<--- This part I don't understand
  24. if (choice == 1 && square[1] == '1')
  25. square[1] = mark;
  26. else if (choice == 2 && square[2] == '2')
  27. square[2] = mark;
  28. else if (choice == 3 && square[3] == '3')
  29. square[3] = mark;
  30. else if (choice == 4 && square[4] == '4')
  31. square[4] = mark;
  32. else if (choice == 5 && square[5] == '5')
  33. square[5] = mark;
  34. else if (choice == 6 && square[6] == '6')
  35. square[6] = mark;
  36. else if (choice == 7 && square[7] == '7')
  37. square[7] = mark;
  38. else if (choice == 8 && square[8] == '8')
  39. square[8] = mark;
  40. else if (choice == 9 && square[9] == '9')
  41. square[9] = mark;
  42. else
  43. {
  44. cout<<"Invalid move ";
  45. player--;
  46. getch();
  47. }
  48. i=checkwin();
  49. player++;
  50. }while(i==-1);
  51. board();
  52. if(i==1)
  53. cout<<"==>aPlayer "<<--player<<" win ";
  54. else
  55. cout<<"==>aGame draw";
  56. getch();
  57. return 0;
  58.  
  59. mark = (player == 1) ? 'X' : 'O';
  60.  
  61. if(player == 1)
  62. {
  63. mark = 'X';
  64. }
  65. else
  66. {
  67. mark = 'O';
  68. }
  69.  
  70. var = cond ? x : y;
  71.  
  72. if (cond) {
  73. var = x;
  74. } else {
  75. var = y;
  76. }
  77.  
  78. player=(player%2)?1:2; //<<--- This part I don't understand
  79.  
  80. player(1) -> 1
  81. player(2) -> 0
  82. player(3) -> 1
  83. player(4) -> 0
  84. ...
  85.  
  86. player = result ? 1 : 2;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement