Class: TTT::MoveGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/games/tictactoe/move_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#gameObject

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_choicesObject



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_playerObject



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_moduleObject



40
41
42
# File 'lib/games/tictactoe/move_generator.rb', line 40

def game_module
  game.game_module
end

#get_moveObject



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_helperObject



48
49
50
# File 'lib/games/tictactoe/move_generator.rb', line 48

def input_helper
  game.input_helper
end

#perfect_moveObject



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_moveObject



32
33
34
# File 'lib/games/tictactoe/move_generator.rb', line 32

def random_move
  available_choices.sample
end