Position search fixes from QA report 3
- The result cache keys on the board's move order too, so "in this move order" is not reused from another order of the same position. - While a search runs, the hover arrow and the position a game opens at belong to the rows shown; small databases keep the last result dimmed. - PGN: a game ending in its chosen occurrence has no next move (it was taken from a variation); Collector::add_match_with_next. - Average rating of a continuation only from games with both ratings. - Narrow windows: the pane switch stays visible, chips that do not fit become "+N more", columns hide by priority, the date becomes the year. - Ctrl+Shift+Backspace clears all conditions with the position; × for the position in small databases; the outcome cache is bounded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
b9eab389c7
commit
131e4b62fb
9 changed files with 289 additions and 104 deletions
|
|
@ -362,9 +362,8 @@ impl Worker<'_> {
|
|||
});
|
||||
} else {
|
||||
let mut rec = [0u8; CBB_RECORD];
|
||||
self.games.retain(|&(i, _)| {
|
||||
read_exact_at(cbb, &mut rec, at(i)).is_err() || sig.admits(&rec)
|
||||
});
|
||||
self.games
|
||||
.retain(|&(i, _)| read_exact_at(cbb, &mut rec, at(i)).is_err() || sig.admits(&rec));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -300,15 +300,16 @@ impl PositionTable {
|
|||
return;
|
||||
};
|
||||
let index = game as u32;
|
||||
out.add_match(Match {
|
||||
// The move after the chosen occurrence is the game's `next` (none when the
|
||||
// game ends there, whatever its other branches play).
|
||||
let first = self.first_child_move(at, refs);
|
||||
out.add_match_with_next(Match {
|
||||
index,
|
||||
ply: u32::from(self.nodes[at].ply),
|
||||
same_order: !other_order,
|
||||
in_variation,
|
||||
next: None,
|
||||
next: first.map(decode),
|
||||
});
|
||||
// The move after the chosen occurrence goes first: it is the game's `next`.
|
||||
let first = self.first_child_move(at, refs);
|
||||
if let Some(pos) = moves.iter().position(|m| Some(m.0) == first) {
|
||||
moves.swap(0, pos);
|
||||
}
|
||||
|
|
@ -647,6 +648,17 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn next_move_belongs_to_the_chosen_occurrence() {
|
||||
// The main line ends in the position; a variation reaches it and goes on.
|
||||
let db = db("1. e4 (1. Nf3 e5 2. e4 Nc6) 1... e5 2. Nf3 *\n");
|
||||
let t = table(&db);
|
||||
let out = search(&t, &db, &query(&["e4", "e5", "Nf3"]));
|
||||
assert_eq!(out.matches.len(), 1);
|
||||
assert!(!out.matches[0].in_variation);
|
||||
assert_eq!(out.matches[0].next, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn counts_each_move_of_a_game_once() {
|
||||
let db = db(PGN);
|
||||
|
|
|
|||
|
|
@ -86,11 +86,11 @@ impl Tally {
|
|||
GameResult::BlackWins => self.black_wins += 1,
|
||||
GameResult::Unknown => {}
|
||||
}
|
||||
for e in [white_elo, black_elo] {
|
||||
if e > 0 {
|
||||
self.elo_sum += u64::from(e);
|
||||
self.elo_count += 1;
|
||||
}
|
||||
// The average rating counts games where both ratings are known, like the
|
||||
// "strongest first" sort.
|
||||
if white_elo > 0 && black_elo > 0 {
|
||||
self.elo_sum += u64::from(white_elo) + u64::from(black_elo);
|
||||
self.elo_count += 2;
|
||||
}
|
||||
self.last_year = self.last_year.max(year);
|
||||
}
|
||||
|
|
@ -161,6 +161,8 @@ pub struct Collector {
|
|||
/// Per move: games that played it in their main line.
|
||||
main_line: HashMap<UciMove, u32>,
|
||||
ended: Tally,
|
||||
/// The last match whose first continuation was recorded (it decides `next`).
|
||||
continued: Option<u32>,
|
||||
}
|
||||
|
||||
impl Collector {
|
||||
|
|
@ -187,6 +189,13 @@ impl Collector {
|
|||
self.matches.push(m);
|
||||
}
|
||||
|
||||
/// Records a matching game whose [`Match::next`] is already decided (the move
|
||||
/// after its chosen occurrence); its continuations do not change it.
|
||||
pub fn add_match_with_next(&mut self, m: Match) {
|
||||
self.matches.push(m);
|
||||
self.continued = Some(m.index);
|
||||
}
|
||||
|
||||
/// Records one continuation of game `index` (added with [`Collector::add_match`]):
|
||||
/// a move played next (`main_line`: in the game's main line) or `None` when the
|
||||
/// game ends here. The first move recorded for a game is its [`Match::next`].
|
||||
|
|
@ -201,14 +210,18 @@ impl Collector {
|
|||
black_elo: u16,
|
||||
year: u16,
|
||||
) {
|
||||
// The first continuation belongs to the chosen occurrence: it is the game's
|
||||
// next move, even when it is the end of the game (later ones come from other
|
||||
// branches of a PGN game).
|
||||
if self.continued != Some(index)
|
||||
&& let Some(m) = self.matches.last_mut()
|
||||
&& m.index == index
|
||||
{
|
||||
m.next = next;
|
||||
self.continued = Some(index);
|
||||
}
|
||||
let tally = match next {
|
||||
Some(uci) => {
|
||||
if let Some(m) = self.matches.last_mut()
|
||||
&& m.index == index
|
||||
&& m.next.is_none()
|
||||
{
|
||||
m.next = Some(uci);
|
||||
}
|
||||
if main_line {
|
||||
*self.main_line.entry(uci).or_default() += 1;
|
||||
}
|
||||
|
|
@ -309,17 +322,25 @@ mod tests {
|
|||
let mut b = Collector::default();
|
||||
b.add(m(2), Some(e4), GameResult::BlackWins, 2500, 0, 2024);
|
||||
b.add(m(5), None, GameResult::Unknown, 0, 0, 0);
|
||||
// A game ending in its chosen occurrence keeps no next move, whatever its other
|
||||
// branches play.
|
||||
b.add_match(m(7));
|
||||
b.add_continuation(7, None, true, GameResult::Draw, 0, 0, 0);
|
||||
b.add_continuation(7, Some(e4), false, GameResult::Draw, 0, 0, 0);
|
||||
a.merge(b);
|
||||
let out = a.finish(&pos);
|
||||
assert_eq!(
|
||||
out.matches.iter().map(|m| m.index).collect::<Vec<_>>(),
|
||||
vec![1, 2, 3, 5]
|
||||
vec![1, 2, 3, 5, 7]
|
||||
);
|
||||
assert_eq!(out.matches[4].next, None, "ends in its chosen occurrence");
|
||||
assert_eq!(out.matches[2].next, Some(e4));
|
||||
assert_eq!(out.moves[0].san, "e4");
|
||||
assert_eq!(out.moves[0].tally.games, 2);
|
||||
assert_eq!(out.moves[0].tally.average_elo(), Some(2600));
|
||||
assert_eq!(out.moves[0].tally.games, 3);
|
||||
// Only game 3 has both ratings.
|
||||
assert_eq!(out.moves[0].tally.average_elo(), Some(2650));
|
||||
assert_eq!(out.moves[0].tally.last_year, 2024);
|
||||
assert_eq!(out.moves[1].san, "d4");
|
||||
assert_eq!(out.ended.games, 1);
|
||||
assert_eq!(out.ended.games, 2);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue