-
Notifications
You must be signed in to change notification settings - Fork 1
/
Maze2dSearchable.h
56 lines (48 loc) · 1.52 KB
/
Maze2dSearchable.h
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
#pragma once
#include "Maze2d.h"
#include "Searcable.h"
#include "Searcher.h"
#include <cmath>
//create search states for maze problem
class Maze2dSearchable : public Searchable<Position>
{
public:
Maze2dSearchable(Maze2d &maze) : _maze(maze) {}
virtual const State<Position> getStartState()
{
return {_maze.getStartPosition(), 0};
}
virtual const State<Position> getGoalState()
{
return {_maze.getEndPosition(), 0};
}
virtual const std::vector<State<Position>> getPossibleStates(State<Position> &currState);
private:
Maze2d _maze;
};
class ManhattanDistance : public Hueristics<Position>
{
private:
const State<Position> _state;
public:
ManhattanDistance(const State<Position> &state) : _state(state) {}
virtual double operator()(const State<Position> &state) const
{
double h = std::abs(_state.data.getXPosition() - state.data.getXPosition()) + (_state.data.getYPosition() - state.data.getYPosition());
// std::cout << "md " << h << std::endl;
return h;
}
};
class AerialDistance : public Hueristics<Position>
{
private:
const State<Position> _state;
public:
AerialDistance(const State<Position> &state) : _state(state) {}
virtual double operator()(const State<Position> &state) const
{
double h = std::sqrt(std::pow((_state.data.getXPosition() - state.data.getXPosition()), 2) + (std::pow((_state.data.getYPosition() - state.data.getYPosition()), 2)));
// std::cout << "ad " << h << std::endl;
return h;
}
};