Skip to content

Commit

Permalink
Eval/the great refactor (#275)
Browse files Browse the repository at this point in the history
* Use bytemuck to cast between weights struct and array

* Add EvalTrace to eval struct conditionally

* Add default trait for EvalTrace

because there's no generic default impl for arrays, as of yet

* Copy over all of the eval methods onto the eval struct

* Pass in explicit eval trace parameter

* Remove old eval implementation on Board

* Make eval terms standalone functions

Makes it easier to call from anywhere, without having to bootstrap a
full Eval struct

* Add conditional compilation so we don't tank nps

As expected, all of the branching in every single eval term is actually
a pretty big deal...

* Move over to new tracing everywhere

* Pull eval terms into separate file

I caved. Collocation my ass...

* Update IDEAS.md
  • Loading branch information
sroelants authored Aug 6, 2024
1 parent 2054911 commit dfe4427
Show file tree
Hide file tree
Showing 9 changed files with 970 additions and 1,725 deletions.
21 changes: 21 additions & 0 deletions Cargo.lock

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

12 changes: 5 additions & 7 deletions IDEAS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
- [] Use `improving` in LMR
- [ ] Reduce when eval is far below alpha (~delta pruning)
- [ ] IIR when TT entry depth is much more shallow (e.g., `depth - tt_depth > 4`)
- [ ] Cutnode reductions
- [ ] IIR more in cutnodes
- [ ] Cutnode LMR reductions

### Pruning
- [] Delta pruning
Expand All @@ -39,9 +40,9 @@
- [] Threat-based history

### Time management
- [ ] Use less time when bestmove remains stable
- [ ] Use less time when eval remains stable
- [ ] Use more time when subtree has more nodes? Or less? I don't really get
- [] Use less time when bestmove remains stable
- [] Use less time when eval remains stable
- [] Use more time when subtree has more nodes? Or less? I don't really get
this one, tbh.

## Evaluation
Expand Down Expand Up @@ -128,9 +129,6 @@
- [] Clear killer moves for the next ply in each node
- [ ] Don't store killers during null-search
- [] Yield killers in a fifo way (easy, since we "rotate" the moves out)
- [ ] Have "short moves" and "long moves", where the long move includes extra
information (like the moved piece), so we can index all of our history
table using long moves instead. (This essentially becomes our `HistIndex`.)
- [=] Performance tweaks in hot loops:
- [] Transmute between enums and integers, instead of lookups
- [] forego bounds checks
Expand Down
2 changes: 2 additions & 0 deletions simbelmyne/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ clap = { version = "4.4.7", features = ["derive"] }
itertools = "0.11.0"
rayon = "1.8.1"
arrayvec = "0.7.4"
bytemuck = { version = "1.16.3", features = ["derive", "min_const_generics"] }

[features]
default = ["spsa"]
spsa = []
wdl = []
texel = []
50 changes: 0 additions & 50 deletions simbelmyne/src/evaluate/lookups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ pub const FILES: BBTable = gen_files();

pub const PASSED_PAWN_MASKS: [BBTable; Color::COUNT] = gen_passed_pawn_masks();

pub const ISOLATED_PAWN_MASKS: BBTable = gen_isolated_pawn_masks();

pub const DOUBLED_PAWN_MASKS: [Bitboard; 8] = gen_doubled_pawn_masks();

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -69,39 +67,6 @@ const fn gen_passed_pawn_masks() -> [BBTable; Color::COUNT] {
masks
}

////////////////////////////////////////////////////////////////////////////////
//
// Isolated pawn masks
//
////////////////////////////////////////////////////////////////////////////////

const fn gen_isolated_pawn_masks() -> BBTable {
const A_FILE: Bitboard = Bitboard(0x101010101010101);

let mut sq: usize = 0;

let mut masks = [Bitboard::EMPTY; Square::COUNT];

while sq < 64 {
let file = sq % 8;
let mut mask = 0;

if file > 0 {
mask |= A_FILE.0 << file - 1;
}

if file < 7 {
mask |= A_FILE.0 << file + 1;
}

masks[sq] = Bitboard(mask);

sq += 1;
}

masks
}

////////////////////////////////////////////////////////////////////////////////
//
// Doubled pawn masks
Expand Down Expand Up @@ -162,18 +127,3 @@ fn passed_pawn_masks() {
Bitboard(0x38383838)
);
}

#[test]
fn isolated_pawn_masks() {
use Square::*;

assert_eq!(
ISOLATED_PAWN_MASKS[A6],
Bitboard(0x202020202020202)
);

assert_eq!(
ISOLATED_PAWN_MASKS[E4],
Bitboard(0x2828282828282828)
);
}
Loading

0 comments on commit dfe4427

Please sign in to comment.