Skip to content

Commit

Permalink
chore: Continue cleaning up the project
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillbobyrev committed May 20, 2024
1 parent 617e58e commit 258044e
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 181 deletions.
38 changes: 0 additions & 38 deletions .github/ISSUE_TEMPLATE/Bug.yml

This file was deleted.

22 changes: 0 additions & 22 deletions .github/ISSUE_TEMPLATE/Feature.yml

This file was deleted.

7 changes: 0 additions & 7 deletions .github/ISSUE_TEMPLATE/config.yml

This file was deleted.

93 changes: 0 additions & 93 deletions ARCHITECTURE.md

This file was deleted.

1 change: 0 additions & 1 deletion BUILDING.md

This file was deleted.

102 changes: 101 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1 +1,101 @@
# Contribution guide
# Contributing guide

This document describes high-level architecture of Pabi. If you want to get
familiar with the code and understand the project structure, this is a great
starting point.

## Design considerations

## Recipes

### Building

### Testing

### Fuzzing

## Code map

### [`src/`](/src/)

The source directory contains code for the engine driver implemented in Rust.

#### [`src/chess/`](/src/chess/)

Contains implementation of the chess environment: [Bitboard]-based board
representation, move generation and position parsing. This is the core of the
engine: a fast move generator and convenient board implementation are crucial
for engine's performance.

#### [`src/evaluation/`](/src/evaluation/)

Contains code that extracts features from a given position and runs "static"
[position evaluation]: a Neural Network considers just a single position and
computes the score that determines how good it is for the player that is going
to make the next move.

The development of the Neural Network model is in another repo:
[kirillbobyrev/pabi-brain](https://github.com/kirillbobyrev/pabi-brain). The
Rust code only runs inference of an already trained model.

#### [`src/search/`](/src/search/)

[Monte-Carlo Tree Search]-based best move [search]. This is "dynamic" position
evaluation that considers possible continuations from a given root position,
evaluates these continuations and computes the final position evaluation, based
on the most prominent lines that can be played out of it. MCTS generates a large
number of playouts following the tree policy and adjusts the score returned by
static evaluation.

#### [`src/interface/`](/src/interface/)

Provides a way for the engine to [communicate with a front-end] (for human play)
or a tournament manager (for playing against other engines). Implements
[Universal Chess Interface] (UCI) protocol. UCI is not targeting human users but
it is not hard to learn and can be an easy way to debug some parts of the engine
manually, so it is also extended with several useful commands (for example, `go
perft`).

### [`tests/`](/tests/)

Tests the engine through public interfaces. Most tests should go here, unit
tests are only valuable for testing private functions that aren't exposed but
are still not trivial.

### [`benches/`](/benches/)

Performance is crucial for a chess engine. This directory contains a number of
performance regression tests that should be frequently run to ensure that the
engine is not becoming slower. Patches affecting performance should have
benchmark result deltas in the description.

### [`fuzz/`](/fuzz/)

[Fuzzers] complement the existing tests by generating random inputs and trying
to increase the coverage. Plenty of bugs can be caught by even relatively simply
fuzzers: writing and running them is highly encouraged.

### [`generated/`](/generated/)

Pre-computed constants (such as [Magic Bitboards], [Vector Attacks] and [Zobrist
hashing] table) speed up move generation and search. This data can be calculated
at build time or startup instead but the drawbacks are:

- Build time (compile-time Rust code can not make use of most built
infrastructure) or runtime (warm-up time) overhead
- Maintenance cost
- Losing opportunities for the compiler to do better optimizations

Hence, these values are calculated once and checked into the source tree as Rust
arrays. These constants shouldn't change over time.

[Bitboard]: https://www.chessprogramming.org/Bitboards
[Monte-Carlo Tree Search]: https://www.chessprogramming.org/Monte-Carlo_Tree_Search
[search]: https://www.chessprogramming.org/Search
[position evaluation]: https://www.chessprogramming.org/Evaluation
[Fuzzers]: https://en.wikipedia.org/wiki/Fuzzing
[communicate with a front-end]: https://www.chessprogramming.org/User_Interface
[Universal Chess Interface]: http://wbec-ridderkerk.nl/html/UCIProtocol.html
[Magic Bitboards]: https://www.chessprogramming.org/Magic_Bitboards
[vector attacks]: https://www.chessprogramming.org/Vector_Attacks
[Zobrist hashing]: https://www.chessprogramming.org/Zobrist_Hashing
9 changes: 3 additions & 6 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
//! environment. This information is then written to a file in the output
//! directory and can be accessed at runtime by the engine.

use std::error::Error;
use std::fmt::Write;
use std::path::Path;
use std::{env, fs, process};

Expand All @@ -23,7 +21,7 @@ fn generate_file(filename: &str, contents: &str) {
fs::write(dest_path, contents).unwrap();
}

fn generate_version() -> Result<(), Box<dyn Error>> {
fn generate_version() {
let version = format!("{} ({})", env!("CARGO_PKG_VERSION"), git_revision_hash());
generate_file("version", &version);
let build_info = format!(
Expand All @@ -32,9 +30,8 @@ fn generate_version() -> Result<(), Box<dyn Error>> {
env::var("TARGET").unwrap()
);
generate_file("build_info", &build_info);
Ok(())
}

fn main() -> Result<(), Box<dyn Error>> {
generate_version()
fn main() {
generate_version();
}
1 change: 1 addition & 0 deletions src/chess.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Implementation of chess environment, its rules and specifics.

// TODO: Re-export public types directly.
pub mod attacks;
pub mod bitboard;
pub mod core;
Expand Down
2 changes: 1 addition & 1 deletion src/evaluation.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod evaluator;
pub mod trivial;
1 change: 0 additions & 1 deletion src/evaluation/evaluator.rs

This file was deleted.

22 changes: 11 additions & 11 deletions src/evaluation/trivial.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::chess::Position;
use crate::chess::position::Position;


fn evaluate(position: &Position) -> i32 {

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, 1.78.0, false)

unused variable: `position`

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, 1.78.0, false)

function `evaluate` is never used

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macos-latest, stable, true)

unused variable: `position`

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macos-latest, stable, true)

function `evaluate` is never used

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, stable, false)

unused variable: `position`

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, stable, false)

function `evaluate` is never used

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, nightly, true)

unused variable: `position`

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, nightly, true)

function `evaluate` is never used

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macos-latest, nightly, true)

unused variable: `position`

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macos-latest, nightly, true)

function `evaluate` is never used

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macos-latest, stable, true)

unused variable: `position`

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macos-latest, stable, true)

function `evaluate` is never used

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macos-latest, stable, true)

unused variable: `position`

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macos-latest, stable, true)

function `evaluate` is never used

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest, stable, true)

unused variable: `position`

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest, stable, true)

function `evaluate` is never used

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, stable, false)

unused variable: `position`

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, stable, false)

function `evaluate` is never used

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, stable, false)

unused variable: `position`

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, stable, false)

function `evaluate` is never used

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macos-latest, nightly, true)

unused variable: `position`

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macos-latest, nightly, true)

function `evaluate` is never used

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macos-latest, nightly, true)

unused variable: `position`

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macos-latest, nightly, true)

function `evaluate` is never used

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, nightly, true)

unused variable: `position`

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, nightly, true)

function `evaluate` is never used

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, nightly, true)

unused variable: `position`

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, nightly, true)

function `evaluate` is never used

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest, nightly, true)

unused variable: `position`

Check warning on line 4 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest, nightly, true)

function `evaluate` is never used
Expand All @@ -12,18 +12,18 @@ fn evaluate(position: &Position) -> i32 {
let queen_value = 9;

Check warning on line 12 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, 1.78.0, false)

unused variable: `queen_value`

Check warning on line 12 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macos-latest, stable, true)

unused variable: `queen_value`

Check warning on line 12 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, stable, false)

unused variable: `queen_value`

Check warning on line 12 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, nightly, true)

unused variable: `queen_value`

Check warning on line 12 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macos-latest, nightly, true)

unused variable: `queen_value`

Check warning on line 12 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macos-latest, stable, true)

unused variable: `queen_value`

Check warning on line 12 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macos-latest, stable, true)

unused variable: `queen_value`

Check warning on line 12 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest, stable, true)

unused variable: `queen_value`

Check warning on line 12 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, stable, false)

unused variable: `queen_value`

Check warning on line 12 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, stable, false)

unused variable: `queen_value`

Check warning on line 12 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macos-latest, nightly, true)

unused variable: `queen_value`

Check warning on line 12 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macos-latest, nightly, true)

unused variable: `queen_value`

Check warning on line 12 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, nightly, true)

unused variable: `queen_value`

Check warning on line 12 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, nightly, true)

unused variable: `queen_value`

Check warning on line 12 in src/evaluation/trivial.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest, nightly, true)

unused variable: `queen_value`

// Count the number of each piece type
let num_pawns = position.count_pawns();
let num_knights = position.count_knights();
let num_bishops = position.count_bishops();
let num_rooks = position.count_rooks();
let num_queens = position.count_queens();
// let num_pawns = position.count_pawns();
// let num_knights = position.count_knights();
// let num_bishops = position.count_bishops();
// let num_rooks = position.count_rooks();
// let num_queens = position.count_queens();

// Calculate the score based on the number of each piece type
score += pawn_value * num_pawns;
score += knight_value * num_knights;
score += bishop_value * num_bishops;
score += rook_value * num_rooks;
score += queen_value * num_queens;
// score += pawn_value * num_pawns;
// score += knight_value * num_knights;
// score += bishop_value * num_bishops;
// score += rook_value * num_rooks;
// score += queen_value * num_queens;

score
}

0 comments on commit 258044e

Please sign in to comment.