Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions arche-core/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ pub struct Position {
pub operations: HashMap<String, String>,
}

impl Position {
/// The position as a board. A suite is read from a committed file, so a
/// fen that does not parse is a broken suite and panics, naming the
/// instrument that was reading it.
pub fn board(&self, instrument: &str) -> Board {
Board::from_fen(&self.fen)
.unwrap_or_else(|e| panic!("{} position {} does not parse: {}", instrument, self.id, e))
}
}

pub fn positions() -> Vec<Position> {
parse_epd(SUITE)
}
Expand Down Expand Up @@ -245,9 +255,7 @@ fn run(
let positions = positions
.iter()
.map(|position| {
let board = Board::from_fen(&position.fen)
.unwrap_or_else(|e| panic!("bench position {} does not parse: {}", position.id, e));
let mut engine = AlphaBeta::with_config(board, table_bytes, config);
let mut engine = AlphaBeta::with_config(position.board("bench"), table_bytes, config);
if audit && !engine.audit_signatures() {
return None;
}
Expand Down Expand Up @@ -294,7 +302,9 @@ fn run(
})
}

fn share(part: u64, whole: u64) -> f64 {
/// A part as a percentage of the whole, and zero where there is no whole.
/// The strategic suite's shares are taken the same way.
pub(crate) fn share(part: u64, whole: u64) -> f64 {
if whole == 0 {
0.0
} else {
Expand Down Expand Up @@ -685,6 +695,8 @@ mod tests {
}
}

/// Two audited runs of it count the same, since the audit reads the
/// search and nothing about the run.
#[test]
fn an_audited_run_searches_the_same_tree() {
let suite = small_suite();
Expand All @@ -700,6 +712,9 @@ mod tests {
.collect::<Vec<_>>()
};
assert_eq!(played(&plain), played(&audited));
let again = run_audited_suite(&suite, Reach::Depth(4), 4 << 20, SearchConfig::default())
.expect("the keys");
assert_eq!(audited.signatures(), again.signatures());
}

/// The false accepts are pinned at zero rather than bounded. The
Expand Down Expand Up @@ -797,16 +812,6 @@ mod tests {
assert!(none.narrow().all(|(_, _, expected)| expected == 0.0));
}

#[test]
fn two_audited_runs_count_the_same() {
let suite = small_suite();
let first = run_audited_suite(&suite, Reach::Depth(4), 4 << 20, SearchConfig::default())
.expect("keys");
let second = run_audited_suite(&suite, Reach::Depth(4), 4 << 20, SearchConfig::default())
.expect("keys");
assert_eq!(first.signatures(), second.signatures());
}

/// A deliberate change to the search is expected to move these: update
/// them in the same commit, from `arche bench`, so the diff states how
/// much of each tree the engine now looks at.
Expand Down
Loading
Loading