refactor : StateManager
All checks were successful
Linux arm64 / Build (push) Successful in 41s

This commit is contained in:
Melvyn
2025-02-02 16:42:31 +01:00
parent b4157167b5
commit 627c49b961

View File

@@ -4,12 +4,22 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Stack; import java.util.Stack;
//TODO: doc /**
* Une pile, qui réprésente les états d'un MultiDoku,
* utile pour les Solvers.
*/
public class StateManager { public class StateManager {
private final Stack<Map<Cell, Integer>> states; /**
* Le MultiDoku auquel il est associé.
*/
private final MultiDoku doku; private final MultiDoku doku;
/**
* La pile des états du MultiDoku associé.
*/
private final Stack<Map<Cell, Integer>> states;
public StateManager(MultiDoku doku) { public StateManager(MultiDoku doku) {
this.states = new Stack<>(); this.states = new Stack<>();
this.doku = doku; this.doku = doku;
@@ -21,12 +31,12 @@ public class StateManager {
} }
public void popState() { public void popState() {
assert (states.size() > 0); assert (!states.isEmpty());
restoreState(states.pop()); restoreState(states.pop());
} }
public Map<Cell, Integer> popAndGetState() { public Map<Cell, Integer> popAndGetState() {
assert (states.size() > 0); assert (!states.isEmpty());
var currentState = saveState(); var currentState = saveState();
restoreState(states.pop()); restoreState(states.pop());
return currentState; return currentState;