diff options
| author | scratko <m@scratko.xyz> | 2024-04-11 15:04:37 +0300 | 
|---|---|---|
| committer | scratko <m@scratko.xyz> | 2024-04-11 15:04:37 +0300 | 
| commit | 235f8481502263fcdb4823ff0bc4e8f831bc934d (patch) | |
| tree | aa7bac493c447571ac88f3793447e05ed17c2d6a /ghosts.c | |
| parent | 76b875e095d8b9ca3f6058fbfc0ab2669eed852d (diff) | |
| download | pacman-235f8481502263fcdb4823ff0bc4e8f831bc934d.tar.gz pacman-235f8481502263fcdb4823ff0bc4e8f831bc934d.tar.bz2 pacman-235f8481502263fcdb4823ff0bc4e8f831bc934d.zip | |
Removed the reverse motion for ghosts
Yellow intersections added.
Diffstat (limited to 'ghosts.c')
| -rw-r--r-- | ghosts.c | 43 | 
1 files changed, 31 insertions, 12 deletions
| @@ -77,19 +77,20 @@ static void change_position(struct ghost_type *ghost,      switch(direction) {      case left:          --ghost->position.x; -        return; +        break;      case right:          ++ghost->position.x; -        return; +        break;      case up:          --ghost->position.y; -        return; +        break;      case down:          ++ghost->position.y; -        return; +        break;      default:          return;      } +    change_point_if_outside_tunnel(&ghost->position);  }  void make_ghost_moves(game_space field, @@ -215,12 +216,14 @@ static void clear_both_queues(struct queue *next_points,      queue_clear(reviewed_points);  } -static int is_bfs_search_for_orange(enum search_flag current_width, -                                    int move_count) +static int is_bfs_search_for_orange(enum search_flag *current_width, +                                    int *move_count)  { -    if(current_width == not_viewed) -        ++move_count; -    return move_count > orange_search_limit; +    if(*current_width == not_viewed) { +        ++*move_count; +        *current_width = viewed; +    } +    return *move_count > orange_search_limit;  }  void breadth_first_search(game_space field, struct ghost_type *ghost, @@ -228,15 +231,23 @@ void breadth_first_search(game_space field, struct ghost_type *ghost,  {      int move_count;      enum search_flag current_width = not_viewed; +    enum movement_direction reverse_direction;      struct coordinates consider_point, near_point;      struct coordinates start_point = { ghost->position.y, ghost->position.x };      struct queue next_points, reviewed_points;      move_count = 0; +    reverse_direction = ghost->direction; +    reverse_direction ^= 1;      queue_init(&next_points);      queue_init(&reviewed_points);      queue_push(&next_points, &target_point);      queue_push(&reviewed_points, &target_point);      while(!empty(&next_points)) { +        if(ghost->position.x == target_point.x && +                ghost->position.y == target_point.y) { +            ghost->direction=none; +            break; +        }          consider_point = queue_front(&next_points);          pop(&next_points);          int dx; @@ -246,22 +257,30 @@ void breadth_first_search(game_space field, struct ghost_type *ghost,                  if(dx != 0 && dy != 0)                      continue;                  near_point = get_near_point(consider_point, dx, dy); +                change_point_if_outside_tunnel(&near_point);                  if(is_obstacle(field, near_point.x, near_point.y))                      continue;                  if(queue_consists_point(&reviewed_points, near_point))                      continue;                  if(equal_points(start_point, near_point)) { -                    if(ghost->color == orange) -                        if(!is_bfs_search_for_orange(current_width, -                                                     move_count)) { +                    if(ghost->color == orange) { +                        if(!is_bfs_search_for_orange(¤t_width, +                                                     &move_count)) {                              redirect(field, two_paths, ghost,                                       ghost->home_position,                                       compute_distance_between_points);                              clear_both_queues(&next_points, &reviewed_points);                              return;                          } +                    }                      ghost->direction =                          find_direction(consider_point, start_point); +#if 1 +                    if(ghost->direction == reverse_direction) { +                        queue_push(&reviewed_points, &consider_point); +                        continue; +                    } +#endif                      clear_both_queues(&next_points, &reviewed_points);                      return;                  } | 
