| Crates.io | gyges |
| lib.rs | gyges |
| version | 1.1.0 |
| created_at | 2024-08-01 01:41:13.935922+00 |
| updated_at | 2025-01-27 04:26:17.078512+00 |
| description | A library for the board game Gygès. |
| homepage | |
| repository | https://github.com/Beck-Bjella/Gyges |
| max_upload_size | |
| id | 1321467 |
| size | 8,329,475 |
A library for the board game Gygès.
Gygès is an abstract strategy game for two players. The object of Gygès is to move a piece to your opponent's last row. The catch is that no one owns the pieces. You can only move a piece in the row nearest you. Pieces are made up of 1, 2, or 3 rings; this number is also the number of spaces they must move. If a piece lands on another piece, it can move the number of spaces equal to that piece's number of rings. It can also displace that piece to any open space.
Check out the game on Board Game Arena: Gygès.
This library is specifically for implementing Gygès, not a tool for playing the game directly. To see an implemented game engine using this library, visit the gyges_engine repository.
Board representation:
BitBoards:
Move generation:
Move representation:
Custom move lists:
Core components:
Transposition table:
This library will only run on an x86_64 architecture. It is not currently compatible with other architectures.
To add this crate to your project, include the following in your Cargo.toml file:
[dependencies]
gyges = "1.1.0"
The library provides predefined starting board positions. Use the following code to load the default board:
use gyges::*;
// Load the starting board position
let board: BoardState = BoardState::from(STARTING_BOARD);
To load a custom board configuration, provide a string where each row is represented by a series of numbers. Rows are inputted from your side of the board to the opponent's, and pieces are numbered based on their ring count:
use gyges::*;
// Load a custom board configuration
let board: BoardState = BoardState::from("321123/000000/000000/000000/000000/321123");
The MoveGen structure is the core for generating moves in Gygès. It provides a flexible interface for generating and calculating move-related data tailored to specific needs using generic parameters.
MoveGen uses two key generic parameters:
GenType: Specifies the type of data to generate:
GenMoves: Generates all possible legal moves.GenMoveCount: Counts the total number of possible moves.GenThreatCount: Counts the number of threats on the board.GenControlMoveCount: Combines control analysis and move counting.QuitType: Controls when generation stops:
NoQuit: Completes the full generation process.QuitOnThreat: Stops generation immediately if a threat is found. This is particularly useful for saving computation in scenarios where you need both the data and the guarantee that no threats exist. If a threat is found, you can handle it separately.use gyges::*;
// Setup
let mut board: BoardState = BoardState::from(STARTING_BOARD);
let player: Player = Player::One;
let mut move_gen: MoveGen = MoveGen::default();
// Generate
let data: GenResult = unsafe { move_gen.gen::<GenMoves, NoQuit>(&mut board, player) };
let mut movelist: RawMoveList = data.move_list;
let moves: Vec<Move> = movelist.moves(&mut board);
println!("Generated moves: {:?}", moves);
use gyges::*;
// Setup
let mut board: BoardState = BoardState::from(STARTING_BOARD);
let player: Player = Player::One;
let mut move_gen: MoveGen = MoveGen::default();
// Generate
let data: GenResult = unsafe { move_gen.gen::<GenMoveCount, QuitOnThreat>(&mut board, player) };
let move_count: usize = data.move_count;
println!("Move count: {}", move_count);
Use the make_move method on the BoardState struct to make a move. This method takes a Move struct as an argument and returns a new BoardState with the move applied:
use gyges::*;
// Setup
let mut board: BoardState = BoardState::from(STARTING_BOARD);
let player: Player = Player::One;
let mut move_gen: MoveGen = MoveGen::default();
// Generate moves
let data: GenResult = unsafe { move_gen.gen::<GenMoves, NoQuit>(&mut board, player) };
let mut movelist: RawMoveList = data.move_list;
let moves: Vec<Move> = movelist.moves(&mut board);
// Make a move
println!("Original board: {}", board);
println!("Move: {:?}", moves[0]);
let mut new_board: BoardState = board.make_move(&moves[0]);
println!("New board: {}", board);
This project and its formatting were inspired by the incredible Rust chess program Pleco.
Contributions are welcome! If you'd like to contribute:
This project is released under the GNU General Public License v3.0. Please review and comply with the terms of the license when using or distributing the project.