Crates.io | chess-notation-parser |
lib.rs | chess-notation-parser |
version | 0.2.3 |
source | src |
created_at | 2022-06-05 20:01:10.356546 |
updated_at | 2022-06-10 08:49:47.464493 |
description | Algebraic chess notation parser |
homepage | |
repository | https://github.com/Rqnsom/chess-notation-parser |
max_upload_size | |
id | 600318 |
size | 57,705 |
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 turnCastling
turn0-0
will be translated to:Turn::Castling(Castling {
r#type: CastlingType::Short,
flags: Flag::NONE,
});
Move
turnsd6
will be translated to:Turn::Move (Move {
who: Piece::Pawn,
dst: Square::D6,
flags: Flag::NONE,
src: None,
promotion: None,
});
d7xe8=B+?
will be translated to:Turn::Move (Move {
who: Piece::Pawn,
dst: Square::E8,
flags: Flag::CHECK | Flag::CAPTURE,
src: Some(vec![Square::D7]),
promotion: Some(Piece::Bishop),
});
Nab3#
will be translated to: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
a1
, a2
... h7
, h8
.Castling notation can be written with both 0
and O
0-0-0
or O-O
Castling
turn is printed out, it will be printed with 0
notationNotation for pieces:
K
: KingQ
: QueenR
: RookB
: BishopN
: KnightCapture is annotated with a lowercase x
character
Qxd3
Check is annotated with a +
character
Qd3+
Checkmate is annotated with a #
character
Qd3#
Pawn promotion is annoted with =
symbol followed by a piece to which
pawn is promoted to
8
and 1
g8=Q
Comments ??
, !!
, ?
, !
, !?
, ?!
are allowed only at the end of
the turn
a1=B??
??a1=B
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.