Move dump of C code for Huffman tables to stderr to avoid conflict with
[xiph/unicode.git] / planarity / graph_score.c
blobb0e17b22772159d927035a479612cfd6d94d892c
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"
32 #include "gettext.h"
34 static char objective_string[160];
37 int graphscore_get_raw_score(graph *g){
38 return (int)ceil((g->original_intersections- g->active_intersections)*
39 g->intersection_mult);
42 int graphscore_get_multiplier_percent(graph *g){
43 float obj_multiplier = 100;
45 if(g->objective_lessthan)
46 if(g->objective > g->active_intersections)
47 obj_multiplier += 100.f * g->objective_mult / g->objective * (g->objective - g->active_intersections);
49 return ceil(obj_multiplier);
52 int graphscore_get_score(graph *g){
53 return graphscore_get_raw_score(g)*graphscore_get_multiplier_percent(g)/100;
56 int graphscore_get_bonus(graph *g){
57 int obj_multiplier = graphscore_get_multiplier_percent(g);
59 if(get_timer()< g->original_intersections*g->intersection_mult)
60 return ceil ((g->original_intersections*g->intersection_mult-get_timer()) * obj_multiplier / 100);
62 return 0;
65 char *graphscore_objective_string(graph *g){
66 if(g->objective == 0)
67 return _("zero intersections");
68 if(g->objective == 1){
69 if(g->objective_lessthan){
70 return _("1 intersection or fewer");
71 }else{
72 return _("1 intersection");
74 }else{
75 snprintf(objective_string,160,_("%d intersections%s"),
76 g->objective,(g->objective_lessthan?
77 _(" or fewer"):""));
78 return objective_string;