class ConnectNGame::Human
The Human
player simply makes carbon based moves.
Public Class Methods
new(name = "Human")
click to toggle source
Build the player
Calls superclass method
# File lib/connect_n_game/human.rb, line 9 def initialize(name = "Human") super(name, "An actual player.", :carbon) end
Public Instance Methods
legal_moves(rack)
click to toggle source
Get a string of legal moves.
Parameters
-
rack - the playing area.
Returns
-
A string with all possible legal moves.
# File lib/cli/cli_human.rb, line 30 def legal_moves(rack) legal = rack.channel_names.reject do |name| channel = Utl.name_to_channel(name) rack.channel_full?(channel) end legal.join("") end
losers_comments()
click to toggle source
The agony of defeat
# File lib/connect_n_game/human.rb, line 21 def losers_comments "Too bad #{name}, you lose. Hang your head in shame." end
make_move(game, piece)
click to toggle source
Make a move. This player moves with DNA and other stuff too.
Parameters
-
game - the game being played.
-
piece - the piece to be played, 1 or 2.
Returns
-
A move, 1 .. rack.width
# File lib/cli/cli_human.rb, line 14 def make_move(game, piece) begin legal = legal_moves(game.rack) puts "Player #{piece} select [#{legal}] " reply = gets[0].upcase channel = Utl.name_to_channel(reply) end until channel && legal.include?(reply) channel end
winners_comments()
click to toggle source
The thrill of victory.
# File lib/connect_n_game/human.rb, line 16 def winners_comments "Congratulations #{name}! You're our winner today!" end