| Crates.io | goban |
| lib.rs | goban |
| version | 0.20.1 |
| created_at | 2018-12-20 18:18:54.96608+00 |
| updated_at | 2025-04-15 21:34:17.859851+00 |
| description | Library for Go move generation and Go ruling. |
| homepage | |
| repository | https://github.com/Sagebati/goban |
| max_upload_size | |
| id | 102959 |
| size | 167,881 |
Library to play with a rusty "Goban" (name of the board where we play Go !), It's built with performance in mind. The library can perform a full playout of a random game in 1.5 ms checking all legal moves.
In Go, they are different rules, atm only two rules are implemented:
Adding more rules can be achieved pretty easily.
Use the version > 0.5.0 because in a bug detecting dead stones and in Ko detection
Only contains move generation, and rules there is no IA, neither front-end.
Features:
The most important struct is Game who has all you need to create and manages go games.
use crate::goban::rules::*;
use crate::goban::rules::game::*;
use rand::seq::IteratorRandom;
use goban::rules::game_builder::GameBuilder;
let mut g = Game::builder()
.size((19,19))
.rule(CHINESE)
// .komi(7.5) Komi is hardcoded for each rule, but can be override like this.
.build().unwrap();
let mut i = 35;
while !g.is_over() && i != 0 {
g.play(
// legals return an iterator of (x,y) points (lazy)
g.legals()
.choose(&mut rand::thread_rng())
.map(|point| Move::Play(point.0,point.1))
.unwrap());
i -= 1;
g.display_goban();
// None if the game is not finished
println!("{:?}", g.outcome());
// Inner array using row policy
println!("{:?}", g.goban().to_vec());
}
#[cfg(feature = "history")]
{
let mut iter_history = g.history().iter();
println!("{:?}", iter_history.next().unwrap());
println!("{:?}", iter_history.next_back().unwrap())
}
┏┯┯┯┯┯┯┯┓
┠┼┼┼┼┼┼┼┨
┠┼┼┼┼┼┼┼┨
┠┼┼┼┼┼┼┼┨
┠┼┼┼┼┼┼┼┨
┠┼┼┼┼┼┼┼┨
┠┼┼┼┼┼┼┼┨
○┼┼┼┼┼┼┼┨
┗┷┷┷┷┷┷┷┛
etc...