A Shogi game serialization/deserialization library in CSA format. CSA format is a plaintext format for recording Shogi games. This library supports parsing CSA-formatted string as well as composing CSA-formatted string from structs. Detail about CSA format is found at here.
Below is an example of parsing CSA-formatted string into structs.
```rust use std::time::Duration; use csa::{parse_csa, Action, Color, GameRecord, MoveRecord, PieceType, Square};
let csa_str = "\ V2.2 N+NAKAHARA N-YONENAGA $EVENT:13th World Computer Shogi Championship PI + +2726FU T12 ";
let game = parsecsa(csastr).expect("failed to parse the csa content"); asserteq!(game.blackplayer, Some("NAKAHARA".tostring())); asserteq!(game.whiteplayer, Some("YONENAGA".tostring())); asserteq!(game.event, Some("13th World Computer Shogi Championship".tostring())); asserteq!(game.moves[0], MoveRecord{ action: Action::Move(Color::Black, Square::new(2, 7), Square::new(2, 6), PieceType::Pawn), time: Some(Duration::fromsecs(12)) }); ```
In contrast, structs can be composed into CSA-formatted string.
```rust use std::time::Duration; use csa::{ Action, Color, GameRecord, MoveRecord, PieceType, Square};
let mut g = GameRecord::default(); g.blackplayer = Some("NAKAHARA".tostring()); g.whiteplayer = Some("YONENAGA".tostring()); g.event = Some("13th World Computer Shogi Championship".tostring()); g.moves.push(MoveRecord { action: Action::Move( Color::Black, Square::new(2, 7), Square::new(2, 6), PieceType::Pawn, ), time: Some(Duration::fromsecs(5)), }); g.moves.push(MoveRecord { action: Action::Toryo, time: None, });
let csa_str = "\ V2.2 N+NAKAHARA N-YONENAGA $EVENT:13th World Computer Shogi Championship PI + +2726FU T5 %TORYO ";
asserteq!(csastr, g.to_string()); ```
csa-rs
is licensed under the MIT license. Please read the LICENSE file in this repository for more information.