Class: RGnuchess::Board

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

Overview

Board represents a chessboard state (just the pieces, not the castling opportunities or en passant capture opportunities).

Defined Under Namespace

Classes: Piece

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(board = nil) ⇒ Board

Returns a new instance of Board.



95
96
97
98
99
100
101
102
# File 'lib/rgnuchess.rb', line 95

def initialize(board=nil)
  unless board
    @board=Array.new(8)
    @board.map!{|x| Array.new(8,Piece.new())}
  else
    @board = board
  end
end

Class Method Details

.parse(lines) ⇒ Object

Parse a board from Gnuchess



92
93
94
# File 'lib/rgnuchess.rb', line 92

def Board.parse(lines)
  Board.new( lines.map{|line| line.chomp.scan(/[^ ]/).map{|char| Piece.parse(char)}} )
end

Instance Method Details

#to_sObject



103
104
105
106
107
# File 'lib/rgnuchess.rb', line 103

def to_s
  @board.map do |row|
    row.map{|p| p.to_s}.join(" ")
  end.join("\n")
end