Skip to content

Commit

Permalink
flimsybird: Extract variables to another file
Browse files Browse the repository at this point in the history
To allow easier trial and error.
  • Loading branch information
francorbacho committed Feb 2, 2024
1 parent 786b039 commit 8a3e3c1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
20 changes: 8 additions & 12 deletions flimsybird/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod params;

use rand::Rng;

use std::convert::TryFrom;
Expand Down Expand Up @@ -200,29 +202,23 @@ fn board_static_evaluation(board: &Board) -> Evaluation {
let mut result = 0;
for (SidedPiece(side, piece), square) in board.inner().into_iter() {
let side_factor = if side == Side::Black { -1 } else { 1 };
let piece_value = match piece {
Piece::Pawn => 100,
Piece::Knight => 300,
Piece::Bishop => 325,
Piece::Rook => 500,
Piece::Queen => 900,
Piece::King => 0,
};
let piece_value = params::piece_value(piece);

result += side_factor * piece_value;
result += piece_value * side_factor;

if Some(square) == wk_shield || Some(square) == bk_shield {
result += 65 * side_factor;
result += params::KING_SHIELD * side_factor;
}

if bb.fullmove_clock > 40 && piece == Piece::Pawn {
result += 10 * square.rank::<i32>();
result += params::ADVANCE_PAWN_GAIN * square.rank::<i32>();
}
}

let white_moves = PseudoMoveGenerator::new_for_side(board.inner(), Side::White).len() as i32;
let black_moves = PseudoMoveGenerator::new_for_side(board.inner(), Side::Black).len() as i32;
let move_diff = white_moves - black_moves;

result += 100.min(5 * (white_moves - black_moves));
result += params::MAX_GAIN_DIFF_MOVES.min(params::MOVE_DIFF_WEIGHT * move_diff);
Evaluation(result)
}
16 changes: 16 additions & 0 deletions flimsybird/src/params.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use cheng::Piece;

pub const fn piece_value(piece: Piece) -> i32 {
match piece {
Piece::Pawn => 100,
Piece::Knight => 300,
Piece::Bishop => 325,
Piece::Rook => 500,
Piece::Queen => 900,
Piece::King => 0,
}
}
pub const KING_SHIELD: i32 = 65;
pub const ADVANCE_PAWN_GAIN: i32 = 10;
pub const MAX_GAIN_DIFF_MOVES: i32 = 100;
pub const MOVE_DIFF_WEIGHT: i32 = 5;

0 comments on commit 8a3e3c1

Please sign in to comment.