#include ".\node.h"
#include <math.h>

Node::Node(void){
    init(0,0);
}

Node::Node(Node* parent, POINT* point){
    init(parent, point);
}

Node::~Node(void){
    if(point){
        delete point;
        point = 0;
    }
}


// initialize
void Node::init(Node* parent, POINT* point){
    setParent(parent);
    setPoint(point);
    givenCost = 0;
    heuristicCost = 0;
}

// getter setter parent
Node* Node::getParent(){
    return parent;
}
void  Node::setParent(Node* _parent){
    parent = _parent;
}
// getter setter tile
POINT* Node::getPoint(){
    return point;
}
void   Node::setPoint(POINT* _point){
    point = _point;
}
// getter setter given cost
int  Node::getGivenCost(){
    return givenCost;
}
void Node::setGivenCost(int _givenCost){
    givenCost = _givenCost;
}
// getter setter heuristic cost
int  Node::getHeuristicCost(){
    return heuristicCost;
}
void Node::setHeuristicCost(POINT* destination){
	int xDiff = abs(point->x - destination->x);
	int yDiff = abs(point->y - destination->y);

	(xDiff > yDiff) ? heuristicCost = xDiff : heuristicCost = yDiff;
}                            
// getter total cost
int Node::getTotalCost(){
    return givenCost + heuristicCost;
}

