#include "Node.h"
#include "AutomaticDeplacement.h"
#include <iostream>
using namespace std;
Node::Node()
{
}
Node::Node(irr::core::vector3df position, irr::core::vector3df parent, float Gparent, int factor, irr::core::vector3df arrivee) : m_position(position), m_parent(parent), m_arrivee(arrivee)
{
G = Gparent + factor;
//H = 10 * abs(m_position.X-m_arrivee.X) + abs(m_position.X-m_arrivee.X);
H = sqrt((m_position.X-m_arrivee.X)*(m_position.X-m_arrivee.X)+(m_position.Z-m_arrivee.Z)*(m_position.Z-m_arrivee.Z));
//cout << "H = " << H << " position x = " << m_position.X << " position z = " << m_position.Z << " m_arrivee x = " << m_arrivee.X << " m_arrivee.Z = " << m_arrivee.Z << endl;
F = G+H;
}
Node::~Node()
{
}
void Node::setG(float a)
{
G = a;
}
float Node::getG() const
{
return G;
}
void Node::setH(float a)
{
H = a;
}
float Node::getH() const
{
return H;
}
float Node::getF() const
{
return F;
}
void Node::setF()
{
F = G+H;
}
irr::core::vector3df Node::getPosition() const
{
return m_position;
}
void Node::setParent(irr::core::vector3df positionParent)
{
m_parent = positionParent;
}
irr::core::vector3df Node::getParent()
{
return m_parent;
}
void Node::afficher() const
{
cout << "Node : " << endl;
cout << "coordonnee = " << m_position.X << " / " << m_position.Z << endl;
cout << "coordonnee du parent = " << m_parent.X << " / " << m_parent.Z << endl;
cout << "F = " << F << " G = " << G << " H = " << H << endl;
}
LowestF :
void AutomaticDeplacement::LowestF(Node parent)
{
int plusPetit = 1000000, indice;
Node test;
for(unsigned int i=0; i<listeOuverte.size(); i++)
{
if(listeOuverte[i].getF() < plusPetit && listeOuverte[i].getParent() == parent.getPosition())
{
plusPetit = listeOuverte[i].getF();
test = listeOuverte[i];
m_current = listeOuverte[i].getPosition();
indice = i;
}
}
//listeOuverte[indice].afficher();
listeOuverte.erase(listeOuverte.begin()+indice);
cout << "nouveau point : X = " << test.getPosition().X << " Z = " << test.getPosition().Z << endl;
listeFermee.push_back(test);
}