Giter Club home page Giter Club logo

turbochess-rs's Introduction

TurboChess library

TurboChess is a chess move generator. It supports:

  • PEXT bitboards (emulated)
  • Make and Undo Position
  • Zobrist hashing
  • FEN support

To get started, create a new Position and now you can work with legal moves

Example 1: Get the count of legal moves

let pos: Position = Position::default(); // Loads the initial position
// Or you can also use another position
// let pos: Position = Position::from_str("r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1").unwrap();

let legals: MoveList = pos.legal(); // Gets all legal moves in the position
for mv in legals {
   println!("{mv}"); // Prints the move in the UCI format
}

println!("Legal count: {}", legals.count());

Example 2: Test all legal moves

let mut pos: Position = Position::default();
let legals: MoveList = pos.legal(); // Gets all legal moves in the position
for mv in legals {
   pos.make_move(mv);
   println!("Doing stuff with move...")
   pos.undo_move(mv);
}
println!("Finished!")

Example 3: Play a random move

let mut pos: Position = Position::default();
let legals: MoveList = pos.legal();

// Gets a random move
let mut rng = rand::thread_rng();
let index = rng.gen_range(0..legals.count());
let mv = legals.get(index);

println!("Move: {mv}");
pos.make_move(mv);
println!("{pos}");
println!("New FEN: {}", pos.fen());

Contribute to TurboChess

Actually, TurboChess probably has performance issues and errors that can be fixed to be faster and accurate. If you find some of these errors, please raise an issue. Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.