class LxChess::Board

Overview

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

Included Modules

Defined in:

lx_chess/board.cr

Constant Summary

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

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(width : Int16 = 8, height : Int16 = 8) #

[View source]

Class Method Detail

def self.cord(index : Int, width = 8) #

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


[View source]

Instance Method Detail

def [](index : Int) #

Retrieve a piece at an index


[View source]
def [](cord : String) #

Retrieve a piece at a human cord ex: a1


[View source]
def []=(index : Int, piece : Piece | Nil) #

Set a piece on the board at a certain index


[View source]
def []=(cord : String, piece : Piece | Nil) #

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


[View source]
def at(x : Int, y : Int) #

Retrieve a piece at an x and y cord


[View source]
def border_left(index) #

Border to the left of a given index


[View source]
def border_right(index) #

Border to the right of a given index


[View source]
def cord(index : Int) #

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


[View source]
def dist_left(index) #

Distance to the left border from an index


[View source]
def dist_right(index) #

Distance to the right border from an index


[View source]
def each(&) #
Description copied from module Enumerable(LxChess::Piece?)

Must yield this collection's elements to the block.


[View source]
def file(index : Int16) #

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


[View source]
def height : Int16 #

[View source]
def height=(height : Int16) #

[View source]
def index_of(x : Int, y : Int) #

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


[View source]
def index_of(cord : String) #

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


[View source]
def indexes_of(cords : Array(String)) #

[View source]
def move(from : String | Int16, to : String | Int16) #

Move a piece from a position to a new position


[View source]
def pieces(color : Nil | Symbol = nil) #

Select pieces from the board by specifying an option color


[View source]
def rank(index : Int16) #

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


[View source]
def rel_index(index : Int, x : Int, y : Int) #

[View source]
def squares : Array(LxChess::Piece?) #

[View source]
def squares=(squares : Array(Nil | LxChess::Piece)) #

[View source]
def width : Int16 #

[View source]
def width=(width : Int16) #

[View source]