Swap code/variable declaration to be pre-C99 compliant.
[xiph/unicode.git] / planarity / graph_score.c
blob3036e6cb886857faf99c520fd964c9d3a5e16b82
1 /*
3 * gPlanarity:
4 * The geeky little puzzle game with a big noodly crunch!
5 *
6 * gPlanarity copyright (C) 2005 Monty <monty@xiph.org>
7 * Original Flash game by John Tantalo <john.tantalo@case.edu>
8 * Original game concept by Mary Radcliffe
10 * gPlanarity is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
13 * any later version.
15 * gPlanarity is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Postfish; see the file COPYING. If not, write to the
22 * Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <string.h>
28 #include <stdio.h>
29 #include <math.h>
30 #include "graph.h"
31 #include "timer.h"
33 static char objective_string[160];
36 int graphscore_get_raw_score(graph *g){
37 return (int)ceil((g->original_intersections- g->active_intersections)*
38 g->intersection_mult);
41 int graphscore_get_multiplier_percent(graph *g){
42 float obj_multiplier = 100;
44 if(g->objective_lessthan)
45 if(g->objective > g->active_intersections)
46 obj_multiplier += 100.f * g->objective_mult / g->objective * (g->objective - g->active_intersections);
48 return ceil(obj_multiplier);
51 int graphscore_get_score(graph *g){
52 return graphscore_get_raw_score(g)*graphscore_get_multiplier_percent(g)/100;
55 int graphscore_get_bonus(graph *g){
56 int obj_multiplier = graphscore_get_multiplier_percent(g);
58 if(get_timer()< g->original_intersections*g->intersection_mult)
59 return ceil ((g->original_intersections*g->intersection_mult-get_timer()) * obj_multiplier / 100);
61 return 0;
64 char *graphscore_objective_string(graph *g){
65 if(g->objective == 0)
66 return "zero intersections";
67 if(g->objective == 1){
68 if(g->objective_lessthan){
69 return "1 intersection or fewer";
70 }else{
71 return "1 intersection";
73 }else{
74 snprintf(objective_string,160,"%d intersections%s",
75 g->objective,(g->objective_lessthan?
76 " or fewer":""));
77 return objective_string;