elo: improve UX on live updating leaderboard

This commit is contained in:
Simon Gardling 2025-03-05 10:31:27 -05:00
parent 875c1737e5
commit 6672b61462
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D
3 changed files with 9 additions and 2 deletions

1
Cargo.lock generated
View File

@ -422,6 +422,7 @@ name = "othello"
version = "0.1.0"
dependencies = [
"arrayvec",
"console",
"const_fn",
"criterion",
"crossbeam-channel",

View File

@ -23,6 +23,7 @@ debug = true
[dependencies]
arrayvec = "0.7"
console = "0.15.11"
const_fn = "0.4"
crossbeam-channel = "0.5.14"
either = "1.13"

View File

@ -5,7 +5,7 @@ use crate::{
logic::{ChildrenEvalMethod, FutureMoveConfig},
repr::{Board, Piece, Winner},
};
use indicatif::{ParallelProgressIterator, ProgressStyle};
use indicatif::{ParallelProgressIterator, ProgressStyle, TermLike};
use rand::seq::SliceRandom;
use rayon::iter::{IntoParallelIterator, ParallelIterator};
use skillratings::{
@ -164,6 +164,7 @@ impl PlayerArena {
// Immediately drop our copy of the sender so the channel closes properly
drop(sender);
let term = console::Term::stdout();
// Process results on main thread as they arrive
let mut received_num = 0;
while let Ok((i, j, o)) = receiver.recv() {
@ -172,7 +173,11 @@ impl PlayerArena {
// print the leaderboard every 5 steps
if received_num % 5 == 0 {
println!("{}", self);
term.clear_last_lines(num)
.expect("unable to clear prev lines");
let formatted_self = format!("{}", self);
term.write_str(&formatted_self)
.expect("unable to write leaderboard");
}
// break if all pairs were recieved