Crates.io | gtp |
lib.rs | gtp |
version | 0.1.2 |
source | src |
created_at | 2019-06-13 07:15:45.169803 |
updated_at | 2021-08-11 04:19:30.560355 |
description | GTP (Go Text Protocol) controller implementation for Rust |
homepage | |
repository | https://github.com/WeirdConstructor/gtp-rs |
max_upload_size | |
id | 140789 |
size | 125,286 |
This crate implements a parser, serializer for the Go Text Protocol and an abstraction for an GTP engine controller. You may just use the protocol handling parts if you have an alternative GTP engine controller implementation. But you are free to use the one provided by this crate.
See also:
A short overview of the API of this crate.
This is the basic usage on how to communicate with a GTP
engine like GNU Go
, Leela Zero
or KataGo
:
use std::time::Duration;
use gtp::Command;
use gtp::controller::Engine;
let mut ctrl = Engine::new("/usr/bin/gnugo", &["--mode", "gtp"]);
assert!(ctrl.start().is_ok());
ctrl.send(Command::cmd("name", |e| e));
let resp = ctrl.wait_response(Duration::from_millis(500)).unwrap();
let ev = resp.entities(|ep| ep.s().s()).unwrap();
assert_eq!(ev[0].to_string(), "GNU");
assert_eq!(ev[1].to_string(), "Go");
assert_eq!(resp.text(), "GNU Go");
Sending commands:
use gtp;
let mut c = gtp::Command::new("list_commands");
assert_eq!(c.to_string(), "list_commands\n");
Sending commands with entities:
use gtp::Command;
assert_eq!(Command::new("clear_board").to_string(), "clear_board\n");
assert_eq!(Command::new_with_args("boardsize", |eb| eb.i(19)).to_string(),
"boardsize 19\n");
Receiving Responses:
let mut rp = gtp::ResponseParser::new();
rp.feed("= o");
rp.feed("k\n\n");
rp.feed("= A\nB\nC\n\n= white b3 b T19\n\n");
assert_eq!(rp.get_response().unwrap().text(), "ok");
assert_eq!(rp.get_response().unwrap().text(), "A\nB\nC");
// And processing entities in the response:
let ents = rp.get_response().unwrap()
.entities(|ep| ep.color().vertex().mv()).unwrap();
assert_eq!(ents[0].to_string(), "w");
assert_eq!(ents[1].to_string(), "B3");
assert_eq!(ents[2].to_string(), "b T19");
// And processing entities in the response more complicatedly:
rp.feed("= white b3\n\n");
let mut ep = gtp::EntityParser::new(&rp.get_response().unwrap().text());
let res = ep.mv().result().unwrap();
assert_eq!(res[0].to_string(), "w B3");
match res[0] {
gtp::Entity::Move((color, (h, v))) => {
assert_eq!(color, gtp::Color::W);
assert_eq!(h, 2);
assert_eq!(v, 3);
},
_ => {},
}
This project is licensed under the GNU General Public License Version 3 or later.
Picking a license for my code bothered me for a long time. I read many discussions about this topic. Read the license explanations. And discussed this matter with other developers.
First about why I write code for free at all:
Those are the reasons why I write code for free. Now the reasons why I publish the code, when I could as well keep it to myself:
Most of those reasons don't yet justify GPL. The main point of the GPL, as far as I understand: The GPL makes sure the software stays free software until eternity. That the user of the software always stays in control. That the users have at least the means to adapt the software to new platforms or use cases. Even if the original authors don't maintain the software anymore. It ultimately prevents "vendor lock in". I really dislike vendor lock in, especially as developer. Especially as developer I want and need to stay in control of the computers I use.
Another point is, that my work has a value. If I give away my work without any strings attached, I effectively work for free. Work for free for companies. I would compromise the price I can demand for my skill, workforce and time.
This makes two reasons for me to choose the GPL:
Please contact me if you need a different license and really want to use my code. As long as I am the only author, I can change the license. We might find an agreement.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in gtp-rs by you, shall be licensed as GPLv3 or later, without any additional terms or conditions.
WeirdConstructor
on the Rust Discord.)