Skip to content

Commit

Permalink
Kings heatmap applied now
Browse files Browse the repository at this point in the history
  • Loading branch information
N1ckn1ght committed May 11, 2024
1 parent 8985875 commit c10349a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ace"
version = "1.0.19"
version = "1.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
19 changes: 5 additions & 14 deletions src/engine/chara.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use super::{clock::Clock, options::Options, weights::Weights, zobrist::Zobrist};

const CENTER: [u64; 2] = [0b0000000000000000000110000001100000011000000000000000000000000000, 0b0000000000000000000000000001100000011000000110000000000000000000];
const STRONG: [u64; 2] = [0b0000000001111110011111100011110000000000000000000000000000000000, 0b0000000000000000000000000000000000111100011111100111111000000000];
const ROUNDS: [u64; 3] = [0b1111111110000001100000011000000110000001100000011000000111111111, 0b0000000001111110010000100100001001000010010000100111111000000000, 0b0000000000000000001111000010010000100100001111000000000000000000];

const DEFAULT_VEC_CAPACITY: usize = 300;

Expand Down Expand Up @@ -1230,6 +1229,11 @@ impl Chara {
}
}

score_pd[0] += self.w.heatmap[0][K ][kbits[0]];
score_pd[0] += self.w.heatmap[0][K2][kbits[1]];
score_pd[1] += self.w.heatmap[1][K ][kbits[0]];
score_pd[1] += self.w.heatmap[1][K2][kbits[1]];

score_pd[0] += self.w.k_mobility_as_q[0][0] * (self.board.get_sliding_diagonal_attacks(kbits[0], occup, sides[0]) | self.board.get_sliding_straight_attacks(kbits[0], occup, sides[0])).count_ones() as i32;
score_pd[0] += self.w.k_mobility_as_q[0][1] * (self.board.get_sliding_diagonal_attacks(kbits[1], occup, sides[1]) | self.board.get_sliding_straight_attacks(kbits[1], occup, sides[1])).count_ones() as i32;

Expand Down Expand Up @@ -1267,19 +1271,6 @@ impl Chara {
if bptr[B2] != 0 && (bptr[B2] & (bptr[B2] - 1)) != 0 {
score += self.w.s_bishop_pair[1];
}

for (ally, bb) in [bptr[K], bptr[K2]].into_iter().enumerate() {
let mut cpd = [0, 0];
for ring in ROUNDS.iter() {
if bb & ring != 0 {
break;
}
cpd[0] += self.w.k_center_dist[0][ally];
cpd[1] += self.w.k_center_dist[1][ally];
}
score_pd[0] += cpd[0];
score_pd[1] += cpd[1];
}

score += ((score_pd[0] as f32 * phase_diff) + (score_pd[1] as f32 * (1.0 - phase_diff))) as i32;
score += self.w.s_mobility * (mobility[0].count_ones() as i32 - mobility[1].count_ones() as i32);
Expand Down
24 changes: 19 additions & 5 deletions src/engine/weights.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::frame::util::flip;
use crate::frame::util::*;

pub struct Weights {
/* These weights are stored with respect to the colour, black pieces will provide negative values
Expand Down Expand Up @@ -30,7 +30,6 @@ pub struct Weights {
pub k_mobility_as_q: [[i32; 2]; 2], // king security (phased)
pub k_pawn_dist1: [[i32; 2]; 2], // bonus if near passing pawn (phased)
pub k_pawn_dist2: [[i32; 2]; 2], // bonus if near passing pawn (phased)
pub k_center_dist: [[i32; 2]; 2], // if king in/near center (phased, per outer ring)
pub g_atk_pro: [i32; 2], // per profitable attack (lazy check for pawns)
pub g_atk_pro_pinned: [i32; 2], // per profitable attack on pinned piece (lazy check for pawns)
pub g_atk_pro_double: [i32; 2], // per double profitable attack (e.g. knight fork!)
Expand Down Expand Up @@ -75,7 +74,6 @@ impl Weights {
let k_mobility_as_q_pre = [-4, 0]; // second is always 0
let k_pawn_dist1_pre = [0, 140];
let k_pawn_dist2_pre = [0, 60];
let k_center_dist_pre = [-40, 100];
let g_atk_pro_pre = 42;
let g_atk_pro_pinned_pre = 710;
let g_atk_pro_double_pre = 840;
Expand All @@ -90,7 +88,7 @@ impl Weights {
let s_turn_pre = 35;
let s_turn_div = 12;

/* These are PeSTO values (used as 1/4 score tiebreakers) + Kaissa weights (x4 of course) + my improvisation:
/* These are PeSTO values (used as 3/8 score tiebreakers) + Kaissa weights (x4 of course) + my improvisation:
+54/0 per pawn in center (d4-e6) in mittelspiel
+20/0 per pawn at c4-c6
+10/10 for pawns per every rank starting from 3rd (e.g. +10/20/30...)
Expand All @@ -103,6 +101,7 @@ impl Weights {
-25/0 per rook at b1, g1
+120/30 per rook on 7th
+8/0 per queen at initial
-!! additional weights in Lazy Application
*/

let pesto = [
Expand Down Expand Up @@ -258,6 +257,22 @@ impl Weights {
}
}

/* Lazy Application */

// additional king near center weights (-40 per ring in mittelspiel, +100 per ring in endspiel)
const ROUNDS: [u64; 3] = [0b0000000001111110010000100100001001000010010000100111111000000000, 0b0000000000000000001111000010010000100100001111000000000000000000, 0b0000000000000000000000000001100000011000000000000000000000000000];
let kcm = -10;
let kce = 60;
for (mult, mut round) in ROUNDS.into_iter().enumerate() {
while round != 0 {
let bit = pop_bit(&mut round);
heatmap[0][K ][bit] += kcm * (mult as i32 + 1);
heatmap[0][K2][bit] -= kcm * (mult as i32 + 1);
heatmap[1][K ][bit] += kce * (mult as i32 + 1);
heatmap[1][K2][bit] -= kce * (mult as i32 + 1);
}
}

/* Transform other W */

let mut g_atk_near_king: [[i32; 5]; 2] = [g_atk_near_king_pre, g_atk_near_king_pre];
Expand Down Expand Up @@ -294,7 +309,6 @@ impl Weights {
k_mobility_as_q: [colour_transform(k_mobility_as_q_pre[0]), colour_transform(k_mobility_as_q_pre[1])],
k_pawn_dist1: [colour_transform(k_pawn_dist1_pre[0]), colour_transform(k_pawn_dist1_pre[1])],
k_pawn_dist2: [colour_transform(k_pawn_dist2_pre[0]), colour_transform(k_pawn_dist2_pre[1])],
k_center_dist: [colour_transform(k_center_dist_pre[0]), colour_transform(k_center_dist_pre[1])],
g_atk_pro: colour_transform(g_atk_pro_pre),
g_atk_pro_pinned: colour_transform(g_atk_pro_pinned_pre),
g_atk_pro_double: colour_transform(g_atk_pro_double_pre),
Expand Down
2 changes: 1 addition & 1 deletion src/frame/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{cmp::min, fs, io::Cursor, path::Path};
use byteorder::{ReadBytesExt, WriteBytesExt, LittleEndian};
use phf::phf_map;

pub const MYNAME: &str = "Akira CE v1.0.19";
pub const MYNAME: &str = "Akira CE v1.1.0";

/* LIMITATIONS */

Expand Down

0 comments on commit c10349a

Please sign in to comment.