feat: undo in Module 9 and stackAt from Module 8; Lesson 8 quote matches the reference
Baba.undo() restores the level before the last step or move (board snapshot: objects in age order with ids, the id counter, and won; rules recompiled). place clears the history. SpellGrid's undo throws/panics 'not supported'. stackAt / stack_at lists a tile's kinds oldest first, on Baba and SpellGrid. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
21fb40c6f5
commit
820b378929
27 files changed
+530
-30
No files matched your search
@@ -317,6 +317,12 @@ impl Baba {
|
||||
kinds
|
||||
}
|
||||
|
||||
/// The kinds on tile (x, y), as `kinds_at`, but oldest object first.
|
||||
pub fn stack_at(&self, x: i32, y: i32) -> Vec<String> {
|
||||
let board = self.level.board();
|
||||
board.at(x, y).map(|o| o.kind.to_string()).collect()
|
||||
}
|
||||
|
||||
// ---- Module 9 ----
|
||||
|
||||
/// Play one whole turn: movement, parse, conversion, parse, hazards, win
|
||||
@@ -334,6 +340,12 @@ impl Baba {
|
||||
pub fn lost(&self) -> bool {
|
||||
self.level.lost()
|
||||
}
|
||||
|
||||
/// Put the level back as it was before the last `step` or `move_dir`. False, and
|
||||
/// no change, if there is none; repeated calls walk further back.
|
||||
pub fn undo(&mut self) -> bool {
|
||||
self.level.undo()
|
||||
}
|
||||
}
|
||||
|
||||
fn normalised(rules: &[puzzle::Rule]) -> Vec<String> {
|
||||
@@ -402,6 +414,10 @@ impl SpellGrid {
|
||||
kinds.sort();
|
||||
kinds
|
||||
}
|
||||
pub fn stack_at(&self, x: i32, y: i32) -> Vec<String> {
|
||||
let board = self.grid.level().board();
|
||||
board.at(x, y).map(|o| o.kind.to_string()).collect()
|
||||
}
|
||||
pub fn step(&mut self, dir: Dir) {
|
||||
self.grid.step(dir);
|
||||
}
|
||||
@@ -411,6 +427,11 @@ impl SpellGrid {
|
||||
pub fn lost(&self) -> bool {
|
||||
self.grid.level().lost()
|
||||
}
|
||||
/// Not supported: Part I has state (health, hands, the log) that the level's
|
||||
/// snapshot doesn't cover. Panics.
|
||||
pub fn undo(&mut self) -> bool {
|
||||
panic!("undo is not supported in SpellGrid");
|
||||
}
|
||||
|
||||
// ---- Module 10 ----
|
||||
|
||||
|
||||
Reference in new issue
Block a user