From dac3b12dc4bb100518ab4a4e13d6393591640921 Mon Sep 17 00:00:00 2001 From: Corentin Jabot Date: Wed, 7 Jul 2021 10:38:52 +0200 Subject: [PATCH] Explain how the ghosts move --- lib/Ghost.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/Ghost.cpp b/lib/Ghost.cpp index eeb8940..99507d1 100644 --- a/lib/Ghost.cpp +++ b/lib/Ghost.cpp @@ -115,6 +115,22 @@ double Ghost::speed() const { return 0.75; } +/* + * Each time a ghost finds itself at an intersection, + * it picks a target position - the specific target depends on the state + * of the ghost and the specific ghost. + * + * For each 4 cells around the current ghost position the straight-line distance + * to the target is calculated (this ignores all obstacles, including walls) + * + * The ghost then selects among these 4 cells the one with the shortest euclidean distance to the target. + * If a cell is a wall or would cause a ghost to move in the opposite direction, the distance to the target + * from that cell is considered infinite (due to the shape of the maze, there is always one direction + * a ghost can take). + * + * In the scatter state, each ghost tries to reach an unreacheable position outside of the map. + * This makes ghosts run in circle around the island at each of the 4 map corner. + */ void Ghost::updateDirection(const Board & board) { const auto current_grid_position = positionInGrid(); if (current_grid_position == last_grid_position)