From 81028d70704651ee452ad4160d1a34a9b28d02ca Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Fri, 24 Jun 2011 11:06:26 -0400 Subject: [PATCH] Use floats for strength calculations s. This has the amusing problem of making everything after the first node 'inf' --- gamedata.cpp | 12 ++++++------ gamedata.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/gamedata.cpp b/gamedata.cpp index e7699ca..d3e7d7b 100644 --- a/gamedata.cpp +++ b/gamedata.cpp @@ -64,7 +64,7 @@ bool GameData::add_vertex(int x, int y, int r, int colour) { Graph::add_vertex(x, y, r, colour, 10); #ifdef DEBUG - fprintf(stderr, "debug: GameData::add_vertex(): strength=%d\n", + fprintf(stderr, "debug: GameData::add_vertex(): strength=%f\n", calculate_strength(*(vertices.rbegin()))); #endif if (player == PLAYER1) player1_played = true; @@ -78,7 +78,7 @@ bool GameData::add_vertex(int x, int y, int r, int colour) if (Graph::add_vertex(x, y, r, colour, 10, current)) { #ifdef DEBUG - fprintf(stderr, "debug: GameData::add_vertex(): strength=%d\n", + fprintf(stderr, "debug: GameData::add_vertex(): strength=%f\n", calculate_strength(*(vertices.rbegin()))); #endif @@ -91,7 +91,7 @@ bool GameData::add_vertex(int x, int y, int r, int colour) // Oh the recursive recursion! -unsigned int GameData::calculate_strength(Vertex* node, unsigned int depth, list* visited) +float GameData::calculate_strength(Vertex* node, unsigned int depth, list* visited) { if (visited == NULL) visited = new list; visited->push_back(node); @@ -99,7 +99,7 @@ unsigned int GameData::calculate_strength(Vertex* node, unsigned int depth, list list all_nodes = get_colour(node->colour); // Special case - a one-node tree just returns its own score! - if (all_nodes.size() == 1) return node->score; + if (all_nodes.size() == 1) return (float)node->score; // Find which vertices we need to visit from here @@ -125,12 +125,12 @@ unsigned int GameData::calculate_strength(Vertex* node, unsigned int depth, list } // This is the base case - this node has no unvisited neighbors - if (to_visit.empty()) return node->score / depth; + if (to_visit.empty()) return (float)(node->score) / depth; // Else, iterate through to_visit and visit them all, summing their // effective strengths adjusted for depth. // Since our trees are acyclic, this can't loop. - int modscore = node->score; + float modscore = (float)node->score; if (depth > 0) modscore /= depth; for (list::iterator cursor = to_visit.begin(); diff --git a/gamedata.h b/gamedata.h index 7f6c8bf..2666988 100644 --- a/gamedata.h +++ b/gamedata.h @@ -29,7 +29,7 @@ class GameData : public Graph bool add_vertex(int x, int y, int r, int colour); private: - unsigned int calculate_strength(Vertex* node, unsigned int depth = 0, list* visited = NULL); + float calculate_strength(Vertex* node, unsigned int depth = 0, list* visited = NULL); Vertex* current; Turn player;