-
Notifications
You must be signed in to change notification settings - Fork 0
/
puzzle_move.h
51 lines (40 loc) · 1.27 KB
/
puzzle_move.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
#ifndef PUZZLEMOVE_H
#define PUZZLEMOVE_H
#include <functional>
#include "board.h"
#include "puzzle_heur.h"
/**
* This is a class to keep track of the possible moves.
* @author Tam Henry Le Nguyen */
class PuzzleMove
{
public:
/** Constructor for starting Board of an A* search */
PuzzleMove(Board &b);
/** Constructor for subsequent search boards
* (i.e. those returned by Board::potentialMoves() ) */
PuzzleMove(int tile, Board *b, PuzzleMove *parent);
/** Destructor */
~PuzzleMove();
/** Compare to PuzzleMoves based on f distance */
bool operator<(const PuzzleMove& p) const;
bool operator>(const PuzzleMove& p) const;
bool operator==(const PuzzleMove& p) const;
// Data members can be public
public:
int tileMove_; /** tile moved to reach the Board b */
Board *b_; /** Pointer to a board representing the updated state */
int g_; /** distance from the start board */
int h_; /** heuristic distance to the goal */
PuzzleMove *prev_; /** Pointer to parent PuzzleMove */
};
// Leave this alone and don't touch it!
struct PuzzleMoveGreater :
public std::binary_function<const PuzzleMove*, const PuzzleMove*,bool>
{
bool operator()(const PuzzleMove *m1, const PuzzleMove *m2) const
{
return *m1 > *m2;
}
};
#endif