Skip to content

Commit

Permalink
Bitboards and compact representation features (#4)
Browse files Browse the repository at this point in the history
* Bitboards
* Compact representation
* Rename move module to eval
* Fix broken UI from previous changes
  • Loading branch information
oriolarcas committed Dec 27, 2023
1 parent 498f7ad commit e3485dd
Show file tree
Hide file tree
Showing 24 changed files with 5,794 additions and 661 deletions.
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.

54 changes: 54 additions & 0 deletions between.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
print("const IN_BETWEEN_TABLE: [[u64; 64]; 64] = [")

def index_to_rank_and_file(index):
rank = index // 8
file = index % 8
return rank, file

for source_index in range(64):
print(" [")
for target_index in range(64):
# Check if the source and target are on the same rank, file or diagonal
source_rank, source_file = index_to_rank_and_file(source_index)
target_rank, target_file = index_to_rank_and_file(target_index)
if source_rank == target_rank or source_file == target_file or abs(source_rank - target_rank) == abs(source_file - target_file):
# They are on the same rank, file or diagonal
if source_index == target_index:
# They are the same square
print(" 0,")
else:
# They are on the same rank, file or diagonal, but not the same square
# Print the squares in between
squares_in_between = []
if source_rank == target_rank:
# They are on the same rank
for file in range(min(source_file, target_file) + 1, max(source_file, target_file)):
squares_in_between.append(source_rank * 8 + file)
elif source_file == target_file:
# They are on the same file
for rank in range(min(source_rank, target_rank) + 1, max(source_rank, target_rank)):
squares_in_between.append(rank * 8 + source_file)
else:
# They are on the same diagonal
for i in range(1, abs(source_rank - target_rank)):
if source_rank < target_rank:
rank = source_rank + i
else:
rank = source_rank - i
if source_file < target_file:
file = source_file + i
else:
file = source_file - i
squares_in_between.append(rank * 8 + file)
if len(squares_in_between) == 0:
# There are no squares in between
print(" 0,")
else:
# Print the squares in between
print(f" 0x{sum([2 ** square for square in squares_in_between]):016x},")
else:
# They are not on the same rank, file or diagonal
print(" 0,")
print(" ],")

print("];")
4 changes: 2 additions & 2 deletions bump_version.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash

usage() {
echo "Usage: $0 <major> <minor> <patch>"
Expand Down Expand Up @@ -26,4 +26,4 @@ cd src-tauri
cargo bump "$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\"/" tauri.conf.json
21 changes: 14 additions & 7 deletions chusst-uci/src/engine.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::duplex_thread::{create_duplex_thread, DuplexThread};
use chusst::board::{Game, Move};
use chusst::moves::{
do_move, get_best_move_with_logger, EngineFeedback, EngineFeedbackMessage, GameMove,
HasStopSignal,
use chusst::eval::{
do_move, get_best_move_with_logger, EngineFeedback, EngineFeedbackMessage, EngineMessage,
GameMove, HasStopSignal,
};
use chusst::game::{Game, Move};

use std::io::Write;
use std::fmt;
use std::io::Write;

#[derive(Clone)]
pub struct GoCommand {
Expand Down Expand Up @@ -124,8 +124,15 @@ impl<'a> BufferedSenderWriter<'a> {
}

impl<'a> EngineFeedback for BufferedSenderWriter<'a> {
fn send(&self, msg: EngineFeedbackMessage) {
let _ = self.send(EngineResponse::Info(msg));
fn send(&self, msg: EngineMessage) {
match msg {
EngineMessage::Info(msg) => {
let _ = self.send(EngineResponse::Log(msg.message));
}
EngineMessage::SearchFeedback(msg) => {
let _ = self.send(EngineResponse::Info(msg));
}
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions chusst-uci/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ mod duplex_thread;
mod engine;
mod stdin;

use chusst::board::{Game, Move};
use chusst::moves::GameMove;
use chusst::eval::GameMove;
use chusst::game::{Game, Move};
use engine::{create_engine_thread, EngineCommand, EngineResponse, GoCommand, NewGameCommand};
use stdin::{create_stdin_thread, StdinResponse};

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chusst",
"version": "0.7.0",
"version": "0.8.0",
"private": true,
"dependencies": {
"@tauri-apps/api": "^1.4.0",
Expand Down
12 changes: 9 additions & 3 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chusst"
version = "0.7.0"
version = "0.8.0"
description = "A simple chess engine in Rust"
authors = ["Oriol Arcas"]
license = ""
Expand All @@ -23,8 +23,14 @@ atty = "0.2.14"
bencher = "0.1.5"

[features]
# DO NOT set 'default', breaks production build

# default = ["compact-board"]
# default = ["bitboards"]
# default = ["compact-board", "bitboards"]

# Use bitboards to evaluate valid moves
bitboards = []
# Use a memory-efficient representation of the board (1 byte per square)
compact-board = []
# Build with this feature to print the search tree to stdout
verbose-search = []

Expand Down
4 changes: 2 additions & 2 deletions src-tauri/benches/search.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use chusst::board::Game;
use chusst::moves::{do_move, get_best_move_recursive, SilentSearchFeedback};
use chusst::eval::{do_move, get_best_move_recursive, SilentSearchFeedback};
use chusst::game::Game;

#[macro_use]
extern crate bencher;
Expand Down

0 comments on commit e3485dd

Please sign in to comment.