#shogi #parser #csa

csa

A Shogi game serialization/deserialization library in CSA format

7 releases (breaking)

0.6.1 Aug 15, 2021
0.6.0 Nov 14, 2020
0.5.0 Jan 1, 2020
0.4.0 Jan 1, 2020
0.1.0 Jun 24, 2017

#297 in Game dev

Download history 60/week @ 2021-08-11 7/week @ 2021-08-18 3/week @ 2021-08-25 6/week @ 2021-09-08 30/week @ 2021-09-15 9/week @ 2021-09-22 28/week @ 2021-09-29 2/week @ 2021-10-06 3/week @ 2021-10-13 13/week @ 2021-10-20 2/week @ 2021-10-27 27/week @ 2021-11-03 37/week @ 2021-11-10 33/week @ 2021-11-17 28/week @ 2021-11-24

125 downloads per month
Used in usi-run

MIT license

53KB
1.5K SLoC

csa-rs

Github Actions Coverage Status crates.io docs.rs

A Shogi game serialization/deserialization library in CSA format.

Documentation

Usage

[dependencies]
csa = "0.6"

License

csa-rs is licensed under the MIT license. Please read the LICENSE file in this repository for more information.


lib.rs:

A serialization/deserialization library for 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 http://www.computer-shogi.org/protocol/record_v22.html.

Examples

Below is an example of parsing CSA-formatted string into structs.

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 = parse_csa(csa_str).expect("failed to parse the csa content");
assert_eq!(game.black_player, Some("NAKAHARA".to_string()));
assert_eq!(game.white_player, Some("YONENAGA".to_string()));
assert_eq!(game.event, Some("13th World Computer Shogi Championship".to_string()));
assert_eq!(game.moves[0],  MoveRecord{
    action: Action::Move(Color::Black, Square::new(2, 7), Square::new(2, 6), PieceType::Pawn),
    time: Some(Duration::from_secs(12))
});

In contrast, structs can be composed into CSA-formatted string.

use std::time::Duration;
use csa::{ Action, Color, GameRecord, MoveRecord, PieceType, Square};

let mut g = GameRecord::default();
g.black_player = Some("NAKAHARA".to_string());
g.white_player = Some("YONENAGA".to_string());
g.event = Some("13th World Computer Shogi Championship".to_string());
g.moves.push(MoveRecord {
    action: Action::Move(
        Color::Black,
        Square::new(2, 7),
        Square::new(2, 6),
        PieceType::Pawn,
    ),
    time: Some(Duration::from_secs(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
";

assert_eq!(csa_str, g.to_string());

Dependencies

~2.5MB
~49K SLoC