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
24 #if !defined(lint) && !defined(SABER)
25 static char sccsid[] = "@(#)as_extend.c 1.2 11/13/90";
29 * Extend the queue by neighbors. This entails getting the
30 * coordinates of all the neighbors, figuring out their lower bound
31 * costs, throwing away ones that are more expensive than ones we
32 * already have, sorting, tand then merging into the queue.
35 as_extend(struct as_data *adp)
39 struct as_queue *head;
43 /* Find the neighboring coordinates. */
44 i = (*adp->neighbor) (head->np->c, adp->neighbor_coords,
49 * Get rid of neighbors that are more costly than ones we already have,
50 * and sort the rest into an array of as_nodes.
52 i = as_winnow(adp, adp->neighbor_coords, i);
56 qsort(adp->neighbor_nodes, i,
57 sizeof(*adp->neighbor_nodes), (qsort_func_t)as_costcomp);
59 /* remove old coord from head of queue and add to list of tried */
65 adp->tried->prev = qp;
66 qp->next = adp->tried;
70 adp->tried->np->flags |= AS_TRIED;
72 head = as_merge(adp, head, adp->neighbor_nodes);