Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/elliotpenson/knight-owl

A chess library in lisp.
https://github.com/elliotpenson/knight-owl

Last synced: 5 days ago
JSON representation

A chess library in lisp.

Awesome Lists containing this project

README

        

#+TITLE: knight-owl
#+AUTHOR: Elliot Penson
#+OPTIONS: num:nil

A chess library in lisp. Defines a data structure for a board,
validates and performs moves, and reads portable game notation.

** Documentation

*** Board

In knight-owl, a chess board is stored as a two-dimensional array
of piece symbols in the form [bw]-[prnbqk]. For example, 'b-n
would indicate a black knight. Empty squares are denoted with nil.

**** ~new-board~

- Description: Evaluate to a fresh 2D array with initial the
chess position.

**** ~duplicate-board~ /board/

- Arguments:
- /board/
- A two-dimensional array of piece symbols.
- Description: Create a new two-dimensional array identical to
the input board.

**** ~print-board~ /board &key stream/

- Arguments:
- /board/
- A two-dimensional array of piece symbols.
- /stream/
- An input stream designator. Defaults to ~t~.
- Description: Write a 2D chess board array to a stream in a
pretty fashion.

**** ~get-square~ /board file rank/

- Arguments:
- /board/
- A two-dimensional array of piece symbols.
- /file/
- An integer.
- /rank/
- An integer.
- Description: Access a chess board x/y location. Note that (setf
get-square) also exists.

*** Movement

**** ~make-move~ /move board whitep/

- Arguments:
- /move/
- A string chess action in standard algebraic notation.
- /board/
- A two-dimensional array of piece symbols.
- /whitep/
- A generalized boolean. Truth value for white, nil for
black.
- Description: Destructively modify the board for the given move.

**** ~valid-move-p~ /move board whitep/

- Arguments:
- /move/
- A string chess action in standard algebraic notation.
- /board/
- A two-dimensional array of piece symbols.
- /whitep/
- A generalized boolean. Truth value for white, nil for
black.
- Description: Determine if a move can legally be performed on a
given board.

**** ~check-p~ /board whitep/

- Arguments:
- /board/
- A two-dimensional array of piece symbols.
- /whitep/
- A generalized boolean. Truth value for white, nil for
black.
- Description: Determines if the king is being attacked.

**** ~checkmate-p~ /board whitep/

- Arguments:
- /board/
- A two-dimensional array of piece symbols.
- /whitep/
- A generalized boolean. Truth value for white, nil for
black.
- Description: Determine if the king is both being attacked and
cannot escape.

**** ~+all-moves+~

- Description: Constant that's defined as a list of all possible
string algebraic notation moves.

*** Portable Game Notation

**** ~pgn-parse~ /stream/

- Arguments:
- /stream/
- An input stream designator
- Description: Parse a single chess game depicted in portable
game notation.

** Move Notation

For general moves, the first character (or lack thereof) indicates
the piece: R for Rook, N for kNight, B for Bishop, Q for Queen, K
for King, and the empty string for pawn. Optionally a file or rank
(or both) may be given after the piece letter to remove
ambiguity. An x comes next if a capture takes place. The next two
characters always represent the destination file [a,z] and rank
[1,8]. If the move includes a pawn promotion, an equals sign and the
letter of the replacement piece are added. Lastly, a plus sign
describes check and the hash symbol checkmate. For castling, O-O and
O-O-O label kingside and queenside castles, respectively.

*** Context-Free Grammar

#+BEGIN_SRC
::= ?
| ???
??
::= R | N | B | Q | K |
::=
::= [a-h]
::= [1-8]
::= x
::= =
::= [#+]
::= |
::= O-O
::= O-O-O
#+END_SRC