aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortslil clingman <>2024-07-07 13:22:37 +0100
committertslil clingman <>2024-07-07 13:22:37 +0100
commit1735a79f0a53df37d9380b88ed98ee6fffc9ff36 (patch)
tree31ed07e92bf5e842c0faafa1025ccbf490243437
parent6edf7d4cdc19ee80b50c813835b8e36b011232b4 (diff)
fix bug in capstone -> wall logicHEADmain
From: ~devp Previously, the cap flag checked stone 0 of a stack rather than stone n-1, so it did not take into account a capstone moved as part of a stack. I additionally added logic to check that no other stones were dropped with the capstones, per Tak rules.
-rw-r--r--README.md6
-rw-r--r--src/game.rs10
2 files changed, 14 insertions, 2 deletions
diff --git a/README.md b/README.md
index a01db3f..4830c94 100644
--- a/README.md
+++ b/README.md
@@ -49,3 +49,9 @@ for this purpose.
Note that the engine is expected to respect the `[Variant XXX]` line
in the PTN game-state, so expect breakage with anything but the
default.
+
+## Additional contributors
+
+With thanks to
+
+- ~devp for fixing a capstone->wall flattening bug
diff --git a/src/game.rs b/src/game.rs
index 4a91755..6bc43dc 100644
--- a/src/game.rs
+++ b/src/game.rs
@@ -424,7 +424,7 @@ impl GameState {
}
let mut steps: usize = drops.len();
- let cap: bool = stack[0].stone == Stone::Capstone;
+ let cap: bool = stack[stack.len() - 1].stone == Stone::Capstone;
let mut pos_new = Position { x: pos.x, y: pos.y };
while steps > 0 {
@@ -453,7 +453,13 @@ impl GameState {
));
}
Stone::Standing => {
- if (steps > 1) || (!cap) {
+ if cap {
+ if (steps > 1) || (drops[drops.len() - 1] > 1) {
+ return Err(String::from(
+ "A capstone move may not flatten a standing stone unless dropped on its own.",
+ ));
+ }
+ } else {
return Err(String::from(
"A move may not cover a standing stone.",
));