Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Opponent < SomePlayer
- def initialize(board)
- super(board)
- @name = 'Computer'
- @positions = []
- @computed_options = []
- end
- def shoot
- available_choices = get_available_options
- coordinate = ShootingCompetitiveCoordinateInput.new(available_choices).fetch
- # if shoot successful
- if @board.set_shoot(coordinate)
- if @positions.size == 3
- @computed_options = []
- else
- @positions << coordinate
- @computed_options = Board.clean_outer(HellTetrisStrategy.new(@positions, @positions.size + 1).places)
- end
- end
- update_computed_options(coordinate)
- end
- private
- def update_computed_options(coordinate)
- @computed_options.delete(coordinate) # can work without checking
- @possible_choices.delete(coordinate)
- unless get_computed_options.any?
- @positions = []
- @computed_options = []
- end
- end
- def get_available_options
- get_computed_options.any? ? get_computed_options : @possible_choices
- end
- def get_computed_options
- @possible_choices & @computed_options
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement