Class: TTT::MoveGenerator
- Inherits:
-
Object
- Object
- TTT::MoveGenerator
- Defined in:
- lib/games/tictactoe/move_generator.rb
Instance Attribute Summary collapse
-
#game ⇒ Object
Returns the value of attribute game.
Instance Method Summary collapse
- #available_choices ⇒ Object
- #computer? ⇒ Boolean
- #current_player ⇒ Object
- #difficult? ⇒ Boolean
- #easy? ⇒ Boolean
- #game_module ⇒ Object
- #get_move ⇒ Object
- #get_player_choice(game) ⇒ Object
- #human? ⇒ Boolean
- #input_helper ⇒ Object
- #perfect_move ⇒ Object
- #random_move ⇒ Object
Instance Attribute Details
#game ⇒ Object
Returns the value of attribute game.
6 7 8 |
# File 'lib/games/tictactoe/move_generator.rb', line 6 def game @game end |
Instance Method Details
#available_choices ⇒ Object
36 37 38 |
# File 'lib/games/tictactoe/move_generator.rb', line 36 def available_choices game.available_choices end |
#computer? ⇒ Boolean
56 57 58 |
# File 'lib/games/tictactoe/move_generator.rb', line 56 def computer? game.current_player_computer? end |
#current_player ⇒ Object
44 45 46 |
# File 'lib/games/tictactoe/move_generator.rb', line 44 def current_player game.current_player end |
#difficult? ⇒ Boolean
60 61 62 |
# File 'lib/games/tictactoe/move_generator.rb', line 60 def difficult? game.current_player_difficult_computer? end |
#easy? ⇒ Boolean
64 65 66 |
# File 'lib/games/tictactoe/move_generator.rb', line 64 def easy? game.current_player_easy_computer? end |
#game_module ⇒ Object
40 41 42 |
# File 'lib/games/tictactoe/move_generator.rb', line 40 def game_module game.game_module end |
#get_move ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/games/tictactoe/move_generator.rb', line 13 def get_move if human? input_helper.get_player_choice(game) elsif computer? input_helper.computer_choosing_graphic if difficult? perfect_move elsif easy? random_move end end end |
#get_player_choice(game) ⇒ Object
8 9 10 11 |
# File 'lib/games/tictactoe/move_generator.rb', line 8 def get_player_choice(game) @game = game get_move end |
#human? ⇒ Boolean
52 53 54 |
# File 'lib/games/tictactoe/move_generator.rb', line 52 def human? game.current_player_human? end |
#input_helper ⇒ Object
48 49 50 |
# File 'lib/games/tictactoe/move_generator.rb', line 48 def input_helper game.input_helper end |
#perfect_move ⇒ Object
26 27 28 29 30 |
# File 'lib/games/tictactoe/move_generator.rb', line 26 def perfect_move minimax = game_module::Minimax.new(game.board, game.number_of_turns_taken, game.player_1_value, game.player_2_value) minimax.run_minimax minimax.choice end |
#random_move ⇒ Object
32 33 34 |
# File 'lib/games/tictactoe/move_generator.rb', line 32 def random_move available_choices.sample end |