Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. class Opponent < SomePlayer
  2. def initialize(board)
  3. super(board)
  4. @name = 'Computer'
  5. @positions = []
  6. @computed_options = []
  7. end
  8.  
  9. def shoot
  10. available_choices = get_available_options
  11. coordinate = ShootingCompetitiveCoordinateInput.new(available_choices).fetch
  12.  
  13. # if shoot successful
  14. if @board.set_shoot(coordinate)
  15. if @positions.size == 3
  16. @computed_options = []
  17. else
  18. @positions << coordinate
  19. @computed_options = Board.clean_outer(HellTetrisStrategy.new(@positions, @positions.size + 1).places)
  20. end
  21. end
  22. update_computed_options(coordinate)
  23. end
  24.  
  25. private
  26.  
  27. def update_computed_options(coordinate)
  28. @computed_options.delete(coordinate) # can work without checking
  29. @possible_choices.delete(coordinate)
  30. unless get_computed_options.any?
  31. @positions = []
  32. @computed_options = []
  33. end
  34. end
  35.  
  36. def get_available_options
  37. get_computed_options.any? ? get_computed_options : @possible_choices
  38. end
  39.  
  40. def get_computed_options
  41. @possible_choices & @computed_options
  42. end
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement