From 1c950d3934ad29724cbb05adfc066b4468ffec19 Mon Sep 17 00:00:00 2001 From: Vegard Matthey Date: Sun, 2 Jun 2024 15:59:20 +0200 Subject: [PATCH] fix score --- src/main.rs | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index d67e87d..df4b844 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,6 +49,8 @@ fn main() { if let Some(i) = rot_index { game.last_rotation = Some((r, i)); } + } else { + game.last_rotation = None; } } } @@ -189,8 +191,8 @@ struct Current { t_spin: Option, lines: u32, points: u32, - perfect: bool, back_to_back: bool, + perfect: bool, } impl Current { @@ -199,8 +201,8 @@ impl Current { t_spin: None, lines: 0, points: 0, - perfect: false, back_to_back: false, + perfect: false, } } } @@ -312,6 +314,7 @@ fn points( combo: &mut i32, prev_difficult: &mut bool, ) { + current.points = 0; if current.lines == 0 { *combo = -1; if current.t_spin.is_none() { @@ -331,22 +334,18 @@ fn points( }; current.points += combo_mul * 50 * level; - let mut perfect = true; + current.perfect = true; 'outer: for line in block_grid.0 { for b in line { if b.is_some() { - perfect = false; + current.perfect = false; break 'outer; } } } - current.perfect = perfect; - - let mut points = 0; - - if perfect { - points += match current.lines { + if current.perfect { + current.points += match current.lines { 1 => 800 * level, 2 => 1200 * level, 3 => 1800 * level, @@ -355,7 +354,7 @@ fn points( }; } - points += match current.t_spin { + current.points += match current.t_spin { Some(TSpin::Proper) => match current.lines { 0 => 400 * level, 1 => 800 * level, @@ -379,23 +378,26 @@ fn points( }; match (current.lines, ¤t.t_spin) { + (1..=3, _) => { + current.back_to_back = false; + *prev_difficult = false; + } (4, _) => { if *prev_difficult { - points += points / 2; + current.points += current.points / 2; current.back_to_back = true; } *prev_difficult = true; } (1.., Some(_)) => { if *prev_difficult { - points += points / 2; + current.points += current.points / 2; current.back_to_back = true; } *prev_difficult = true; } _ => *prev_difficult = false, } - current.points = points; } fn handle_action(