-
Notifications
You must be signed in to change notification settings - Fork 0
/
Labyrinth.hpp
77 lines (60 loc) · 2.15 KB
/
Labyrinth.hpp
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/** ---------------------------------------------------------------------------
** Labyrinth.hpp
**
** Contains the representation of a labyrinth board and its maximum free path.
**
** Author: Santiago Gil Begué.
** -------------------------------------------------------------------------*/
#ifndef LABYRINTH_LABYRINTH_HPP
#define LABYRINTH_LABYRINTH_HPP
#include <vector>
#include <iosfwd>
// Wall and free path of the labyrinth.
#define WALL -2
#define WALL_FILE '#'
#define FREE -1
#define FREE_FILE '.'
class Labyrinth {
public:
// Constructors.
Labyrinth() {}
Labyrinth(const std::vector<std::vector<int>> &board);
Labyrinth(std::ifstream &inputFile);
/*
* @return A labyrinth with the solution to the maximum free path problem.
*/
Labyrinth solveMaxPath() const;
/*
* @return A labyrinth with the solution to the maximum free path problem
* with the current position in the [i, j] position.
*/
Labyrinth solveMaxPath(const unsigned long i, const unsigned long j) const;
// Size of the labyrinth.
unsigned long rows() const;
unsigned long columns() const;
// mMaxPath getter.
int maxPath() const;
// Returns labyrinth's cell at ith row and jth column.
int at(const unsigned long i, const unsigned long j) const;
// Sets value to the ith row and jth column of the labyrinth board.
void set(const unsigned long i, const unsigned long j, const int value);
/**
* @param l Labyrinth to compare its maximum free path.
* @return true if l has a longer free path than this labyrinth.
*/
bool operator<(const Labyrinth &l) const;
/**
* Pretty print.
*
* @param out Stream that will receive the labyrinth l as a string.
* @param l Labyrinth to send to the stream as a string.
* @return Stream with a string version of l.
*/
friend std::ostream& operator<<(std::ostream &out, const Labyrinth &l);
private:
/** Labyrinth board. */
std::vector<std::vector<int>> mBoard;
/** Length of the maximum free path of this labyrinth board. */
int mMaxPath = 0;
};
#endif // LABYRINTH_LABYRINTH_HPP