Compare commits

..

No commits in common. "2ae53bc4649b71a49dfd3fb8f7f8e5565a0c6c5d" and "2e46abbee0c619c9c9592a59895579daf5e4f48a" have entirely different histories.

5 changed files with 9 additions and 46 deletions

View file

@ -24,7 +24,6 @@ serde = ["dep:serde"]
[dependencies]
anyhow = "1.0.81"
chrono = { version = "0.4.37" }
clap = { version = "4.5.3", features = ["derive"], optional = true }
colored = { version = "2.1.0", optional = false }
libpt = "0.4.2"
@ -32,7 +31,6 @@ rand = "0.8.5"
regex = "1.10.3"
serde = { version = "1.0.197", optional = true, features = ["serde_derive"] }
serde_json = { version = "1.0.114", optional = true }
# serde_with = "3.7.0"
thiserror = "1.0.58"
[[bin]]

View file

@ -11,12 +11,8 @@ pub struct BuiltinBenchmark<'wl, WL: WordList, SL: Solver<'wl, WL>> {
builder: GameBuilder<'wl, WL>,
}
impl<'wl, WL, SL> Benchmark<'wl, WL, SL> for BuiltinBenchmark<'wl, WL, SL>
where
WL: WordList,
WL: 'wl,
SL: Solver<'wl, WL>,
SL: 'wl,
impl<'wl, WL: WordList, SL: Solver<'wl, WL>> Benchmark<'wl, WL, SL>
for BuiltinBenchmark<'wl, WL, SL>
{
fn build(wordlist: &'wl WL, solver: SL) -> crate::error::WResult<Self> {
let builder: GameBuilder<_> = Game::builder(wordlist);

View file

@ -19,7 +19,6 @@ where
WL: WordList,
WL: 'wl,
SL: Solver<'wl, WL>,
SL: 'wl,
{
fn build(wordlist: &'wl WL, solver: SL) -> WResult<Self>;
fn builder(&'wl self) -> &'wl GameBuilder<'wl, WL>;
@ -28,12 +27,16 @@ where
}
fn solver(&'wl self) -> &'wl SL;
fn play(&'wl self) -> WResult<GuessResponse> {
self.solver().play(&mut self.make_game()?)
// FIXME: wth why does the lifetime break here?
let mut game: Game<'wl, WL> = self.make_game()?;
todo!()
}
fn bench(&'wl self, n: usize) -> WResult<Report> {
// PERF: it would be better to make this multithreaded
let part = n / 20;
let mut report = Report::new();
let start = std::time::Instant::now();
for i in 0..n {
// TODO: limit execution time for the following, perhaps async
@ -43,8 +46,6 @@ where
}
}
report.finalize();
Ok(report)
}
}

View file

@ -1,4 +1,3 @@
use chrono::{self, NaiveDateTime, NaiveTime, TimeDelta};
use std::fmt::Display;
#[cfg(feature = "serde")]
@ -7,24 +6,14 @@ use serde::{Deserialize, Serialize};
use crate::game::response::GuessResponse;
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Report {
data: Vec<GuessResponse>,
start: NaiveDateTime,
end: Option<NaiveDateTime>,
benchtime: Option<TimeDelta>,
/// is the benchmark finished?
finished: bool,
}
impl Report {
pub fn new() -> Self {
Self {
data: Vec::new(),
start: chrono::Local::now().naive_local(),
benchtime: None,
end: None,
finished: false,
}
Self { data: Vec::new() }
}
pub fn add(&mut self, data: GuessResponse) {
self.data.push(data)
@ -41,23 +30,6 @@ impl Report {
pub fn avg_score(&self) -> usize {
todo!()
}
/// finalize the record
///
/// Sets the [benchtime](Report::benchtime) and [over](Report::over). In future versions, this
/// method might be used to precompute statistical information from the data.
pub(crate) fn finalize(&mut self) {
self.end = Some(chrono::Local::now().naive_local());
self.benchtime = Some(self.end.unwrap() - self.start);
self.finished = true;
}
/// is the report finished?
///
/// Will be true after the [benchmark][super::Benchmark] is done.
pub fn finished(&self) -> bool {
self.finished
}
}
impl Display for Report {

View file

@ -58,10 +58,6 @@ fn main() -> anyhow::Result<()> {
println!("word length: must be {} long but is {}", game.length(), len);
continue;
}
GameError::WordNotInWordlist(w) => {
println!("bad word: word \"{w}\" is not in the wordlist",);
continue;
}
_ => {
return Err(err.into());
}