From c10eb9933689c7c8d58adb28a67ad1c8cb675a00 Mon Sep 17 00:00:00 2001 From: Patricia Aas Date: Mon, 2 Aug 2021 14:24:11 +0200 Subject: [PATCH] Early return in Clyde --- lib/Clyde.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Clyde.cpp b/lib/Clyde.cpp index 087a9ee..346fb08 100644 --- a/lib/Clyde.cpp +++ b/lib/Clyde.cpp @@ -25,10 +25,12 @@ Position Clyde::target(const GameState & gameState) const { // Clyde always target its scatter target, unless pacman is further than 8 tiles away auto targetPosition = scatterTarget(); + if (state == State::Scatter) + return targetPosition; const auto pacManPosition = gameState.pacMan.positionInGrid(); auto distanceFomPacMan = std::hypot(pos.x - pacManPosition.x, pos.y - pacManPosition.y); - if (state == State::Chase && distanceFomPacMan > 8) + if (distanceFomPacMan > 8) targetPosition = gridPositionToPosition(pacManPosition); return targetPosition;