-
Notifications
You must be signed in to change notification settings - Fork 1
/
State.cpp
61 lines (48 loc) · 1.29 KB
/
State.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// Created by yuvalshechter on 29/01/2020.
//
#include "State.h"
State::State(string indexes1, double cost1){
this->cost = cost1;
this->fatherVertex = NULL;
this->indexes = indexes1;
this->i = int(indexes1[0]) - 48;
this->j = int(indexes1[2]) - 48;
}
State * State::get_father() {
return this->fatherVertex;
}
double State::getCostVertex() {
return this->cost;
}
void State::set_father(State *fatherVertex1) {
this->fatherVertex = fatherVertex1;
}
void State::setCost(double cost) {
this->cost = cost;
}
//this is function the hold the indexes of the vertex in the vertexMap
void State::setIndex(string indexes) {
this->indexes = indexes;
}
int State::getCost() {
return this->cost;
}
string State::get_vertex_index() {
return this->indexes;
}
int State::getI() {
string index = this->get_vertex_index() ;
return stoi(index.substr(0, index.find(',', 0))) ;
}
double State::h(State* goal) {
return sqrt(pow((double)(this->getI() - goal->getI()), 2) + pow((double)(this->getJ() - goal->getJ()), 2)) ;
}
int State::getJ() {
string index_vertex = this->get_vertex_index() ;
int commaPlace = index_vertex.find(',', 0) ;
return stoi(index_vertex.substr(commaPlace + 1, index_vertex.length() - commaPlace - 1)) ;
}
State::~State(){
delete fatherVertex;
}