Skip to content

Commit

Permalink
misc bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MinusKelvin committed Oct 14, 2020
1 parent 87b424a commit 246acd6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
13 changes: 10 additions & 3 deletions opening-book/pc-gen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ fn main() {
let mut i = 0;
while let Some(initial_bag) = bags.pop() {
i += 1;
let skip = std::fs::metadata(&format!("pc-{}.ccbook", i)).is_ok();
let mut book = BookBuilder::new();
let (send, recv) = crossbeam_channel::bounded(256);
let count = &std::sync::atomic::AtomicUsize::new(0);
Expand All @@ -43,6 +44,7 @@ fn main() {
if queued_bags.insert(bag) {
bags.push(bag);
}
if skip { continue }
let send = send.clone();
let combos = all_combinations.get(
&seq.iter().copied().collect()
Expand All @@ -57,10 +59,11 @@ fn main() {
}
let c = count.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
if 100*c / total != 100*(c+1) / total {
println!("{}%", (c+1) / total);
println!("{}%", 100*(c+1) / total);
}
});
}
if skip { return }
println!("Took {:?} to spawn solve tasks", t.elapsed());

drop(send);
Expand All @@ -76,14 +79,18 @@ fn main() {
println!("Took {:?} to add moves to the book", t.elapsed());
println!("book is {} positions large", book.positions().count());
});
if skip { continue }

let t = std::time::Instant::now();
book.recalculate_graph();
println!("Took {:?} to calculate the book", t.elapsed());
println!("{:?}", book.value_of_position(libtetris::Board::new().into()));
let initial_position = libtetris::Board::new_with_state(
[[false; 10]; 40], initial_bag.bag, initial_bag.hold, false, 0
).into();
println!("{:?}", book.value_of_position(initial_position));

let t = std::time::Instant::now();
book.compile(&[libtetris::Board::new().into()]).save(
book.compile(&[initial_position]).save(
std::fs::File::create(&format!("pc-{}.ccbook", i)).unwrap()
).unwrap();
println!("Took {:?} to save PC book {}", t.elapsed(), i);
Expand Down
8 changes: 4 additions & 4 deletions opening-book/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ impl BookBuilder {
} else {
next.insert(q.next().unwrap());
}
self.suggest_move_raw(position, next, &q.collect::<Vec<_>>(), state.bag)
self.suggest_move_raw(position, next, &q.collect::<Vec<_>>())
}

pub fn suggest_move_raw(
&self, pos: Position, next: EnumSet<Piece>, queue: &[Piece], bag: EnumSet<Piece>
&self, pos: Position, next: EnumSet<Piece>, queue: &[Piece]
) -> Option<FallingPiece> {
let values = &self.0.get(&pos)?.values;
let queue = queue.iter().copied().take(NEXT_PIECES)
Expand Down Expand Up @@ -210,9 +210,9 @@ impl BookBuilder {
fn build_position(&self, pos: &Position) -> Vec<(Sequence, Option<FallingPiece>)> {
let mut sequences = vec![];
for (next, bag) in pos.next_possibilities() {
for (queue, b) in possible_sequences(vec![], bag) {
for (queue, _) in possible_sequences(vec![], bag) {
let seq = Sequence { next, queue };
let mv = self.suggest_move_raw(*pos, next, &queue, b);
let mv = self.suggest_move_raw(*pos, next, &queue);
sequences.push((seq, mv));
}
}
Expand Down

0 comments on commit 246acd6

Please sign in to comment.