2 * A* Search - A search library used in Empire to determine paths between
4 * Copyright (C) 1990-1998 Phil Lapsley
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 * Extend the queue by neighbors. This entails getting the
28 * coordinates of all the neighbors, figuring out their lower bound
29 * costs, throwing away ones that are more expensive than ones we
30 * already have, sorting, tand then merging into the queue.
33 as_extend(struct as_data *adp)
37 struct as_queue *head;
41 /* Find the neighboring coordinates. */
42 i = adp->neighbor(head->np->c, adp->neighbor_coords, adp->userdata);
46 * Get rid of neighbors that are more costly than ones we already have,
47 * and sort the rest into an array of as_nodes.
49 i = as_winnow(adp, adp->neighbor_coords, i);
53 qsort(adp->neighbor_nodes, i,
54 sizeof(*adp->neighbor_nodes), as_costcomp);
56 /* remove old coord from head of queue and add to list of tried */
62 adp->tried->prev = qp;
63 qp->next = adp->tried;
67 adp->tried->np->flags |= AS_TRIED;
69 head = as_merge(adp, head, adp->neighbor_nodes);