From 9a2531b982cc3c4f5104ad4e40b1f9783e68d10e Mon Sep 17 00:00:00 2001 From: Johannes Date: Sat, 14 Dec 2019 18:11:05 +0100 Subject: [PATCH] day 13 task 2 UI fix --- src/tasks/day13.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/tasks/day13.rs b/src/tasks/day13.rs index ee6295b..fe3529b 100644 --- a/src/tasks/day13.rs +++ b/src/tasks/day13.rs @@ -81,20 +81,25 @@ impl Game { self.pc.clear_output(); let done = self.pc.run_until_input_empty(); let output = self.pc.get_output().into_iter().map(|it| *it).collect_vec(); - let mut score = 0; + let mut score = None; output .iter() .tuples() .scan(&mut self.field, |map, (x, y, t)| { if *x == -1 && *y == 0 { - score = *t; + score = Some(*t); } else { map.insert((*x, *y), FieldType::from(*t)); } Some(()) }) .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 { self.print(); }