Class: Bchess::Game

Inherits:
Object
  • Object
show all
Defined in:
lib/bchess/game.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fen = '') ⇒ Game

Returns a new instance of Game.



5
6
7
8
9
# File 'lib/bchess/game.rb', line 5

def initialize(fen = '')
  @fen = fen
  @board = Board.new(fen)
  @moves = []
end

Instance Attribute Details

#boardObject (readonly)

Returns the value of attribute board.



3
4
5
# File 'lib/bchess/game.rb', line 3

def board
  @board
end

#fenObject (readonly)

Returns the value of attribute fen.



3
4
5
# File 'lib/bchess/game.rb', line 3

def fen
  @fen
end

#movesObject (readonly)

Returns the value of attribute moves.



3
4
5
# File 'lib/bchess/game.rb', line 3

def moves
  @moves
end

Instance Method Details

#add_move(move) ⇒ Object



11
12
13
# File 'lib/bchess/game.rb', line 11

def add_move(move)
  moves << move
end

#validate_gameObject



15
16
17
18
19
# File 'lib/bchess/game.rb', line 15

def validate_game
  moves.all? do |move|
    board.execute(move)
  end
end