From 523f70eb9eddacd5f008e746a88c2fc4e4171697 Mon Sep 17 00:00:00 2001 From: Stephen Enders Date: Sat, 12 Feb 2022 12:41:19 -0500 Subject: Prevent piece capture on illegal move You could capture a piece on a move that was shorter/longer than a valid placement. For example: if you rolled a 2 and there was an enemy piece 1 space away. You could place your token in space 1, remove the enemy piece, but your move wouldn't count as valid and you'd snap back to your original position. By placing the catpure method after the "in_place" we ensure we only remove the enemy piece if its fully valid. --- src/ur.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/ur.cpp b/src/ur.cpp index afc72d3..10868a0 100644 --- a/src/ur.cpp +++ b/src/ur.cpp @@ -369,17 +369,6 @@ main() pieces, enemyPieces, takenPieceId)) { - // did we take a piece - if (takenPieceId >= 0) { - for (auto& ep : (*enemyPieces)) { - if (ep.id == takenPieceId) { - Log::debug("Captured piece " + Log::str(takenPieceId) + - " returning to board side"); - ep.sprite.setPosition(ep.origin); - ep.position = -1; - } - } - } grabbed_piece->sprite.setPosition(s.getPosition()); if (bp.position == (grabbed_piece->position + turn_roll)) { @@ -387,6 +376,19 @@ main() Log::str(bp.position)); grabbed_piece->position = bp.position; in_place = true; + + // did we take a piece + if (takenPieceId >= 0) { + for (auto& ep : (*enemyPieces)) { + if (ep.id == takenPieceId) { + Log::debug("Captured piece " + + Log::str(takenPieceId) + + " returning to board side"); + ep.sprite.setPosition(ep.origin); + ep.position = -1; + } + } + } } break; } -- cgit v1.2.3-54-g00ecf