Use floats for strength calculations s. This has the amusing problem of making everything after the first node 'inf'
This commit is contained in:
parent
977322d4ee
commit
81028d7070
12
gamedata.cpp
12
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<Vertex*>* visited)
|
||||
float GameData::calculate_strength(Vertex* node, unsigned int depth, list<Vertex*>* visited)
|
||||
{
|
||||
if (visited == NULL) visited = new list<Vertex*>;
|
||||
visited->push_back(node);
|
||||
|
@ -99,7 +99,7 @@ unsigned int GameData::calculate_strength(Vertex* node, unsigned int depth, list
|
|||
list<Vertex*> 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<Vertex*>::iterator cursor = to_visit.begin();
|
||||
|
|
|
@ -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<Vertex*>* visited = NULL);
|
||||
float calculate_strength(Vertex* node, unsigned int depth = 0, list<Vertex*>* visited = NULL);
|
||||
|
||||
Vertex* current;
|
||||
Turn player;
|
||||
|
|
Loading…
Reference in New Issue
Block a user