From 76b875e095d8b9ca3f6058fbfc0ab2669eed852d Mon Sep 17 00:00:00 2001 From: scratko Date: Wed, 10 Apr 2024 22:01:48 +0300 Subject: Searching for all ghosts --- pacman.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'pacman.c') 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, -- cgit v1.2.3