day 13 task 2 UI fix

This commit is contained in:
Johannes
2019-12-14 18:11:05 +01:00
parent b67ed69f7d
commit 9a2531b982

View File

@@ -81,20 +81,25 @@ impl Game {
self.pc.clear_output(); self.pc.clear_output();
let done = self.pc.run_until_input_empty(); let done = self.pc.run_until_input_empty();
let output = self.pc.get_output().into_iter().map(|it| *it).collect_vec(); let output = self.pc.get_output().into_iter().map(|it| *it).collect_vec();
let mut score = 0; let mut score = None;
output output
.iter() .iter()
.tuples() .tuples()
.scan(&mut self.field, |map, (x, y, t)| { .scan(&mut self.field, |map, (x, y, t)| {
if *x == -1 && *y == 0 { if *x == -1 && *y == 0 {
score = *t; score = Some(*t);
} else { } else {
map.insert((*x, *y), FieldType::from(*t)); map.insert((*x, *y), FieldType::from(*t));
} }
Some(()) Some(())
}) })
.any(|_| false); .any(|_| false);
self.score = score;
// stupid workaround because I cannot access score from within the clojure,
// due to then double-borrowing of mutable reference to self
if let Some(score) = score {
self.score = score;
}
if self.show_output { if self.show_output {
self.print(); self.print();
} }