elo: improve UX on live updating leaderboard
This commit is contained in:
parent
875c1737e5
commit
6672b61462
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -422,6 +422,7 @@ name = "othello"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec",
|
"arrayvec",
|
||||||
|
"console",
|
||||||
"const_fn",
|
"const_fn",
|
||||||
"criterion",
|
"criterion",
|
||||||
"crossbeam-channel",
|
"crossbeam-channel",
|
||||||
|
|||||||
@ -23,6 +23,7 @@ debug = true
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
arrayvec = "0.7"
|
arrayvec = "0.7"
|
||||||
|
console = "0.15.11"
|
||||||
const_fn = "0.4"
|
const_fn = "0.4"
|
||||||
crossbeam-channel = "0.5.14"
|
crossbeam-channel = "0.5.14"
|
||||||
either = "1.13"
|
either = "1.13"
|
||||||
|
|||||||
@ -5,7 +5,7 @@ use crate::{
|
|||||||
logic::{ChildrenEvalMethod, FutureMoveConfig},
|
logic::{ChildrenEvalMethod, FutureMoveConfig},
|
||||||
repr::{Board, Piece, Winner},
|
repr::{Board, Piece, Winner},
|
||||||
};
|
};
|
||||||
use indicatif::{ParallelProgressIterator, ProgressStyle};
|
use indicatif::{ParallelProgressIterator, ProgressStyle, TermLike};
|
||||||
use rand::seq::SliceRandom;
|
use rand::seq::SliceRandom;
|
||||||
use rayon::iter::{IntoParallelIterator, ParallelIterator};
|
use rayon::iter::{IntoParallelIterator, ParallelIterator};
|
||||||
use skillratings::{
|
use skillratings::{
|
||||||
@ -164,6 +164,7 @@ impl PlayerArena {
|
|||||||
// Immediately drop our copy of the sender so the channel closes properly
|
// Immediately drop our copy of the sender so the channel closes properly
|
||||||
drop(sender);
|
drop(sender);
|
||||||
|
|
||||||
|
let term = console::Term::stdout();
|
||||||
// Process results on main thread as they arrive
|
// Process results on main thread as they arrive
|
||||||
let mut received_num = 0;
|
let mut received_num = 0;
|
||||||
while let Ok((i, j, o)) = receiver.recv() {
|
while let Ok((i, j, o)) = receiver.recv() {
|
||||||
@ -172,7 +173,11 @@ impl PlayerArena {
|
|||||||
|
|
||||||
// print the leaderboard every 5 steps
|
// print the leaderboard every 5 steps
|
||||||
if received_num % 5 == 0 {
|
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
|
// break if all pairs were recieved
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user