back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
path: root/pacman.c
diff options
context:
space:
mode:
authorscratko <m@scratko.xyz>2024-04-10 22:01:48 +0300
committerscratko <m@scratko.xyz>2024-04-10 22:01:48 +0300
commit76b875e095d8b9ca3f6058fbfc0ab2669eed852d (patch)
treeb0d170622775c08881b3e6d516ea97ce2e89ff7b /pacman.c
parent155a3c5f91c7a3bd89febfeb9927478961f5ee28 (diff)
downloadpacman-76b875e095d8b9ca3f6058fbfc0ab2669eed852d.tar.gz
pacman-76b875e095d8b9ca3f6058fbfc0ab2669eed852d.tar.bz2
pacman-76b875e095d8b9ca3f6058fbfc0ab2669eed852d.zip
Searching for all ghosts
Diffstat (limited to 'pacman.c')
-rw-r--r--pacman.c35
1 files changed, 32 insertions, 3 deletions
diff --git a/pacman.c b/pacman.c
index 9346055..f2e0161 100644
--- a/pacman.c
+++ b/pacman.c
@@ -19,10 +19,39 @@ static void pathfinder_stage(game_space field, struct pacman pac,
struct ghost_type *blue_ghost,
struct ghost_type *orange_ghost)
{
+ void (*search_method)(game_space, struct ghost_type*, struct coordinates);
enum intersection_type intersection;
- intersection = get_intersection(field, red_ghost);
- if(intersection != direct_path)
- redirect(field, intersection, red_ghost, pac, breadth_first_search);
+ int color_priority;
+ struct ghost_type *current_ghost;
+ struct coordinates target_point;
+ for(color_priority = 0; color_priority <= orange; ++color_priority) {
+ switch(color_priority) {
+ case red:
+ current_ghost = red_ghost;
+ target_point = pac.position;
+ search_method = breadth_first_search;
+ break;
+ case pink:
+ current_ghost = pink_ghost;
+ target_point = identify_target_in_front(pac, pink_shift);
+ search_method = compute_distance_between_points;
+ break;
+ case blue:
+ current_ghost = blue_ghost;
+ target_point = identify_blue_target(pac, red_ghost);
+ search_method = compute_distance_between_points;
+ break;
+ case orange:
+ current_ghost = orange_ghost;
+ target_point = pac.position;
+ search_method = breadth_first_search;
+ break;
+ }
+ intersection = get_intersection(field, current_ghost);
+ if(intersection != direct_path)
+ redirect(field, intersection, current_ghost, target_point,
+ search_method);
+ }
}
static void initialize_ghosts(struct ghost_type *red_ghost,