Skip to content

Commit

Permalink
Renamed project
Browse files Browse the repository at this point in the history
  • Loading branch information
miestrode committed Jan 20, 2024
1 parent f5d8cf6 commit ab93d90
Show file tree
Hide file tree
Showing 38 changed files with 78 additions and 119 deletions.
18 changes: 10 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ members = ["crates/*"]
resolver = "2"

[workspace.dependencies]
hash-bootstrap = { path = "crates/hash-bootstrap" }
hash-core = { path = "crates/hash-core" }
hash-engine = { path = "crates/hash-engine" }
hash-network = { path = "crates/hash-network" }
hash-search = { path = "crates/hash-search" }
hash-train = { path = "crates/hash-train" }
hash-server = { path = "crates/hash-server" }
hash-client = { path = "crates/hash-client" }
mangrove-bootstrap = { path = "crates/mangrove-bootstrap" }
mangrove-core = { path = "crates/mangrove-core" }
mangrove-engine = { path = "crates/mangrove-engine" }
mangrove-pisa = { path = "crates/mangrove-pisa" }
mangrove-search = { path = "crates/mangrove-search" }
mangrove-train = { path = "crates/mangrove-train" }

swamp-server = { path = "crates/swamp-server" }
swamp-client = { path = "crates/swamp-client" }

rustifact = "0.10.1"
burn = "0.11.1"
burn-wgpu = "0.11.1"
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# The Hash Chess Engine
# The Mangrove Chess Engine

[![Status](https://github.com/miestrode/hash/workflows/Rust/badge.svg)](https://github.com/miestrode/hash/actions)

Hash is a CEGO (revision 1) compliant experimental Chess engine written in Rust, with the goal of putting to use recent advancements in statistics, computer science and computer Chess. Unlike most traditional Chess engines, Hash doesn't use the alpha-beta framework, and instead opts to perform directed tree search in the form of AlphaZero-style MCTS, while in the future, incorporating and facilitating new ideas and innovations in Computer Chess, neural network architecture, and directed tree search.
Mangrove is a CEGO (revision 1) compliant experimental Chess engine written in Rust, with the goal of putting to use recent advancements in statistics, computer science and computer Chess. Unlike most traditional Chess engines, Mangrove doesn't use the alpha-beta framework, and instead opts to perform directed tree search in the form of AlphaZero-style MCTS, while in the future, incorporating and facilitating new ideas and innovations in Computer Chess, neural network architecture, and directed tree search.

A secondary goal of Hash is to use as much Rust as possible in its design, to test the boundaries of what is possible to do with modern Rust. Therefore, Hash currently uses the Burn deep learning framework for running its neural networks, instead of more established options, such as Tensorflow or PyTorch. The hope is that, in the future, there will be less of a feature gap between the frameworks, and that optimization tools will grow to support Burn and similar Rust-based projects.
A secondary goal of Mangrove is to use as much Rust as possible in its design, to test the boundaries of what is possible to do with modern Rust. Therefore, Mangrove currently uses the Burn deep learning framework for running its neural networks, instead of more established options, such as Tensorflow or PyTorch. The hope is that, in the future, there will be less of a feature gap between the frameworks, and that optimization tools will grow to support Burn and similar Rust-based projects.

Hash is currently in the process of being written, and has not officially released in any form. It is unlikely the code in the repository here currently works as a full Chess engine.
Mangrove is currently in the process of being written, and has not officially released in any form. It is unlikely the code in the repository here currently works as a full Chess engine.

## CEGO (or, why Hash doesn't support UCI)
## CEGO (or, why Mangrove doesn't support UCI)

Hash doesn't support UCI, and instead uses its bespoke protocol, CEGO (Chess Engine Game Operation). The reasons for this are partially explained in [here](docs/cego/REVISION-1.md). It suffices to say, we felt UCI and similar protocols weren't good choices given the use cases for this engine.
Mangrove doesn't support UCI, and instead uses its bespoke protocol, CEGO (Chess Engine Game Operation). The reasons for this are partially explained in [here](docs/cego/REVISION-1.md). It suffices to say, we felt UCI and similar protocols weren't good choices given the use cases for this engine.

## Documentation

As we feel Hash is a sufficiently large project, documentation explaining things such as its current network structure and things of the like can be seen in [here](docs/). Note that documentation is currently largely incomplete.
As we feel Mangrove is a sufficiently large project, documentation explaining things such as its current network structure and things of the like can be seen in [here](docs/). Note that documentation is currently largely incomplete.

## Contributing

The project currently will not accept contributions which significantly alter the source code, and so does not have guidelines for doing so. This is because things are currently far too underdeveloped. In the future, a `CONTRIBUTING.md` file will be made.
Mangrove currently isn't accept contributions which significantly alter the source code, and so does not have guidelines for doing so. This is because things are currently far too underdeveloped. In the future, a `CONTRIBUTING.md` file will be made.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[package]
name = "hash-bootstrap"
authors = ["Yoav Grimland <[email protected]>"]
name = "mangrove-bootstrap"
version = "0.0.0"
edition.workspace = true

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
[package]
name = "hash-core"
authors = ["Yoav Grimland <[email protected]>"]
name = "mangrove-core"
version = "0.0.0"
edition.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[build-dependencies]
hash-bootstrap.workspace = true
mangrove-bootstrap.workspace = true
rustifact.workspace = true
rand.workspace = true

[dev-dependencies]
test-case.workspace = true

[dependencies]
hash-bootstrap.workspace = true
mangrove-bootstrap.workspace = true
rustifact.workspace = true
arrayvec.workspace = true
thiserror.workspace = true
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{array, io::Error};

use rand::{rngs::StdRng, Rng, SeedableRng};

use hash_bootstrap::{BitBoard, Color, Metadata, Square, ZobristMap};
use mangrove_bootstrap::{BitBoard, Color, Metadata, Square, ZobristMap};
use rustifact::ToTokenStream;

const SEED: u64 = 0x73130172E6DEA605;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
mg,
repr::{ChessMove, ParsePieceBoardError, Piece, PieceBoard, PieceKind, PieceKindBoard, Player},
};
use hash_bootstrap::{BitBoard, Color, ParseSquareError, Square};
use mangrove_bootstrap::{BitBoard, Color, ParseSquareError, Square};

#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Board {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::str::FromStr;

use hash_bootstrap::Color;
use mangrove_bootstrap::Color;

use crate::{
board::{Board, MakeMoveError, ParseBoardError},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use hash_bootstrap::{
use mangrove_bootstrap::{
BitBoard, Color, Metadata, Square, ZobristCastlingRights, ZobristMap, ZobristPieces,
ZobristSide,
};
Expand Down Expand Up @@ -254,7 +254,7 @@ pub fn line_between(a: Square, b: Square) -> BitBoard {
/// let combined_hash = white_king_rook ^ side_to_play;
/// ```
pub mod zobrist {
use hash_bootstrap::{Color, Square};
use mangrove_bootstrap::{Color, Square};

use crate::repr::{CastlingRights, Piece, PieceBoard, PieceKind};

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use arrayvec::ArrayVec;
use hash_bootstrap::{BitBoard, Color, Square};
use mangrove_bootstrap::{BitBoard, Color, Square};

use crate::{
board::Board,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use hash_bootstrap::{BitBoard, Color, ParseSquareError, Square};
use mangrove_bootstrap::{BitBoard, Color, ParseSquareError, Square};
use std::{
fmt::{self, Display},
ops::{Index, IndexMut},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
[package]
name = "hash-network"
authors = ["Yoav Grimland <[email protected]>"]
name = "mangrove-pisa"
version = "0.0.0"
edition.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
hash-bootstrap.workspace = true
hash-core.workspace = true
mangrove-bootstrap.workspace = true
mangrove-core.workspace = true
burn.workspace = true
serde.workspace = true

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use burn::tensor::{backend::Backend, Shape, Tensor};
use hash_bootstrap::{BitBoard, Color, Square};
use hash_core::{board::Board, repr::Player};
use mangrove_bootstrap::{BitBoard, Color, Square};
use mangrove_core::{board::Board, repr::Player};

pub mod model;
mod model;

pub use model::*;

fn bitboard_to_tensor<B: Backend>(bitboard: BitBoard) -> Tensor<B, 2> {
Tensor::from_floats((Square::ALL).map(|square| f32::from(bitboard.get_bit(square))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use burn::{
},
tensor::{activation, backend::Backend, Shape, Tensor},
};
use hash_bootstrap::Square;
use hash_core::{
use mangrove_bootstrap::Square;
use mangrove_core::{
board::Board,
repr::{ChessMove, PieceKind},
};
Expand Down Expand Up @@ -205,13 +205,13 @@ impl IndexMut<ChessMove> for MoveProbabilities {
}
}

pub struct H0Result {
pub struct PisaResult {
pub value: f32,
pub move_probabilities: MoveProbabilities,
}

impl<B: Backend> From<H0Result> for Tensor<B, 1> {
fn from(value: H0Result) -> Self {
impl<B: Backend> From<PisaResult> for Tensor<B, 1> {
fn from(value: PisaResult) -> Self {
Tensor::cat(
vec![
Tensor::from_floats(value.move_probabilities.probabilities),
Expand All @@ -228,15 +228,15 @@ pub struct BatchOutput<B: Backend> {
}

#[derive(Module, Debug)]
pub struct H0<B: Backend> {
pub struct Pisa<B: Backend> {
move_history: usize,
conv_block: Conv2d<B>,
se_blocks: Vec<SeBlock<B>>,
fc_1: Linear<B>,
output: Linear<B>,
}

impl<B: Backend> H0<B> {
impl<B: Backend> Pisa<B> {
pub fn move_history(&self) -> usize {
self.move_history
}
Expand All @@ -260,7 +260,7 @@ impl<B: Backend> H0<B> {
}
}

pub fn process(&self, input: Vec<&[Board]>) -> Vec<H0Result> {
pub fn process(&self, input: Vec<&[Board]>) -> Vec<PisaResult> {
let batch_output = self.forward(Tensor::stack(
input
.iter()
Expand All @@ -285,7 +285,7 @@ impl<B: Backend> H0<B> {
values
.into_iter()
.zip(probabilities)
.map(|(value, move_probabilities)| H0Result {
.map(|(value, move_probabilities)| PisaResult {
value,
move_probabilities,
})
Expand All @@ -294,7 +294,7 @@ impl<B: Backend> H0<B> {
}

#[derive(Config, Debug)]
pub struct H0Config {
pub struct PisaConfig {
#[config(default = 1)]
initial_kernel_stride: usize,
#[config(default = 3)]
Expand All @@ -313,9 +313,9 @@ pub struct H0Config {
ratio: usize,
}

impl H0Config {
pub fn init<B: Backend>(&self) -> H0<B> {
H0 {
impl PisaConfig {
pub fn init<B: Backend>(&self) -> Pisa<B> {
Pisa {
move_history: self.move_history,
conv_block: Conv2dConfig::new(
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
[package]
name = "hash-search"
authors = ["Yoav Grimland <[email protected]>"]
name = "mangrove-search"
version = "0.0.0"
edition.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
hash-core.workspace = true
hash-network.workspace = true
mangrove-core.workspace = true
mangrove-pisa.workspace = true
burn.workspace = true
thiserror.workspace = true
tracing.workspace = true
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::tree::Tree;
use burn::tensor::backend::Backend;
use hash_core::repr::ChessMove;
use hash_network::model::H0;
use mangrove_core::repr::ChessMove;
use mangrove_pisa::Pisa;

use std::{
sync::mpsc::{self, Receiver, Sender, TryRecvError},
Expand All @@ -15,7 +15,7 @@ pub enum SearchCommand {

pub fn start_search_thread<B: Backend>(
mut tree: Tree,
network: H0<B>,
network: Pisa<B>,
exploration_rate: f32,
) -> (Sender<SearchCommand>, Receiver<ChessMove>) {
let (command_sender, command_receiver) = mpsc::channel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::{
};

use burn::tensor::backend::Backend;
use hash_core::{board::Board, mg, repr::ChessMove};
use hash_network::model::H0;
use mangrove_core::{board::Board, mg, repr::ChessMove};
use mangrove_pisa::Pisa;
use ringbuffer::{AllocRingBuffer, RingBuffer};

use crate::puct;
Expand Down Expand Up @@ -200,7 +200,7 @@ impl Tree {
}
}

pub fn grow<B: Backend>(&self, network: &H0<B>, exploration_rate: f32) {
pub fn grow<B: Backend>(&self, network: &Pisa<B>, exploration_rate: f32) {
let (path, boards) = self.select(exploration_rate, network.move_history());
let end_board = boards.last().unwrap();
let network_result = &network.process(vec![&boards[..]])[0];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
[package]
name = "hash-train"
authors = ["Yoav Grimland <[email protected]>"]
name = "mangrove-train"
version = "0.0.0"
edition.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
hash-core.workspace = true
hash-search.workspace = true
hash-network.workspace = true
mangrove-core.workspace = true
mangrove-search.workspace = true
mangrove-pisa.workspace = true
burn = { workspace = true, features = ["autodiff"] }
ringbuffer.workspace = true
rand.workspace = true
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
use std::iter;

use burn::tensor::{backend::Backend, Tensor};
use hash_core::{
use mangrove_core::{
board::Board,
game::{Game, Outcome},
};
use hash_network::model::{H0Result, MoveProbabilities, H0};
use hash_search::{
puct::PuctSelector,
tree::{Selector, Tree},
};
use mangrove_pisa::model::{MoveProbabilities, Pisa, PisaResult};
use mangrove_search::tree::Tree;
use rand::{distributions::WeightedIndex, Rng};
use ringbuffer::{AllocRingBuffer, RingBuffer};

Expand Down Expand Up @@ -103,7 +100,7 @@ pub fn gen_game<B: Backend>(
.chain(iter::repeat(None).take(model.move_history() - boards.len()))
.collect(),
),
expected_output: H0Result {
expected_output: PisaResult {
// If the finshing color, in other words, the color that would play if the game
// wasn't finished, actually won, it would mean it would have the ability to
// capture the opponent's king, and thus this color always loses.
Expand Down
File renamed without changes.
10 changes: 4 additions & 6 deletions crates/hash-engine/Cargo.toml → crates/mangrove/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
[package]
name = "hash-engine"
description = "The Hash Chess Engine CLI"
name = "mangrove"
version = "0.0.0"
authors = ["Yoav Grimland <[email protected]>"]
edition.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -14,9 +12,9 @@ clap = { workspace = true, features = [
"color",
"unstable-styles",
] }
hash-core.workspace = true
hash-search.workspace = true
hash-network.workspace = true
mangrove-core.workspace = true
mangrove-search.workspace = true
mangrove-pisa.workspace = true
thiserror.workspace = true
burn-wgpu.workspace = true
tracing.workspace = true
Expand Down
Loading

0 comments on commit ab93d90

Please sign in to comment.