Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect threefold repetition #15

Merged
merged 6 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions bump_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ echo Updating package.json
npm version --allow-same-version --commit-hooks false --git-tag-version false "$new_ver"

echo Updating Cargo.toml
cd src-tauri
cargo bump "$new_ver"
cargo set-version -p chusst-gen "$new_ver"

echo Updating tauri.conf.json
sed -E -i'' "s/\"version\": \"[0-9.]+\"/\"version\": \"$new_ver\"/" tauri.conf.json
sed -E -i'' "s/\"version\": \"[0-9.]+\"/\"version\": \"$new_ver\"/" src-tauri/tauri.conf.json
2 changes: 1 addition & 1 deletion chusst-gen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chusst-gen"
version = "0.10.0"
version = "0.11.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
15 changes: 9 additions & 6 deletions chusst-gen/benches/search.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use divan::Bencher;

use chusst_gen::eval::{Game, SilentSearchFeedback};
use chusst_gen::eval::{Game, GameHistory, SilentSearchFeedback};
use chusst_gen::game::BitboardGame;

#[divan::bench]
fn search(bench: Bencher) {
bench.bench_local(|| {
let game = BitboardGame::new();
let history = GameHistory::new();

let best_branch = game
.get_best_move_recursive(4, &mut (), &mut SilentSearchFeedback::default())
.get_best_move_recursive(4, &history, &mut (), &mut SilentSearchFeedback::default())
.unwrap();

best_branch.searched
Expand Down Expand Up @@ -123,9 +124,11 @@ fn game_benchmark() -> u64 {
// use std::io::Write;

let mut game = BitboardGame::new();
let get_best_move_helper = |game: &mut BitboardGame| {
let mut history = GameHistory::new();

let get_best_move_helper = |game: &mut BitboardGame, history: &mut GameHistory| {
let best_branch = game
.get_best_move_recursive(3, &mut (), &mut SilentSearchFeedback::default())
.get_best_move_recursive(3, history, &mut (), &mut SilentSearchFeedback::default())
.unwrap();

(best_branch.searched, best_branch.moves.first().unwrap().mv)
Expand All @@ -147,14 +150,14 @@ fn game_benchmark() -> u64 {
// print!("{}. ", turn);
// std::io::stdout().flush().unwrap();

let (white_searched, white_move) = get_best_move_helper(&mut game);
let (white_searched, white_move) = get_best_move_helper(&mut game, &mut history);
// let white_move_name = move_name(&game.board, &game.last_move, &game.player, &white_move);
game.do_move(&white_move);

// print!("{} ", white_move_name);
// std::io::stdout().flush().unwrap();

let (black_searched, black_move) = get_best_move_helper(&mut game);
let (black_searched, black_move) = get_best_move_helper(&mut game, &mut history);
// let black_move_name = move_name(&game.board, &game.last_move, &game.player, &black_move);
game.do_move(&black_move);

Expand Down
45 changes: 45 additions & 0 deletions chusst-gen/src/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,51 @@ pub trait Board:

Some(board)
}

fn to_fen(&self) -> String {
let mut fen = String::new();

for rank in (0..8).rev() {
let mut empty = 0;
for file in 0..8 {
let piece = self.at(&pos!(rank, file));
match piece {
Some(Piece { piece, player }) => {
if empty > 0 {
fen.push_str(&empty.to_string());
empty = 0;
}
let piece_char = match (player, piece) {
(Player::White, PieceType::Pawn) => 'P',
(Player::White, PieceType::Knight) => 'N',
(Player::White, PieceType::Bishop) => 'B',
(Player::White, PieceType::Rook) => 'R',
(Player::White, PieceType::Queen) => 'Q',
(Player::White, PieceType::King) => 'K',
(Player::Black, PieceType::Pawn) => 'p',
(Player::Black, PieceType::Knight) => 'n',
(Player::Black, PieceType::Bishop) => 'b',
(Player::Black, PieceType::Rook) => 'r',
(Player::Black, PieceType::Queen) => 'q',
(Player::Black, PieceType::King) => 'k',
};
fen.push(piece_char);
}
None => {
empty += 1;
}
}
}
if empty > 0 {
fen.push_str(&empty.to_string());
}
if rank > 0 {
fen.push('/');
}
}

fen
}
}

fn get_unicode_piece(piece: PieceType, player: Player) -> char {
Expand Down
Loading
Loading