move tracking # pieces into Simul

This commit is contained in:
tali 2023-04-13 18:33:12 -04:00
parent e62270cd42
commit a76f03687a
2 changed files with 13 additions and 4 deletions

View File

@ -96,19 +96,20 @@ fn simulation(
previews: config.game.rules.previews,
};
let mut sim = sim::Simul::new(seed, sim_opts);
let mut pieces = 0;
let time_start = std::time::Instant::now();
while sim.lines_left() > 0 {
// TODO: progress bar
if !io.quiet {
eprintln!("#{}, {} left", pieces, sim.lines_left());
eprintln!("#{}, {} left", sim.pieces(), sim.lines_left());
}
let mut bot = bot::Bot::new(
sim.matrix(),
mino::Queue::new(sim.queue().hold(), sim.queue().next()),
);
for i in 0..config.bot.iters {
bot.think();
if i % 1000 == 999 {
@ -118,7 +119,6 @@ fn simulation(
if let Some(placement) = bot.suggest() {
sim.play(placement);
pieces += 1;
if let Some(moves) = moves.as_mut() {
moves.push(output::Move { placement })
@ -127,6 +127,7 @@ fn simulation(
break;
}
}
let time_end = std::time::Instant::now();
let profile = data.profile.then(|| output::Profile {
@ -136,7 +137,7 @@ fn simulation(
output::Output {
seed,
cleared: config.game.goal - sim.lines_left(),
pieces,
pieces: sim.pieces(),
config: config.game,
moves,
profile,

View File

@ -21,6 +21,7 @@ pub struct Simul {
queue: Queue,
garbage: Garbage,
matrix: MatBuf,
pieces: usize,
lines_left: usize,
}
@ -40,6 +41,7 @@ impl Simul {
queue,
garbage,
matrix,
pieces: 0,
lines_left: options.goal,
}
}
@ -48,8 +50,10 @@ impl Simul {
/// and garbage lines.
pub fn play(&mut self, piece: Piece) {
// play piece
self.pieces += 1;
self.queue.remove(piece.ty);
piece.cells().fill(&mut self.matrix);
// process line clears
let c = self.matrix.clear_lines();
self.lines_left -= self.garbage.clear(c.start);
@ -64,6 +68,10 @@ impl Simul {
&self.queue
}
pub fn pieces(&self) -> usize {
self.pieces
}
pub fn lines_left(&self) -> usize {
self.lines_left
}