Guest User

Untitled

a guest
Feb 21st, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. public String move (int square) {
  2.  
  3. String whosTurn = getToMove();
  4.  
  5.  
  6.  
  7. if(square == 1)
  8. {
  9. if(positions[0][0] == "X" || positions[0][0] == "O" )
  10. {
  11. throw new IllegalArgumentException();
  12. }
  13. positions[0][0] = whosTurn;
  14. }
  15.  
  16. else if(square == 2 )
  17. {
  18. if(positions[0][1] == "X" || positions[0][1] == "O" )
  19. {
  20. throw new IllegalArgumentException();
  21. }
  22. positions[0][1] = whosTurn;
  23. }
  24.  
  25. else if(square == 3)
  26. {
  27. if(positions[0][2] == "X" || positions[0][2] == "O" )
  28. {
  29. throw new IllegalArgumentException();
  30. }
  31. positions[0][2] = whosTurn;
  32. }
  33.  
  34. else if(square == 4)
  35. {
  36. if(positions[1][0] == "X" || positions[1][0] == "O" )
  37. {
  38. throw new IllegalArgumentException();
  39. }
  40. positions[1][0] = whosTurn;
  41. }
  42. else if(square == 5)
  43. {
  44. if(positions[1][1] == "X" || positions[1][1] == "O" )
  45. {
  46. throw new IllegalArgumentException();
  47. }
  48. positions[1][1] = whosTurn;
  49. }
  50. else if(square == 6)
  51. {
  52. if(positions[1][2] == "X" || positions[1][2] == "O" )
  53. {
  54. throw new IllegalArgumentException();
  55. }
  56. positions[1][2] = whosTurn;
  57. }
  58. else if(square == 7)
  59. {
  60. if(positions[2][0] == "X" || positions[2][0] == "O" )
  61. {
  62. throw new IllegalArgumentException();
  63. }
  64. positions[2][0] = whosTurn;
  65. }
  66. else if(square == 8)
  67. {
  68. if(positions[2][1] == "X" || positions[2][1] == "O" )
  69. {
  70. throw new IllegalArgumentException();
  71. }
  72. positions[2][1] = whosTurn;
  73. }
  74. else if(square == 9)
  75. {
  76. if(positions[2][2] == "X" || positions[2][2] == "O" )
  77. {
  78. throw new IllegalArgumentException();
  79. }
  80. positions[2][2] = whosTurn;
  81. }
  82.  
  83. if (isWon() == true || isDrawn() == true)
  84. {
  85. throw new IllegalArgumentException();
  86. }
  87.  
  88.  
  89. if (square < 1 || square > 9)
  90. {
  91. throw new IllegalArgumentException();
  92.  
  93. }
  94.  
  95. count++;
  96. // whosTurn = getToMove();
  97. isWon();
  98. isDrawn();
  99. return whosTurn;
  100.  
  101.  
  102. }
Add Comment
Please, Sign In to add comment