class

LxChess::Board

Inherits Enumerable < Reference < Object

A Board represents the squares of a chess board. it also handles coversion of indicies <=> cords. The internal representation is a contiguous array

Constants

LETTERS = ('a'..'z').to_a

Constructors

new(width : Int16 = 8, height : Int16 = 8)
Source

Class methods

cord(index : Int, width = 8)

Convert an index into a human coordinate (ex: a1)

Source

Instance methods

[](index : Int)

Retrieve a piece at an index

Source
[](cord : String)

Retrieve a piece at a human cord ex: a1

Source
[]=(index : Int, piece : Piece | Nil)

Set a piece on the board at a certain index

Source
[]=(cord : String, piece : Piece | Nil)

Set a piece on the board at a certain human readable cord

Source
at(x : Int, y : Int)

Retrieve a piece at an x and y cord

Source
border_left(index)

Border to the left of a given index

Source
border_right(index)

Border to the right of a given index

Source
cord(index : Int)

Convert an index into a human coordinate (ex: a1)

Source
dist_left(index)

Distance to the left border from an index

Source
dist_right(index)

Distance to the right border from an index

Source
each

Must yield this collection's elements to the block.

Source
file(index : Int16)

The file of a given index file(4) # => 4 file(8) # => 0

Source
height
Source
height=(height : Int16)
Source
index_of(x : Int, y : Int)

Convert an x and y position into an index. Ex: 4, 4 => 36

Source
index_of(cord : String)

Convert human cord into an index on the board. Ex: a1 => 0

Source
indexes_of(cords : Array(String))
Source
move(from : String | Int16, to : String | Int16)

Move a piece from a position to a new position

Source
pieces(color : Nil | Symbol = nil)

Select pieces from the board by specifying an option color

Source
rank(index : Int16)

The rank of a given index rank(4) # => 0 rank(8) # => 1

Source
rel_index(index : Int, x : Int, y : Int)
Source
squares
Source
squares=(squares : Array(Nil | LxChess::Piece))
Source
width
Source
width=(width : Int16)
Source