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
@@ -161,3 +161,22 @@ fn test_08_stacked_you_moves_together() {
|
||||
assert_eq!(b.pos_of(first), Some((2, 2)));
|
||||
assert_eq!(b.pos_of(second), Some((2, 2)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_08_stack_is_age_ordered() {
|
||||
let mut b = new_baba(empty_level(3, 3));
|
||||
write(&mut b, &[("BABA", 0, 0), ("IS", 1, 0), ("YOU", 2, 0)]);
|
||||
let baba = b.place("baba", 0, 2);
|
||||
b.place("rock", 1, 2);
|
||||
b.place("key", 1, 2);
|
||||
|
||||
assert_eq!(b.stack_at(1, 2), vec!["rock", "key"]);
|
||||
|
||||
b.move_dir(Dir::Right);
|
||||
|
||||
assert_eq!(b.pos_of(baba), Some((1, 2)));
|
||||
assert_eq!(b.kinds_at(1, 2), vec!["baba", "key", "rock"]);
|
||||
// Oldest first: Baba arrived last, but it was placed first.
|
||||
assert_eq!(b.stack_at(1, 2), vec!["baba", "rock", "key"]);
|
||||
assert_eq!(b.stack_at(0, 2), Vec::<String>::new());
|
||||
}
|
||||
@@ -163,3 +163,25 @@ test("test_08_stacked_you_moves_together", () => {
|
||||
expect(b.posOf(first)).toEqual([2, 2]);
|
||||
expect(b.posOf(second)).toEqual([2, 2]);
|
||||
});
|
||||
|
||||
test("test_08_stack_is_age_ordered", () => {
|
||||
const b = newBaba(emptyLevel(3, 3));
|
||||
write(b, [
|
||||
["BABA", 0, 0],
|
||||
["IS", 1, 0],
|
||||
["YOU", 2, 0],
|
||||
]);
|
||||
const baba = b.place("baba", 0, 2);
|
||||
b.place("rock", 1, 2);
|
||||
b.place("key", 1, 2);
|
||||
|
||||
expect(b.stackAt(1, 2)).toEqual(["rock", "key"]);
|
||||
|
||||
b.move("right");
|
||||
|
||||
expect(b.posOf(baba)).toEqual([1, 2]);
|
||||
expect(b.kindsAt(1, 2)).toEqual(["baba", "key", "rock"]);
|
||||
// Oldest first: Baba arrived last, but it was placed first.
|
||||
expect(b.stackAt(1, 2)).toEqual(["baba", "rock", "key"]);
|
||||
expect(b.stackAt(0, 2)).toEqual([]);
|
||||
});
|
||||
Reference in new issue
Block a user