Class: TTT::Interface::CLI::HumanPlayer

Inherits:
Player
  • Object
show all
Defined in:
lib/ttt/interface/cli/players.rb

Instance Attribute Summary

Attributes inherited from Player

#cli, #game, #marker

Instance Method Summary collapse

Methods inherited from Player

#initialize

Constructor Details

This class inherits a constructor from TTT::Interface::CLI::Player

Instance Method Details

#available_moves_regexObject



47
48
49
50
# File 'lib/ttt/interface/cli/players.rb', line 47

def available_moves_regex
  moves = game.available_moves
  /^[#{moves.join}]$/
end

#list_available_movesObject



43
44
45
# File 'lib/ttt/interface/cli/players.rb', line 43

def list_available_moves
  game.available_moves.join(', ')
end

#take_turnObject



36
37
38
39
40
41
# File 'lib/ttt/interface/cli/players.rb', line 36

def take_turn
  fileout.puts "The nine squares consecutively map to a number. "\
    "Topleft starts at 1, topright continues with 3, and bottomright ends with 9."
  move = prompt "Where would you like to move? (#{list_available_moves}) ", :validate => available_moves_regex
  game.mark move.to_i
end