On this page:
chess-square?
chess-square
chess-square-rank
chess-square-file
3.1 Occupied Chess Squares
occupied-chess-square?
occupied-chess-square-piece
chess-square-occupy
chess-square-remove-occupant
3.2 Ranks and Files
chess-rank?
chess-rank
chess-rank-index
chess-file?
chess-file
chess-file-index
in-chess-ranks
in-chess-files
3.3 Chess Square Constants
a1
a2
a3
a4
a5
a6
a7
a8
b1
b2
b3
b4
b5
b6
b7
b8
c1
c2
c3
c4
c5
c6
c7
c8
d1
d2
d3
d4
d5
d6
d7
d8
e1
e2
e3
e4
e5
e6
e7
e8
f1
f2
f3
f4
f5
f6
f7
f8
g1
g2
g3
g4
g5
g6
g7
g8
h1
h2
h3
h4
h5
h6
h7
h8
7.5

3 Chess Squares

 (require chess/square) package: chess

A chess square is a single space on a chess board. There are 64 squares. This module exports a constant for each chess square, with a name based on its position:

Examples:
> a8

#<chess-square:a8>

> d4

#<chess-square:d4>

> c7

#<chess-square:c7>

procedure

(chess-square? v)  boolean?

  v : any/c
A predicate for chess squares.

procedure

(chess-square #:rank rank #:file file)  chess-square?

  rank : chess-rank?
  file : chess-file?
Constructs a chess square representing the location at rank and file.

procedure

(chess-square-rank square)  chess-rank?

  square : chess-square?
Returns the chess rank of square.

procedure

(chess-square-file square)  chess-file?

  square : chess-square?
Returns the chess file of square.

3.1 Occupied Chess Squares

An occupied chess square is a combination of a square and a piece. Construct one with chess-square-occupy.

procedure

(occupied-chess-square? v)  boolean?

  v : any/c
A predicate for occupied chess squares.

Returns the chess piece currently occupying square.

procedure

(chess-square-occupy square piece)  occupied-chess-square?

  square : chess-square?
  piece : colored-chess-piece?
Constructs an occupied chess square where square is occupied by piece.

Example:
> (chess-square-occupy d4 white-pawn)

(occupied-chess-square

 #:file (chess-file 3)

 #:piece (colored-chess-piece #:owner #<white> #:type #<pawn>)

 #:rank (chess-rank 3))

Removes the chess piece currently occupying square and returns the unoccupied square.

Examples:
> (define occupied (chess-square-occupy d4 white-pawn))
> (chess-square-remove-occupant occupied)

#<chess-square:d4>

3.2 Ranks and Files

procedure

(chess-rank? v)  boolean?

  v : any/c
A predicate for chess ranks.

procedure

(chess-rank index)  chess-rank?

  index : (integer-in 0 7)
Constructs a chess rank representing the row of spaces at position index, where positions 0 and 1 correspond to the ranks containing white’s starting pieces and positions 6 and 7 correspond to black’s starting ranks.

procedure

(chess-rank-index rank)  (integer-in 0 7)

  rank : chess-rank?
Returns the index of rank. See chess-rank for details on rank numbering.

procedure

(chess-file? v)  boolean?

  v : any/c
A predicate for chess files.

procedure

(chess-file index)  chess-file?

  index : (integer-in 0 7)
Constructs a chess file representing the column of spaces at position index, where position 0 corresponds to the A file and position 7 corresponds to the H file.

procedure

(chess-file-index file)  (integer-in 0 7)

  file : chess-file?
Returns the index of file. See chess-file for details on file numbering.

procedure

(in-chess-ranks [#:descending? descending?])

  (sequence/c chess-rank?)
  descending? : boolean? = #f
Returns a sequence of all chess ranks. If descending? is true, the ranks are listed from top to bottom, otherwise they are listed from bottom to top.

procedure

(in-chess-files [#:right-to-left? right-to-left?])

  (sequence/c chess-file?)
  right-to-left? : boolean? = #f
Returns a sequence of all chess files. If right-to-left? is true, the files are listed from right to left (from the H file to the A file). Otherwise, they are listed from left to right.

3.3 Chess Square Constants

value

a1 : chess-square?

value

a2 : chess-square?

value

a3 : chess-square?

value

a4 : chess-square?

value

a5 : chess-square?

value

a6 : chess-square?

value

a7 : chess-square?

value

a8 : chess-square?

value

b1 : chess-square?

value

b2 : chess-square?

value

b3 : chess-square?

value

b4 : chess-square?

value

b5 : chess-square?

value

b6 : chess-square?

value

b7 : chess-square?

value

b8 : chess-square?

value

c1 : chess-square?

value

c2 : chess-square?

value

c3 : chess-square?

value

c4 : chess-square?

value

c5 : chess-square?

value

c6 : chess-square?

value

c7 : chess-square?

value

c8 : chess-square?

value

d1 : chess-square?

value

d2 : chess-square?

value

d3 : chess-square?

value

d4 : chess-square?

value

d5 : chess-square?

value

d6 : chess-square?

value

d7 : chess-square?

value

d8 : chess-square?

value

e1 : chess-square?

value

e2 : chess-square?

value

e3 : chess-square?

value

e4 : chess-square?

value

e5 : chess-square?

value

e6 : chess-square?

value

e7 : chess-square?

value

e8 : chess-square?

value

f1 : chess-square?

value

f2 : chess-square?

value

f3 : chess-square?

value

f4 : chess-square?

value

f5 : chess-square?

value

f6 : chess-square?

value

f7 : chess-square?

value

f8 : chess-square?

value

g1 : chess-square?

value

g2 : chess-square?

value

g3 : chess-square?

value

g4 : chess-square?

value

g5 : chess-square?

value

g6 : chess-square?

value

g7 : chess-square?

value

g8 : chess-square?

value

h1 : chess-square?

value

h2 : chess-square?

value

h3 : chess-square?

value

h4 : chess-square?

value

h5 : chess-square?

value

h6 : chess-square?

value

h7 : chess-square?

value

h8 : chess-square?

Constants for each chess square.