class ConnectNGame::Player
The abstract Player
class of the connect_n_game.
Responsibility
-
This mostly abstract class is responsible for specifying the shared behavior of all the sorts of players, both human and automaton. This is where moves are generated, victory celebrated, and defeat mourned.
Attributes
The list of available players.
The description of this player.
The name of this player.
The type of this player: :carbon or :silicon
Public Class Methods
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
Is this an organic life-form?
# File lib/connect_n_game/player.rb, line 46 def carbon? type == :carbon end
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
Is this an automaton?
# File lib/connect_n_game/player.rb, line 41 def silicon? type == :silicon end