Crate transforms algebraic chess notation into software readable structs and
vice versa. Parsed chess notation for each turn is stored within Turn
struct.
To parse a certain chess turn, such as d2xe3
, store it in form of &str
and
pass it as an argument into Turn::try_from()
function.
Turn
is an enum with two elements:
Castling
- a struct which describes castling turnMove
- a struct which describes every other possible turn
Turn::Castling(Castling {
r#type: CastlingType::Short,
flags: Flag::NONE,
});
Turn::Move (Move {
who: Piece::Pawn,
dst: Square::D6,
flags: Flag::NONE,
src: None,
promotion: None,
});
Turn::Move (Move {
who: Piece::Pawn,
dst: Square::E8,
flags: Flag::CHECK | Flag::CAPTURE,
src: Some(vec![Square::D7]),
promotion: Some(Piece::Bishop),
});
Turn::Move (Move {
who: Piece::Knight,
dst: Square::B3,
flags: Flag::CHECKMATE,
src: Some(Square::get_file('a').unwrap()), // Vector of 'Ax' squares
promotion: None,
});
-
Square notation should use lowercase alphabetic characters
- Valid:
a1
,a2
...h7
,h8
.
- Valid:
-
Castling notation can be written with both
0
andO
- Valid example:
0-0-0
orO-O
- When
Castling
turn is printed out, it will be printed with0
notation
- Valid example:
-
Notation for pieces:
K
: KingQ
: QueenR
: RookB
: BishopN
: Knight- Pawns are indicated by the absence of the letter
-
Capture is annotated with a lowercase
x
character- Valid example:
Qxd3
- Valid example:
-
Check is annotated with a
+
character- Valid example:
Qd3+
- Valid example:
-
Checkmate is annotated with a
#
character- Valid example:
Qd3#
- Valid example:
-
Pawn promotion is annoted with
=
symbol followed by a piece to which pawn is promoted to- Pawn promotion is valid only for ranks
8
and1
- Valid example:
g8=Q
- Pawn promotion is valid only for ranks
-
Comments
??
,!!
,?
,!
,!?
,?!
are allowed only at the end of the turn- Valid example:
a1=B??
- Invalid example:
??a1=B
- Valid example:
I don't really play chess that much, but I needed something to practice my Rust skills, so this was sort of a fun project. This particular crate was created for the purpose of Pacifist chess simulation.