chess/algebraic_notation
This module provides functionality to generate Standard Algrebaic Notation for chess moves.
Here are some examples of SAN:
e4
“Pawn to E4”
Qxd7
“Queen takes D7”
exd3+
“E-Pawn takes D3, check”
Nac3
“Knight A2 to C3”
Formatting rules
The formatting is generated as follows:
(<standard-move> | 'O-O' | 'O-O-O')<checks>
where:
'O-O'
refers to a short castle'O-O-O'
refers to a long castle<checks>
is:'#'
if this move checkmates the enemy king'+'
if this move checks the enemy king- otherwise empty
<standard-move>
is defined as:
<figure><disambiguation><takes><destination><promotion>
where: (cases are processed from top to bottom)
<figure>
is:- empty for pawn
'N'
for knight'B'
for bishop'R'
for rook'Q'
for queen'K'
for king
<disambiguation>
is:<file>
if the moved figure is a pawn and it captures an enemy figure- empty if moved figure is unambigous
<file>
if moved figure is ambigous and the ambigous figures are on different files<row>
if moved figure is ambigous and the ambigous figures are on different rows<square>
otherwise
<takes>
is:'x'
if a capture takes place- empty otherwise
<destination>
is the<square>
the figure is moved to<promotion>
is:'='<figure>
if a pawn is promoting to<figure>
- empty otherwise
Types
An error returned by describe
.
pub type DescribeError {
GameAlreadyOver
ProvidedMoveIsIllegal
}
Constructors
-
GameAlreadyOver
Tried to describe a move, which belongs to a game that is already over.
-
ProvidedMoveIsIllegal
Tried to describe a move, which is not legal.
Values
pub fn describe(
game game: chess.GameState,
move move: chess.Move,
) -> Result(String, DescribeError)
Describes the given move
using Standard Algebraic Notation.
See the module description for the formatting rules and examples.
game
is the state before executing the move.
Errors if the game is already over, or the provided move
not legal.