class ConnectNGame::Player

The abstract Player class of the connect_n_game.
Responsibility

Attributes

players[R]

The list of available players.

description[R]

The description of this player.

name[R]

The name of this player.

type[R]

The type of this player: :carbon or :silicon

Public Class Methods

new(name, description, type) click to toggle source

Do the common player setup
Parameters

  • name - The name of the player.

  • description - A witty description of the player.

  • type - :carbon or :silicon


Returns

  • An instance of Player

# File lib/connect_n_game/player.rb, line 35
def initialize(name, description, type)
   fail "Invalid type #{type}" unless [:carbon, :silicon].include?(type)
   @name, @description, @type = name, description, type
end

Public Instance Methods

carbon?() click to toggle source

Is this an organic life-form?

# File lib/connect_n_game/player.rb, line 46
def carbon?
  type == :carbon
end
make_move(_game, piece) click to toggle source

Make a move. This is dummy code for testing only.
Parameters

  • _game - the game being played - not used here.

  • piece - the piece to be played, 1 or 2.


Returns

  • A move, 1 .. rack.width

# File lib/connect_n_game/player.rb, line 56
def make_move(_game, piece)
  piece
end
silicon?() click to toggle source

Is this an automaton?

# File lib/connect_n_game/player.rb, line 41
def silicon?
  type == :silicon
end