forked from micromouseonline/libMaze
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmazesearcher.h
107 lines (97 loc) · 3.52 KB
/
mazesearcher.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/************************************************************************
*
* Copyright (C) 2017 by Peter Harrison. www.micromouseonline.com
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without l> imitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
************************************************************************/
#ifndef MAZESEARCHER_H
#define MAZESEARCHER_H
/*
* The mazeSearcher is the mouse. The robot that explores and runs the maze.
* It gets its sensor data from the worldview and uses it to update a maze
* and act appropriately.
*
* It is here that the behaviour of the mouse will be defined. For each
* action, a single public function should be defined.
*
* Note that there is no access to private state information except through
* accessor functions. Thus, it is possible to implement the mouse in any
* way the user chooses and the tests will only deal with the public
* functions.
*
* A single SearchTo function is provided along with an enum naming the
* search method and means to select one of those methods.
*
* From the outside, code should set a method and then call MouseSearchTo().
* there should not be any direct calls to specific search methods.
*/
#include <cstdint>
#include "maze.h"
class MazeSearcher {
public:
enum {
SEARCH_NORMAL,
SEARCH_ALTERNATE,
SEARCH_LEFT_WALL,
SEARCH_RIGHT_WALL,
};
enum {
E_NO_ROUTE = -1,
E_ROUTE_TOO_LONG = -2,
};
MazeSearcher();
~MazeSearcher();
uint16_t location() const;
void setLocation(uint16_t location);
uint8_t heading() const;
void setHeading(uint8_t heading);
void setMapFromFileData(const uint8_t *mazeWalls, uint16_t cellCount);
Maze *map();
/// move the mouse 1 cell in in the current Heading
const Maze *realMaze() const;
void setRealMaze(const Maze *mRealMaze);
void move();
void turnRight();
void turnLeft();
void turnAround();
/// follow direction data in the maze to get to the given target cell
/// return the number of steps needed
int runTo(uint16_t target);
/// search unknown maze for target cell
/// return the number of steps needed
int searchTo(uint16_t target);
void setSearchMethod(int mSearchMethod);
bool isVerbose() const;
void setVerbose(bool mVerbose);
uint8_t followLeftWall() const;
uint8_t followRightWall() const;
uint8_t followAlternateWall() const;
private:
uint16_t mLocation;
uint8_t mHeading;
Maze *mMap;
const Maze *mRealMaze;
bool mVerbose;
int mSearchMethod;
MazeSearcher &operator=(const MazeSearcher &rhs);
MazeSearcher(const MazeSearcher &orig);
};
#endif /* MAZESEARCHER_H */