Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. ;--------------------------------------------------------------------------------------------------------
  2. ; PROCEDURE TO DECIDE THE COMPUTER'S MOVES
  3. ;--------------------------------------------------------------------------------------------------------
  4. ; GOTO PLAYER2TURN
  5. player2Turn PROC
  6.  
  7. mov esi, offset player1board
  8.  
  9. cmp computerguess, 0
  10. je guessUp
  11. cmp computerguess, 1
  12. je guessDown
  13. cmp computerguess, 2
  14. je guessLeft
  15. cmp computerguess, 3
  16. je guessRight
  17. jmp generatePoints
  18.  
  19. guessUp:
  20. cmp ypoint, 0
  21. je generatePoints
  22.  
  23. inc ypoint
  24. call checkHitOrNot
  25.  
  26. guessDown:
  27. cmp ypoint, 9
  28. je generatePoints
  29.  
  30. dec ypoint
  31. call checkHitOrNot
  32.  
  33. guessLeft:
  34. cmp xpoint, 9
  35. je generatePoints
  36.  
  37. inc xpoint
  38. call checkHitOrNot
  39.  
  40. guessRight:
  41. cmp xpoint, 0
  42. je generatePoints
  43.  
  44. dec xpoint
  45. call checkHitOrNot
  46.  
  47.  
  48. ; Gets a random number from 0 - 9 as the x and y points
  49. generatePoints:
  50. mov eax, 10
  51. call RandomRange
  52. mov xpoint, al
  53. call RandomRange
  54. mov ypoint, al
  55.  
  56. ; Checks if the point was a hit or not
  57. checkHitOrNot:
  58.  
  59. call coordinateToIndex
  60. mov ebx, 0
  61. movzx ebx, shipindex
  62. add esi, ebx
  63.  
  64. ; If its not ASCII 176 (empty spot), randomizes the points again
  65. mov bl, 176
  66. cmp [esi], bl
  67. jne itsAlreadyPicked
  68.  
  69. ; If there is a ship, calls player2Hits. If not, calls player2Misses
  70. mov bl, 254
  71. cmp [esi], bl
  72. je player2Hits
  73. jmp player2Misses
  74.  
  75. ; If the spot has already been picked
  76. itsAlreadyPicked:
  77. jmp generatePoints
  78.  
  79.  
  80. player2Hits:
  81. inc player2score
  82. mov ebx, 0
  83. mov bl, 88
  84. mov [esi], bl
  85. cmp player2score, 17
  86. je player2Wins
  87. jmp endOfTurn
  88.  
  89.  
  90. player2Misses:
  91.  
  92. mov ebx, 0
  93. mov bl, 79
  94. mov [esi], bl
  95. jmp endOfTurn
  96.  
  97.  
  98. player2Wins:
  99. ; CALL THE LOSE WINDOW
  100.  
  101.  
  102.  
  103. endOfTurn:
  104. call displayPlayer1Board
  105. ret
  106.  
  107.  
  108.  
  109.  
  110. ret
  111. player2Turn ENDP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement