| Crates.io | hexchess |
| lib.rs | hexchess |
| version | 2.4.3 |
| created_at | 2024-09-04 02:02:19.22876+00 |
| updated_at | 2025-09-21 03:44:45.245217+00 |
| description | A library for Gliński's hexagonal chess, and the brain of hexchess.club |
| homepage | |
| repository | https://github.com/scottbedard/hexchess |
| max_upload_size | |
| id | 1362400 |
| size | 204,361 |
hexchessA library for Gliński's hexagonal chess, and the brain of hexchess.club.
Run the following Cargo command in your project directory:
cargo add hexchess
Or add hexchess as a dependency to your Cargo.toml file.
The Hexchess struct represents a deserialized version of Forsyth–Edwards Notation. Since castling is not a part of hexchess, that section is omitted. The following is a generalized version of the struct. The board is stored as an array of Option<Piece> values, sorted by FEN index.
{
board: [
'b', 'q', 'b', 'k', 'n', null, 'b', null, 'n', 'r',
null, null, null, null, null, 'r', 'p', 'p', 'p', 'p',
'p', 'p', 'p', 'p', 'p', null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null,
null, 'P', null, null, null, null, null, null, null, null,
null, 'P', null, 'P', null, null, null, null, null, null,
null, 'P', null, 'B', null, 'P', null, null, null, null,
null, 'P', null, null, 'B', null, null, 'P', null, null,
null, 'P', 'R', 'N', 'Q', 'B', 'K', 'N', 'R', 'P',
null
],
turn: 'w',
ep: null,
halfmove: 0,
fullmove: 1
}
The following methods are available,
applyApply a whitespace separated sequence of moves.
let mut hexchess = Hexchess::init();
let _ = hexchess.apply("g4g5 e7e6 f5f6 e6f6");
hexchess.to_string() // b/qbk/n1b1n/r5r/ppp1ppppp/5p5/6P4/4P6/3P1B1P3/2P2B2P2/1PRNQBKNRP1 w - 0 3
apply_moveApply a single move by San.
let san = San::from("g4g5").unwrap();
let mut hexchess = Hexchess::init();
let _ = hexchess.apply_move(&san);
hexchess.to_string() // b/qbk/n1b1n/r5r/ppppppppp/11/5PP4/4P6/3P1B1P3/2P2B2P2/1PRNQBKNRP1 b - 0 1
apply_move_unsafeApply a single by San, regardless of turn or legality.
let san = San::from("b1b6").unwrap();
let mut hexchess = Hexchess::init();
let _ = hexchess.apply_move_unsafe(&san)
hexchess.to_string() // b/qbk/n1b1n/r5r/ppppppppp/1P9/5P5/4P1P4/3P1B1P3/2P2B2P2/2RNQBKNRP1 b - 0 1
current_movesGet all current legal moves.
let hexchess = Hexchess::init();
for san in hexchess.current_moves() {
// ...
}
find_kingFind FEN index for king belonging to Color.
let hexchess = Hexchess::init();
hexchess.find_king(Color::Black); // Some(3)
hexchess.find_king(Color::White); // Some(86)
getGet board value from position name.
let hexchess = Hexchess::init();
hexchess.get("e1") // Some(WhiteQueen)
get_colorGet all board indices occupied by Color pieces.
let hexchess = Hexchess::init();
hexchess.get_color(Black) // [0, 1, 2, ...]
is_checkTest if the board is in check.
let hexchess = Hexchess::init();
hexchess.is_check() // false
is_checkmateTest if the game is in checkmate.
let hexchess = Hexchess::init();
hexchess.is_checkmate() // false
is_stalemateTest if the game is in stalemate.
let hexchess = Hexchess::init();
hexchess.is_stalemate() // false
moves_fromGet all legal moves from a position.
let hexchess = Hexchess::init();
hexchess.moves_from(h!("f5")) // [San { from: 41, promotion: None, to: 30 }]
moves_from_unsafeGet all moves from a position, including ones that result in self-check.
let hexchess = Hexchess::parse("1/3/5/7/4r4/5K5/11/11/11/11/11 w - 0 1").unwrap();
hexchess.moves_from_unsafe(h!("f6")) // [San, San, San, ...]
to_stringSerialize Hexchess to string.
let hexchess = Hexchess::init();
hexchess.to_string() // b/qbk/n1b1n/r5r/ppppppppp/11/5P5/4P1P4/3P1B1P3/2P2B2P2/1PRNQBKNRP1 w - 0 1
Copyright (c) 2024-present, Scott Bedard