Skip to content

Commit 6c57b64

Browse files
committed
Fix lints
1 parent 9e9fab4 commit 6c57b64

File tree

4 files changed

+36
-38
lines changed

4 files changed

+36
-38
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/target
2+
.idea

Diff for: src/algorithms/the_algorithm.rs

+32-35
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use std::collections::HashMap;
2-
use tokio::time::{Duration, Instant};
32

43
use chess::{Action, BitBoard, Board, BoardStatus, ChessMove, Color, MoveGen, Piece};
4+
use tokio::time::{Duration, Instant};
55

66
use crate::common::constants::{
7-
modules::{self, *},
7+
modules::*,
88
naive_psqt_tables::*,
99
tapered_pesto_psqt_tables::*,
1010
};
@@ -134,7 +134,7 @@ impl Algorithm {
134134
// node on our layer
135135
stats.progress_on_next_layer *= 1. / num_legal_moves as f32;
136136
stats.progress_on_next_layer +=
137-
(i.saturating_sub(1)) as f32 / num_legal_moves as f32;
137+
i.saturating_sub(1) as f32 / num_legal_moves as f32;
138138
return best_evaluation;
139139
};
140140

@@ -182,7 +182,7 @@ impl Algorithm {
182182
num_extensions + extend_by,
183183
board_played_times_prediction,
184184
mg_incremental_psqt_eval,
185-
eg_incremental_psqt_eval
185+
eg_incremental_psqt_eval,
186186
);
187187
board_played_times_prediction.insert(
188188
new_board,
@@ -196,8 +196,8 @@ impl Algorithm {
196196
// Replace best_eval if ours is better
197197
if evaluation.eval.is_some()
198198
&& (best_evaluation.eval.is_none()
199-
|| maximise && evaluation.eval.unwrap() > best_evaluation.eval.unwrap()
200-
|| !maximise && evaluation.eval.unwrap() < best_evaluation.eval.unwrap())
199+
|| maximise && evaluation.eval.unwrap() > best_evaluation.eval.unwrap()
200+
|| !maximise && evaluation.eval.unwrap() < best_evaluation.eval.unwrap())
201201
{
202202
if original && module_enabled(self.modules, ANALYZE) {
203203
let mut vec = Vec::new();
@@ -238,19 +238,19 @@ impl Algorithm {
238238
}
239239
}
240240

241-
if utils::module_enabled(self.modules, modules::TAPERED_INCREMENTAL_PESTO_PSQT) {
241+
if module_enabled(self.modules, TAPERED_INCREMENTAL_PESTO_PSQT) {
242242
fn calc_increment(
243243
piece_type: Piece,
244244
location: usize,
245-
mg_eg: bool
245+
mg_eg: bool,
246246
) -> f32 {
247247
if mg_eg {
248248
TAPERED_MG_PESTO[piece_type.to_index()][location]
249249
} else {
250250
TAPERED_EG_PESTO[piece_type.to_index()][location]
251251
}
252252
}
253-
let moved_piece_type= board.piece_on(chess_move.get_source()).unwrap();
253+
let moved_piece_type = board.piece_on(chess_move.get_source()).unwrap();
254254

255255
let multiplier = if board.side_to_move() == Color::White {
256256
1
@@ -264,7 +264,6 @@ impl Algorithm {
264264
mg_incremental_psqt_eval_change += Self::calc_tapered_psqt_eval(board, i, true);
265265
mg_incremental_psqt_eval_change += Self::calc_tapered_psqt_eval(board, i, false);
266266
}
267-
268267
} else {
269268
//Remove the eval from the previous square we stood on.
270269
let source: usize = (56 - chess_move.get_source().to_int()
@@ -277,8 +276,8 @@ impl Algorithm {
277276
let dest: usize = (56 - chess_move.get_dest().to_int()
278277
+ 2 * (chess_move.get_dest().to_int() % 8))
279278
as usize;
280-
mg_incremental_psqt_eval_change += calc_increment(moved_piece_type, dest, true);
281-
eg_incremental_psqt_eval_change += calc_increment(moved_piece_type, dest, false);
279+
mg_incremental_psqt_eval_change += calc_increment(moved_piece_type, dest, true);
280+
eg_incremental_psqt_eval_change += calc_increment(moved_piece_type, dest, false);
282281

283282
//Decrement enemy eval from potetntial capture
284283
if let Some(attacked_piece_type) = board.piece_on(chess_move.get_dest()) {
@@ -289,8 +288,8 @@ impl Algorithm {
289288
mg_incremental_psqt_eval += mg_incremental_psqt_eval_change * multiplier as f32;
290289
eg_incremental_psqt_eval += eg_incremental_psqt_eval_change * multiplier as f32;
291290
}
292-
best_evaluation.incremental_psqt_eval =
293-
Some(mg_incremental_psqt_eval + eg_incremental_psqt_eval);
291+
best_evaluation.incremental_psqt_eval =
292+
Some(mg_incremental_psqt_eval + eg_incremental_psqt_eval);
294293
}
295294

296295
if module_enabled(self.modules, TRANSPOSITION_TABLE) && depth >= 3 {
@@ -320,7 +319,7 @@ impl Algorithm {
320319
board: &Board,
321320
depth: u32,
322321
deadline: Option<Instant>,
323-
) -> (Option<chess::Action>, Vec<String>, Stats) {
322+
) -> (Option<Action>, Vec<String>, Stats) {
324323
let mut stats = Stats::default();
325324
let out = self.node_eval_recursive(
326325
board,
@@ -343,7 +342,7 @@ impl Algorithm {
343342
&mut self,
344343
board: &Board,
345344
deadline: Instant,
346-
) -> (chess::Action, Vec<String>, Stats) {
345+
) -> (Action, Vec<String>, Stats) {
347346
self.board_played_times.insert(
348347
*board,
349348
*self.board_played_times.get(board).unwrap_or(&0) + 1,
@@ -401,7 +400,7 @@ impl Algorithm {
401400
board: &Board,
402401
board_played_times_prediction: &HashMap<Board, u32>,
403402
mg_incremental_psqt_eval: f32,
404-
eg_incremental_psqt_eval: f32
403+
eg_incremental_psqt_eval: f32,
405404
) -> f32 {
406405
let board_status = board.status();
407406
if board_status == BoardStatus::Stalemate {
@@ -426,7 +425,7 @@ impl Algorithm {
426425
let diff_material: i32 = material_each_side.0 as i32 - material_each_side.1 as i32;
427426

428427
let mut controlled_squares = 0;
429-
if utils::module_enabled(self.modules, modules::SQUARE_CONTROL_METRIC) {
428+
if module_enabled(self.modules, SQUARE_CONTROL_METRIC) {
430429
controlled_squares = if board.side_to_move() == Color::Black {
431430
-1i32
432431
} else {
@@ -436,7 +435,7 @@ impl Algorithm {
436435

437436
// Compares piece position with an 8x8 table containing certain values. The value corresponding to the position of the piece gets added as evaluation.
438437
let mut naive_psqt: f32 = 0.;
439-
if utils::module_enabled(self.modules, modules::NAIVE_PSQT) {
438+
if module_enabled(self.modules, NAIVE_PSQT) {
440439
fn naive_psqt_calc(
441440
naive_psqt_table: [f32; 64],
442441
piece_bitboard: &BitBoard,
@@ -503,18 +502,18 @@ impl Algorithm {
503502
let mut mg_tapered_pesto: f32 = 0.;
504503
let mut eg_tapered_pesto: f32 = 0.;
505504
let mut tapered_pesto: f32 = 0.;
506-
if utils::module_enabled(self.modules, modules::TAPERED_EVERY_PESTO_PSQT) {
505+
if module_enabled(self.modules, TAPERED_EVERY_PESTO_PSQT) {
507506
for i in 0..5 {
508507
mg_tapered_pesto += Self::calc_tapered_psqt_eval(board, i, true);
509508
eg_tapered_pesto += Self::calc_tapered_psqt_eval(board, i, false);
510509
}
511-
tapered_pesto = ((material_each_side.0 + material_each_side.1 - 2 * piece_value(Piece::King)) as f32 * mg_tapered_pesto +
512-
(78 - (material_each_side.0 + material_each_side.1 - 2 * piece_value(Piece::King))) as f32 * eg_tapered_pesto)
513-
/ 78.;
510+
tapered_pesto = ((material_each_side.0 + material_each_side.1 - 2 * piece_value(Piece::King)) as f32 * mg_tapered_pesto +
511+
(78 - (material_each_side.0 + material_each_side.1 - 2 * piece_value(Piece::King))) as f32 * eg_tapered_pesto)
512+
/ 78.;
514513
}
515514

516515
let mut pawn_structure: f32 = 0.;
517-
if utils::module_enabled(self.modules, modules::PAWN_STRUCTURE) {
516+
if module_enabled(self.modules, PAWN_STRUCTURE) {
518517
fn pawn_structure_calc(
519518
all_pawn_bitboard: &BitBoard,
520519
color_bitboard: &BitBoard,
@@ -526,15 +525,15 @@ impl Algorithm {
526525
//pawn chain, awarding 0.5 eval for each pawn protected by another pawn. Constants should in theory cover an (literal) edge case... I hope.
527526
bonus += 0.5
528527
* ((pawn_bitboard & 0xFEFEFEFEFEFEFEFE & (pawn_bitboard << 9)).count_ones()
529-
+ (pawn_bitboard & 0x7F7F7F7F7F7F7F7F & (pawn_bitboard << 7)).count_ones())
530-
as f32;
528+
+ (pawn_bitboard & 0x7F7F7F7F7F7F7F7F & (pawn_bitboard << 7)).count_ones())
529+
as f32;
531530

532531
//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.
533532
for i in 0..7 {
534533
//constant 0x8080808080808080: entire first rank.
535534
bonus -= 0.5
536535
* ((pawn_bitboard & (0x8080808080808080 >> i)).count_ones() as f32 - 1.)
537-
.max(0.);
536+
.max(0.);
538537
}
539538

540539
//king safety. Outer 3 pawns get +1 eval bonus per pawn if king is behind them. King bitboard required is either ..X..... or ......X.
@@ -558,9 +557,9 @@ impl Algorithm {
558557
}
559558

560559
let mut incremental_psqt_eval: f32 = 0.;
561-
if utils::module_enabled(self.modules, modules::TAPERED_INCREMENTAL_PESTO_PSQT) {
560+
if module_enabled(self.modules, TAPERED_INCREMENTAL_PESTO_PSQT) {
562561
incremental_psqt_eval = (material_each_side.0 + material_each_side.1 - 2 * piece_value(Piece::King)) as f32 * mg_incremental_psqt_eval
563-
+ (78 - material_each_side.0 + material_each_side.1 - 2 * piece_value(Piece::King)) as f32 * eg_incremental_psqt_eval
562+
+ (78 - material_each_side.0 + material_each_side.1 - 2 * piece_value(Piece::King)) as f32 * eg_incremental_psqt_eval
564563
}
565564

566565
let evaluation: f32 = controlled_squares as f32 / 20.
@@ -577,7 +576,7 @@ impl Algorithm {
577576
piece_bitboard: &BitBoard,
578577
color_bitboard: &BitBoard,
579578
piece_index: usize,
580-
mg_eg: bool
579+
mg_eg: bool,
581580
) -> f32 {
582581
// Essentially, gets the dot product between a "vector" of the bitboard (containing 64 0s and 1s) and the table with NAIVE_PSQT bonus constants.
583582
let mut bonus: f32 = 0.;
@@ -592,22 +591,21 @@ impl Algorithm {
592591
// and we (hopefully?) linerarly transition from one to the other, depending on material value.
593592
bonus += ((piece_bitboard & color_bitboard)
594593
.reverse_colors()
595-
.to_size(i as u8) & 1) as f32
594+
.to_size(i as u8) & 1) as f32
596595
* TAPERED_MG_PESTO[piece_index][i];
597596
}
598597
bonus
599598
} else {
600599
for i in 0..63 {
601600
bonus += ((piece_bitboard & color_bitboard)
602601
.reverse_colors()
603-
.to_size(i as u8) & 1) as f32
602+
.to_size(i as u8) & 1) as f32
604603
* TAPERED_EG_PESTO[piece_index][i];
605604
}
606605
bonus
607606
}
608-
609607
}
610-
608+
611609
macro_rules! tapered_psqt_calc {
612610
($board: tt, $piece: tt, $index: tt, $mg_eg: tt) => {
613611
tapered_psqt_calc(
@@ -627,7 +625,6 @@ impl Algorithm {
627625
5 => tapered_psqt_calc!(board, King, 5, mg_eg),
628626
6_u8..=u8::MAX => unimplemented!()
629627
}
630-
631628
}
632629

633630
pub(crate) fn reset(&mut self) {

Diff for: src/common/utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ impl AddAssign for Stats {
110110
}
111111

112112
impl Div<u32> for Stats {
113+
type Output = StatsAverage;
114+
113115
fn div(self, rhs: u32) -> Self::Output {
114116
StatsAverage {
115117
alpha_beta_breaks: self.alpha_beta_breaks as f32 / rhs as f32,
@@ -126,8 +128,6 @@ impl Div<u32> for Stats {
126128
tt_size: self.tt_size as f32 / rhs as f32,
127129
}
128130
}
129-
130-
type Output = StatsAverage;
131131
}
132132
#[derive(Default, Debug)]
133133
// These fields are used through Debug

Diff for: src/pitter/logic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ impl Competition {
242242
);
243243

244244
//Whether the game just played should be printed in console.
245-
if PRINT_GAME == true {
245+
if PRINT_GAME {
246246
println!("Game pair played. Outcome: {:?}", combined_outcome);
247247
println!("{}", utils::to_pgn(&game_pair_info.0.game.unwrap()));
248248
}

0 commit comments

Comments
 (0)