]> git.pond.sub.org Git - empserver/blob - src/lib/as/as_costcomp.c
Indented with src/scripts/indent-emp.
[empserver] / src / lib / as / as_costcomp.c
1 /*
2  *  A* Search - A search library used in Empire to determine paths between
3  *              objects.
4  *  Copyright (C) 1990-1998 Phil Lapsley
5  *
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.
10  *
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.
15  *
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
19  */
20 #include "as.h"
21
22 #if !defined(lint) && !defined(SABER)
23 static char sccsid[] = "@(#)as_costcomp.c       1.4     11/13/90";
24 #endif /* not lint */
25
26 /*
27  * Compare the lower bound costs of two nodes.  If the two nodes have
28  * equal lower bound costs, sort on the secondary field.
29  * Used as comparision function for qsort.
30  */
31 int
32 as_costcomp(struct as_node **n1, struct as_node **n2)
33 {
34     double diff;
35
36     diff = (*n1)->lbcost - (*n2)->lbcost;
37     if (diff < -0.0001)
38         return (-1);
39     if (diff > 0.0001)
40         return (1);
41
42     /* equal, check secondary cost */
43     diff = (*n1)->seccost - (*n2)->seccost;
44     if (diff < -0.0001)
45         return (-1);
46     if (diff > 0.0001)
47         return (1);
48     return (0);
49 }