Class: NeuroGammon::Game
- Inherits:
-
Object
- Object
- NeuroGammon::Game
- Defined in:
- lib/neuro_gammon/game.rb
Instance Attribute Summary collapse
-
#black_player ⇒ Object
readonly
Returns the value of attribute black_player.
-
#board_states ⇒ Object
readonly
Returns the value of attribute board_states.
-
#colour_moved ⇒ Object
readonly
Returns the value of attribute colour_moved.
-
#dice_states ⇒ Object
readonly
Returns the value of attribute dice_states.
-
#moves ⇒ Object
readonly
Returns the value of attribute moves.
-
#white_player ⇒ Object
readonly
Returns the value of attribute white_player.
-
#winner_colour ⇒ Object
Returns the value of attribute winner_colour.
Instance Method Summary collapse
- #add_board_state(state) ⇒ Object
- #add_dice_state(dice) ⇒ Object
- #add_move(move) ⇒ Object
-
#initialize(white_player, black_player) ⇒ Game
constructor
A new instance of Game.
Constructor Details
#initialize(white_player, black_player) ⇒ Game
Returns a new instance of Game.
15 16 17 18 19 20 21 22 |
# File 'lib/neuro_gammon/game.rb', line 15 def initialize white_player,black_player @black_player=black_player @white_player=white_player @board_states=[] @moves=[] @dice_states=[] @colour_moved=[] end |
Instance Attribute Details
#black_player ⇒ Object (readonly)
Returns the value of attribute black_player.
11 12 13 |
# File 'lib/neuro_gammon/game.rb', line 11 def black_player @black_player end |
#board_states ⇒ Object (readonly)
Returns the value of attribute board_states.
8 9 10 |
# File 'lib/neuro_gammon/game.rb', line 8 def board_states @board_states end |
#colour_moved ⇒ Object (readonly)
Returns the value of attribute colour_moved.
13 14 15 |
# File 'lib/neuro_gammon/game.rb', line 13 def colour_moved @colour_moved end |
#dice_states ⇒ Object (readonly)
Returns the value of attribute dice_states.
9 10 11 |
# File 'lib/neuro_gammon/game.rb', line 9 def dice_states @dice_states end |
#moves ⇒ Object (readonly)
Returns the value of attribute moves.
10 11 12 |
# File 'lib/neuro_gammon/game.rb', line 10 def moves @moves end |
#white_player ⇒ Object (readonly)
Returns the value of attribute white_player.
12 13 14 |
# File 'lib/neuro_gammon/game.rb', line 12 def white_player @white_player end |
#winner_colour ⇒ Object
Returns the value of attribute winner_colour.
7 8 9 |
# File 'lib/neuro_gammon/game.rb', line 7 def winner_colour @winner_colour end |
Instance Method Details
#add_board_state(state) ⇒ Object
24 25 26 |
# File 'lib/neuro_gammon/game.rb', line 24 def add_board_state state self.board_states << Marshal.load(Marshal.dump(state)) end |
#add_dice_state(dice) ⇒ Object
28 29 30 |
# File 'lib/neuro_gammon/game.rb', line 28 def add_dice_state dice dice_states << Marshal.load(Marshal.dump(dice)) end |
#add_move(move) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/neuro_gammon/game.rb', line 32 def add_move move moves << Marshal.load(Marshal.dump(move)) #TODO test for a valid range for coming on and bearing off, throw Exceptions otherwise, and harden unit tests for this if move[0]==-1 #come on colour_moved << (move[1]>17 ? Board::WHITE : Board::BLACK) elsif move[1]==-1 #bear off colour_moved << (move[0]<=5 ? Board::WHITE : Board::BLACK) else colour_moved << (move[0]-move[1]>0 ? Board::WHITE : Board::BLACK) end end |