Most of the attack functionality now in place, but it's not all quite working yet
This commit is contained in:
76
graph.cpp
76
graph.cpp
@ -1,6 +1,11 @@
|
||||
#include "graph.h"
|
||||
#include "mathutils.h"
|
||||
#include "debug.h"
|
||||
#include <list>
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
using std::list;
|
||||
|
||||
Graph::Graph(bool planar)
|
||||
{
|
||||
@ -17,7 +22,7 @@ Graph::~Graph()
|
||||
}
|
||||
}
|
||||
|
||||
bool Graph::point_in_vertex(int x, int y, int r)
|
||||
bool Graph::point_in_vertex(int x, int y)
|
||||
{
|
||||
for (list<Vertex*>::iterator cursor = vertices.begin();
|
||||
cursor != vertices.end(); cursor++)
|
||||
@ -113,16 +118,6 @@ bool Graph::add_vertex(int x, int y, int r, int colour, int score, Vertex* src)
|
||||
}
|
||||
|
||||
|
||||
Vertex::Vertex(int x, int y, int r, int colour, int score)
|
||||
{
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->r = r;
|
||||
this->colour = colour;
|
||||
this->score = score;
|
||||
}
|
||||
|
||||
|
||||
list<Vertex*> Graph::get_colour(int colour)
|
||||
{
|
||||
list<Vertex*> answer;
|
||||
@ -167,3 +162,62 @@ list<Vertex*> Graph::get_neighbors(Vertex* v)
|
||||
|
||||
return answer;
|
||||
}
|
||||
|
||||
|
||||
void Graph::remove_vertex(Vertex* target)
|
||||
{
|
||||
list<Edge> dead_edges = get_edges(target);
|
||||
|
||||
for (list<Edge>::iterator cursor = dead_edges.begin();
|
||||
cursor != dead_edges.end(); cursor++)
|
||||
{
|
||||
Edge e = *cursor;
|
||||
list<Edge>::iterator to_del = find(edges.begin(), edges.end(), e);
|
||||
|
||||
if (to_del != edges.end())
|
||||
{
|
||||
edges.erase(to_del);
|
||||
}
|
||||
}
|
||||
|
||||
list<Vertex*>::iterator to_del = find(vertices.begin(), vertices.end(),
|
||||
target);
|
||||
|
||||
assert(to_del != vertices.end());
|
||||
vertices.erase(to_del);
|
||||
delete target;
|
||||
}
|
||||
|
||||
|
||||
Vertex::Vertex(int x, int y, int r, int colour, int score)
|
||||
{
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->r = r;
|
||||
this->colour = colour;
|
||||
this->score = score;
|
||||
}
|
||||
|
||||
|
||||
Edge::Edge()
|
||||
{
|
||||
a = NULL;
|
||||
b = NULL;
|
||||
score = 0;
|
||||
}
|
||||
|
||||
|
||||
Edge::Edge(Vertex* a, Vertex* b, int score)
|
||||
{
|
||||
this->a = a;
|
||||
this->b = b;
|
||||
this->score = score;
|
||||
}
|
||||
|
||||
|
||||
bool Edge::operator==(const Edge e) const
|
||||
{
|
||||
return (this->a == e.a &&
|
||||
this->b == e.b &&
|
||||
this->score == e.score);
|
||||
}
|
||||
|
Reference in New Issue
Block a user