Skip to content

Commit 91f6fd0

Browse files
committed
Improved the bot
1 parent 25e134d commit 91f6fd0

File tree

13 files changed

+494
-351
lines changed

13 files changed

+494
-351
lines changed

notebooks/benchmark.ipynb

Lines changed: 34 additions & 69 deletions
Large diffs are not rendered by default.

src/api/get/get_eval.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
use axum::{ extract::{ State, Json }, response::IntoResponse, http::StatusCode };
22
use serde::{ Deserialize, Serialize };
3-
use std::{ collections::HashMap, str::FromStr, sync::{ Arc, Mutex } };
3+
use std::{ str::FromStr, sync::Arc};
44
use chess::Board;
55
use crate::bot::{
66
algorithm::root::search,
7-
include::types::{ EngineState, ServerState, TT_TABLE_SIZE },
7+
include::types::{
8+
EngineState,
9+
RepetitionHistory,
10+
ServerState,
11+
TranspositionTable,
12+
TT_TABLE_SIZE,
13+
},
814
};
9-
use lru::LruCache;
10-
use std::num::NonZeroUsize;
1115

1216
#[derive(Debug, Deserialize)]
1317
pub struct EvalRequest {
@@ -46,27 +50,26 @@ pub async fn eval_position_handler(
4650
}
4751
};
4852

49-
let mut history: HashMap<u64, u32> = HashMap::new();
53+
let mut history = RepetitionHistory::new();
5054
for fen in &payload.history {
5155
if let Ok(board) = Board::from_str(fen) {
5256
let hash = board.get_hash();
53-
*history.entry(hash).or_insert(0) += 1;
57+
history.increment(hash);
5458
}
5559
}
5660

57-
let capacity = NonZeroUsize::new(TT_TABLE_SIZE).unwrap();
58-
let transposition_table = Arc::new(Mutex::new(LruCache::new(capacity)));
61+
let transposition_table = TranspositionTable::new(TT_TABLE_SIZE);
62+
5963
let mut engine = EngineState {
6064
game_id: "eval_temp".to_string(),
6165
current_board,
6266
history,
63-
statistics: HashMap::new(),
67+
statistics: Default::default(),
6468
global_map: Arc::clone(&state.global_map),
6569
transposition_table,
6670
};
6771

6872
let board = engine.current_board.clone();
69-
// Default time values — can tweak or make them params if needed
7073
let (best_move, nodes, time_taken_ms, eval, depth) = search(
7174
payload.time_left_ms,
7275
payload.time_limit_ms,

src/api/post/add_game.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
use axum::{ extract::State, response::IntoResponse, Json, http::StatusCode };
2-
use lru::LruCache;
32
use serde::{ Deserialize, Serialize };
4-
use std::{ collections::HashMap, num::NonZeroUsize, str::FromStr, sync::{ Arc, Mutex } };
5-
use crate::bot::include::types::{ EngineState, ServerState, TT_TABLE_SIZE };
3+
use std::{ collections::HashMap, str::FromStr, sync::Arc };
4+
use crate::bot::include::types::{
5+
EngineState,
6+
RepetitionHistory,
7+
ServerState,
8+
TranspositionTable,
9+
TT_TABLE_SIZE,
10+
};
611
use chess::Board;
712

813
#[derive(Debug, Deserialize)]
@@ -43,16 +48,16 @@ pub async fn new_game_handler(
4348
}
4449
};
4550

46-
let mut history: HashMap<u64, u32> = HashMap::new();
51+
// ✅ Use the new RepetitionHistory wrapper
52+
let mut history = RepetitionHistory::new();
4753
for fen in &payload.history {
4854
if let Ok(board) = Board::from_str(fen) {
4955
let hash = board.get_hash();
50-
*history.entry(hash).or_insert(0) += 1;
56+
history.increment(hash);
5157
}
5258
}
5359

54-
let capacity = NonZeroUsize::new(TT_TABLE_SIZE).unwrap();
55-
let transposition_table = Arc::new(Mutex::new(LruCache::new(capacity)));
60+
let transposition_table = TranspositionTable::new(TT_TABLE_SIZE);
5661
let engine = EngineState {
5762
game_id: payload.game_id.clone(),
5863
current_board,

src/api/post/make_move.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub async fn make_move_handler(
5555

5656
engine.current_board = engine.current_board.make_move_new(chess_move);
5757
let hash = engine.current_board.get_hash();
58-
*engine.history.entry(hash).or_insert(0) += 1;
58+
engine.history.increment(hash);
5959

6060
let new_fen = engine.current_board.to_string();
6161

src/bot/algorithm/ab.rs

Lines changed: 0 additions & 169 deletions
This file was deleted.

0 commit comments

Comments
 (0)