Skip to content

Commit 1f4f5cd

Browse files
committed
Merge branch 'main' of github.com:LelleSwe/chess-algorithm-development into LelleSwe/main
2 parents 0741ec2 + aa85106 commit 1f4f5cd

File tree

3 files changed

+59
-48
lines changed

3 files changed

+59
-48
lines changed

src/algorithms/the_algorithm.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,7 @@ impl Algorithm {
6969
stats.time_for_transposition_access += Instant::now() - start;
7070
stats.transposition_table_entries += 1
7171
}
72-
return Evaluation::new(
73-
Some(eval + incremental_psqt_eval),
74-
None,
75-
None,
76-
Some(incremental_psqt_eval),
77-
);
72+
return Evaluation::new(Some(eval), None, None, Some(incremental_psqt_eval));
7873
}
7974

8075
// Whether we should try to maximise the eval
@@ -255,7 +250,6 @@ impl Algorithm {
255250
- 2 * piece_value(Piece::King)) as f32
256251
* TAPERED_EG_PESTO[piece_type.to_index()][location]
257252
}
258-
259253
let moved_piece_type = board.piece_on(chess_move.get_source()).unwrap();
260254

261255
let multiplier = if board.side_to_move() == Color::White {
@@ -418,10 +412,10 @@ impl Algorithm {
418412
// This is third time this is played. Draw by three-fold repetition
419413
return 0.;
420414
}
421-
let material_each_side = utils::material_each_side(board);
415+
let material_each_side: (u32, u32) = utils::material_each_side(board);
422416

423417
// Negative when black has advantage
424-
let diff_material = material_each_side.0 as i32 - material_each_side.1 as i32;
418+
let diff_material: i32 = material_each_side.0 as i32 - material_each_side.1 as i32;
425419

426420
let mut controlled_squares = 0;
427421
if utils::module_enabled(self.modules, modules::SQUARE_CONTROL_METRIC) {
@@ -513,10 +507,10 @@ impl Algorithm {
513507
let mut bonus: f32 = 0.;
514508
let pawn_bitboard: usize = (all_pawn_bitboard & color_bitboard).to_size(0);
515509
let king_bitboard: usize = (all_king_bitboard & color_bitboard).to_size(0);
516-
//pawn chain, awarding 0.5 eval for each pawn protected by another pawn.
510+
//pawn chain, awarding 0.5 eval for each pawn protected by another pawn. Constants should in theory cover an (literal) edge case... I hope.
517511
bonus += 0.5
518-
* ((pawn_bitboard & (pawn_bitboard << 7)).count_ones()
519-
+ (pawn_bitboard & (pawn_bitboard << 9)).count_ones())
512+
* ((pawn_bitboard & (0xFEFEFEFEFEFEFEFE & pawn_bitboard << 7)).count_ones()
513+
+ (pawn_bitboard & (0x7F7F7F7F7F7F7F7F & pawn_bitboard << 9)).count_ones())
520514
as f32;
521515

522516
//stacked pawns. -0.5 points per rank containing >1 pawns. By taking the pawn bitboard and operating bitwise AND for another bitboard (integer) where the leftmost rank is filled. This returns all pawns in that rank. By bitshifting we can choose rank. Additionally by counting we get number of pawns. We then remove 1 as we only want to know if there are >1 pawn. If there is, subtract 0.5 points per extra pawn.

src/common/constants.rs

+49-32
Original file line numberDiff line numberDiff line change
@@ -163,56 +163,73 @@ pub(crate) mod tapered_pesto_psqt_tables {
163163
],
164164
];
165165

166+
#[rustfmt::skip]
166167
pub(crate) const TAPERED_EG_PESTO: [[f32; 64]; 6] = [
167168
//Pawn
168169
[
169-
0., 0., 0., 0., 0., 0., 0., 0., 1.78, 1.73, 1.58, 1.34, 1.47, 1.32, 1.65, 1.87, 0.94,
170-
1., 0.85, 0.67, 0.56, 0.53, 0.82, 0.84, 0.32, 0.24, 0.13, 0.05, -0.02, 0.04, 0.17,
171-
0.17, 0.13, 0.09, -0.03, -0.07, -0.07, -0.08, 0.03, -0.01, 0.04, 0.07, -0.06, 0.01, 0.,
172-
-0.05, -0.01, -0.08, 0.13, 0.08, 0.08, 0.10, 0.13, 0., 0.02, -0.07, 0., 0., 0., 0., 0.,
173-
0., 0., 0.,
170+
0., 0., 0., 0., 0., 0., 0., 0.,
171+
1.78, 1.73, 1.58, 1.34, 1.47, 1.32, 1.65, 1.87,
172+
0.94, 1., 0.85, 0.67, 0.56, 0.53, 0.82, 0.84,
173+
0.32, 0.24, 0.13, 0.05, -0.02, 0.04, 0.17, 0.17,
174+
0.13, 0.09, -0.03, -0.07, -0.07, -0.08, 0.03, -0.01,
175+
0.04, 0.07, -0.06, 0.01, 0., -0.05, -0.01, -0.08,
176+
0.13, 0.08, 0.08, 0.10, 0.13, 0., 0.02, -0.07,
177+
0., 0., 0., 0., 0., 0., 0., 0.,
174178
],
175179
//Knight
176180
[
177-
-0.58, -0.38, -0.13, -0.28, -0.31, -0.27, -0.63, -0.99, -0.25, -0.08, -0.25, -0.02,
178-
-0.09, -0.25, -0.24, -0.52, -0.24, -0.20, 0.10, 0.09, -0.01, -0.09, -0.19, -0.41,
179-
-0.17, 0.03, 0.22, 0.22, 0.22, 0.11, 0.08, -0.18, -0.18, -0.06, 0.16, 0.25, 0.16, 0.17,
180-
0.04, -0.18, -0.23, -0.03, -0.01, 0.15, 0.10, -0.03, -0.20, -0.22, -0.42, -0.20, -0.10,
181-
-0.05, -0.02, -0.20, -0.23, -0.44, -0.29, -0.51, -0.23, -0.15, -0.22, -0.18, -0.50,
182-
-0.64,
181+
-0.58, -0.38, -0.13, -0.28, -0.31, -0.27, -0.63, -0.99,
182+
-0.25, -0.08, -0.25, -0.02, -0.09, -0.25, -0.24, -0.52,
183+
-0.24, -0.20, 0.10, 0.09, -0.01, -0.09, -0.19, -0.41,
184+
-0.17, 0.03, 0.22, 0.22, 0.22, 0.11, 0.08, -0.18,
185+
-0.18, -0.06, 0.16, 0.25, 0.16, 0.17, 0.04, -0.18,
186+
-0.23, -0.03, -0.01, 0.15, 0.10, -0.03, -0.20, -0.22,
187+
-0.42, -0.20, -0.10, -0.05, -0.02, -0.20, -0.23, -0.44,
188+
-0.29, -0.51, -0.23, -0.15, -0.22, -0.18, -0.50, -0.64,
183189
],
184190
//Bishop
185191
[
186-
-0.14, -0.21, -0.11, -0.08, -0.07, -0.09, -0.17, -0.24, -0.08, -0.04, 0.07, -0.12,
187-
-0.03, -0.13, -0.04, -0.14, 0.02, -0.08, 0.0, -0.01, -0.02, 0.06, 0.0, 0.04, -0.03,
188-
0.09, 0.12, 0.09, 0.14, 0.10, 0.03, 0.02, -0.06, 0.03, 0.13, 0.19, 0.07, 0.10, -0.03,
189-
-0.09, -0.12, -0.03, 0.08, 0.10, 0.13, 0.03, -0.07, -0.015, -0.14, -0.18, -0.07, -0.01,
190-
0.04, -0.09, -0.15, -0.027, -0.23, -0.09, -0.23, -0.05, -0.09, -0.16, -0.05, -0.017,
192+
-0.14, -0.21, -0.11, -0.08, -0.07, -0.09, -0.17, -0.24,
193+
-0.08, -0.04, 0.07, -0.12, -0.03, -0.13, -0.04, -0.14,
194+
0.02, -0.08, 0.0, -0.01, -0.02, 0.06, 0.0, 0.04,
195+
-0.03, 0.09, 0.12, 0.09, 0.14, 0.10, 0.03, 0.02,
196+
-0.06, 0.03, 0.13, 0.19, 0.07, 0.10, -0.03, -0.09,
197+
-0.12, -0.03, 0.08, 0.10, 0.13, 0.03, -0.07, -0.015,
198+
-0.14, -0.18, -0.07, -0.01, 0.04, -0.09, -0.15, -0.027,
199+
-0.23, -0.09, -0.23, -0.05, -0.09, -0.16, -0.05, -0.017,
191200
],
192201
//Rook
193202
[
194-
0.13, 0.10, 0.18, 0.15, 0.12, 0.12, 0.08, 0.05, 0.11, 0.13, 0.13, 0.11, -0.03, 0.03,
195-
0.08, 0.03, 0.07, 0.07, 0.07, 0.05, 0.04, -0.03, -0.05, -0.03, 0.04, 0.03, 0.13, 0.01,
196-
0.02, 0.01, -0.01, 0.02, 0.03, 0.05, 0.08, 0.04, -0.05, -0.06, -0.08, -0.11, -0.04,
197-
0.0, -0.05, -0.01, -0.07, -0.12, -0.08, -0.16, -0.06, -0.06, 0.0, 0.02, -0.09, -0.09,
198-
-0.11, -0.03, -0.09, 0.02, 0.03, -0.01, -0.05, -0.13, 0.04, -0.20,
203+
0.13, 0.10, 0.18, 0.15, 0.12, 0.12, 0.08, 0.05,
204+
0.11, 0.13, 0.13, 0.11, -0.03, 0.03, 0.08, 0.03,
205+
0.07, 0.07, 0.07, 0.05, 0.04, -0.03, -0.05, -0.03,
206+
0.04, 0.03, 0.13, 0.01, 0.02, 0.01, -0.01, 0.02,
207+
0.03, 0.05, 0.08, 0.04, -0.05, -0.06, -0.08, -0.11,
208+
-0.04, 0.0, -0.05, -0.01, -0.07, -0.12, -0.08, -0.16,
209+
-0.06, -0.06, 0.0, 0.02, -0.09, -0.09, -0.11, -0.03,
210+
-0.09, 0.02, 0.03, -0.01, -0.05, -0.13, 0.04, -0.20,
199211
],
200212
//Queen
201213
[
202-
-0.09, 0.22, 0.22, 0.27, 0.27, 0.19, 0.10, 0.20, -0.17, 0.20, 0.32, 0.41, 0.58, 0.25,
203-
0.30, 0., -0.20, 0.06, 0.09, 0.49, 0.47, 0.35, 0.19, 0.09, 0.03, 0.22, 0.24, 0.45,
204-
0.57, 0.40, 0.57, 0.36, -0.18, 0.28, 0.19, 0.47, 0.31, 0.34, 0.39, 0.23, -0.16, -0.27,
205-
0.15, 0.06, 0.09, 0.17, 0.10, 0.05, -0.22, -0.23, -0.30, -0.16, -0.16, -0.23, -0.36,
206-
-0.32, -0.33, -0.28, -0.22, -0.43, -0.05, -0.32, -0.20, -0.41,
214+
-0.09, 0.22, 0.22, 0.27, 0.27, 0.19, 0.10, 0.20,
215+
-0.17, 0.20, 0.32, 0.41, 0.58, 0.25, 0.30, 0.,
216+
-0.20, 0.06, 0.09, 0.49, 0.47, 0.35, 0.19, 0.09,
217+
0.03, 0.22, 0.24, 0.45, 0.57, 0.40, 0.57, 0.36,
218+
-0.18, 0.28, 0.19, 0.47, 0.31, 0.34, 0.39, 0.23,
219+
-0.16, -0.27, 0.15, 0.06, 0.09, 0.17, 0.10, 0.05,
220+
-0.22, -0.23, -0.30, -0.16, -0.16, -0.23, -0.36, -0.32,
221+
-0.33, -0.28, -0.22, -0.43, -0.05, -0.32, -0.20, -0.41,
207222
],
208223
//King
209224
[
210-
-0.74, -0.35, -0.18, -0.18, -0.11, 0.15, 0.04, -0.17, -0.12, 0.17, 0.14, 0.17, 0.17,
211-
0.38, 0.23, 0.11, 0.10, 0.17, 0.23, 0.15, 0.20, 0.45, 0.44, 0.13, -0.08, 0.22, 0.24,
212-
0.27, 0.26, 0.33, 0.26, 0.03, -0.18, -0.04, 0.21, 0.24, 0.27, 0.23, 0.09, -0.11, -0.19,
213-
-0.03, 0.11, 0.21, 0.23, 0.16, 0.07, -0.09, -0.27, -0.11, 0.04, 0.13, 0.14, 0.04,
214-
-0.05, -0.17, -0.53, -0.34, -0.21, -0.11, -0.28, -0.14, -0.24, -0.43,
225+
-0.74, -0.35, -0.18, -0.18, -0.11, 0.15, 0.04, -0.17,
226+
-0.12, 0.17, 0.14, 0.17, 0.17, 0.38, 0.23, 0.11,
227+
0.10, 0.17, 0.23, 0.15, 0.20, 0.45, 0.44, 0.13,
228+
-0.08, 0.22, 0.24, 0.27, 0.26, 0.33, 0.26, 0.03,
229+
-0.18, -0.04, 0.21, 0.24, 0.27, 0.23, 0.09, -0.11,
230+
-0.19, -0.03, 0.11, 0.21, 0.23, 0.16, 0.07, -0.09,
231+
-0.27, -0.11, 0.04, 0.13, 0.14, 0.04, -0.05, -0.17,
232+
-0.53, -0.34, -0.21, -0.11, -0.28, -0.14, -0.24, -0.43,
215233
],
216234
];
217235
}
218-

src/main.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::time::Duration;
22

33
use crate::algorithms::the_algorithm::Algorithm;
4-
#[allow(dead_code, unused_imports)]
4+
#[allow(unused_imports)]
55
use crate::common::constants::modules::{
66
ALPHA_BETA, ANALYZE, NAIVE_PSQT, PAWN_STRUCTURE, SEARCH_EXTENSIONS, SKIP_BAD_MOVES,
77
SQUARE_CONTROL_METRIC, TAPERED_EVERY_PESTO_PSQT, TAPERED_INCREMENTAL_PESTO_PSQT,
@@ -17,8 +17,8 @@ mod pitter;
1717
#[tokio::main]
1818
async fn main() {
1919
//ALPHA_BETA | ANALYZE | SEARCH_EXTENSIONS | SKIP_BAD_MOVES | SQUARE_CONTROL_METRIC | TRANSPOSITION_TABLE | NAIVE_PSQT | PAWN_STRUCTURE | TAPERED_EVERY_PRESTO_PSQT | TAPERED_INCREMENTAL_PESTO_PSQT
20-
let modules1 = ALPHA_BETA | TAPERED_INCREMENTAL_PESTO_PSQT;
21-
let modules2 = ALPHA_BETA;
20+
let modules1 = ALPHA_BETA | TAPERED_EVERY_PESTO_PSQT;
21+
let modules2 = ALPHA_BETA | NAIVE_PSQT;
2222
let time_per_move1 = Duration::from_micros(2000);
2323
let time_per_move2 = Duration::from_micros(2000);
2424

@@ -30,6 +30,6 @@ async fn main() {
3030
// competition.analyze_algorithm_choices(|(game_info, _), _| {
3131
// game_info.outcome == GameOutcome::InconclusiveTooLong
3232
// });
33-
let results = competition.start_competition(200).await;
33+
let results = competition.start_competition(50).await;
3434
dbg!(results);
3535
}

0 commit comments

Comments
 (0)