diff --git a/README.md b/README.md index a368b22..3e7ba08 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ The current control scheme adheres to vim-like keybindings and is modal. ### Todo - - [ ] Game logic + - [x] Game logic - [x] Validate Sudokus - [x] Generate Sudokus - [x] Difficulties to choose @@ -69,7 +69,7 @@ The current control scheme adheres to vim-like keybindings and is modal. - [x] Preselect numbers - [x] Edit Mode to (re)place numbers - [x] Markup Mode to mark where numbers could go - - [ ] Autoremove marks after placing number in edit mode + - [x] Autoremove marks after placing number in edit mode - [x] Go Mode to move to blocks 1-9 - [x] Toggle Number/Mark with Space - [ ] Undo/Redo stack diff --git a/src/main.rs b/src/main.rs index 7059835..a4949b4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ use std::{io, time::Duration}; fn main() { let mut screen = Screen::init(io::stdout()); - let mut state = State::init(Difficulty::Expert); + let mut state = State::init(Difficulty::Mid); screen.draw_board().or_crash(); loop { diff --git a/src/state.rs b/src/state.rs index ad71ad8..b2148a4 100644 --- a/src/state.rs +++ b/src/state.rs @@ -102,10 +102,11 @@ impl State { pub fn toggle_current_cell(&mut self) { if self.current_cell_is_modifiable() { - *self.current_cell() = if *self.current_cell() == self.preselection { - 0 + if *self.current_cell() == self.preselection { + *self.current_cell() = 0; } else { - self.preselection + *self.current_cell() = self.preselection; + self.delete_colliding_marks(self.preselection, self.cur_row, self.cur_col); } } } @@ -116,6 +117,14 @@ impl State { } } + pub fn delete_colliding_marks(&mut self, num: u8, row: usize, col: usize) { + for i in 0..9 { + self.markups[i][col][num as usize - 1] = false; + self.markups[row][i][num as usize - 1] = false; + self.markups[row / 3 * 3 + i / 3][col / 3 * 3 + i % 3][num as usize - 1] = false; + } + } + pub fn enter_mode(&mut self, mode: Mode) { match mode { Mode::Go => {