Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: LineSensors mbed
r5map.h@18:2bd595af51d2, 2015-04-18 (annotated)
- Committer:
- jmar11
- Date:
- Sat Apr 18 03:13:27 2015 +0000
- Revision:
- 18:2bd595af51d2
- Parent:
- 17:5046b27f5441
- Child:
- 19:9f4510646c9e
r5map.h correction
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| jmar11 | 18:2bd595af51d2 | 1 | #ifndef R5_MAP |
| jmar11 | 18:2bd595af51d2 | 2 | #define R5_MAP |
| jmar11 | 18:2bd595af51d2 | 3 | |
| jmar11 | 18:2bd595af51d2 | 4 | #include <vector> |
| jmar11 | 18:2bd595af51d2 | 5 | |
| jmar11 | 18:2bd595af51d2 | 6 | using namespace std; |
| jmar11 | 18:2bd595af51d2 | 7 | |
| jmar11 | 18:2bd595af51d2 | 8 | struct position |
| jmar11 | 18:2bd595af51d2 | 9 | { |
| jmar11 | 18:2bd595af51d2 | 10 | position(int xx = 0, int yy = 0) : x(xx), y(yy) {} |
| jmar11 | 18:2bd595af51d2 | 11 | inline bool operator==(const typename ::position& rhs){return ((x==rhs.x) && (y==rhs.y)); } |
| jmar11 | 18:2bd595af51d2 | 12 | inline bool operator!=(const typename ::position& rhs){return !operator==(rhs);} |
| jmar11 | 18:2bd595af51d2 | 13 | int x,y; |
| jmar11 | 18:2bd595af51d2 | 14 | }; |
| jmar11 | 18:2bd595af51d2 | 15 | |
| jmar11 | 18:2bd595af51d2 | 16 | enum wallState { OPEN, CLOSED, UNKNOWN }; |
| jmar11 | 18:2bd595af51d2 | 17 | enum direction { NORTH, EAST, SOUTH, WEST }; |
| jmar11 | 18:2bd595af51d2 | 18 | |
| jmar11 | 18:2bd595af51d2 | 19 | struct Cell |
| jmar11 | 18:2bd595af51d2 | 20 | { |
| jmar11 | 18:2bd595af51d2 | 21 | Cell() : north(UNKNOWN), south(UNKNOWN), east(UNKNOWN), west(UNKNOWN), visited(false) {} |
| jmar11 | 18:2bd595af51d2 | 22 | wallState north; |
| jmar11 | 18:2bd595af51d2 | 23 | wallState south; |
| jmar11 | 18:2bd595af51d2 | 24 | wallState east; |
| jmar11 | 18:2bd595af51d2 | 25 | wallState west; |
| jmar11 | 18:2bd595af51d2 | 26 | bool visited ; |
| jmar11 | 18:2bd595af51d2 | 27 | int number; |
| jmar11 | 18:2bd595af51d2 | 28 | }; |
| jmar11 | 18:2bd595af51d2 | 29 | |
| jmar11 | 18:2bd595af51d2 | 30 | class R5Map |
| jmar11 | 17:5046b27f5441 | 31 | { |
| jmar11 | 18:2bd595af51d2 | 32 | public: |
| jmar11 | 18:2bd595af51d2 | 33 | R5Map(int conSize = DEFAULT_SIZE); |
| jmar11 | 18:2bd595af51d2 | 34 | void setPosition(position cell); |
| jmar11 | 18:2bd595af51d2 | 35 | void setStart(position newStart); |
| jmar11 | 18:2bd595af51d2 | 36 | void setFinish(position newFin); |
| jmar11 | 18:2bd595af51d2 | 37 | void setWall(position cell, direction dir, wallState state); |
| jmar11 | 18:2bd595af51d2 | 38 | void setCurWall(direction dir, wallState state); |
| jmar11 | 18:2bd595af51d2 | 39 | void setVisited(position cell); |
| jmar11 | 18:2bd595af51d2 | 40 | void setCurVisited(); |
| jmar11 | 18:2bd595af51d2 | 41 | position getPosition() const; |
| jmar11 | 18:2bd595af51d2 | 42 | position getStart() const; |
| jmar11 | 18:2bd595af51d2 | 43 | position getFinish() const; |
| jmar11 | 18:2bd595af51d2 | 44 | wallState getWall(position cell, direction dir) const; |
| jmar11 | 18:2bd595af51d2 | 45 | wallState getCurWall(direction dir) const; |
| jmar11 | 18:2bd595af51d2 | 46 | bool getVisited(position cell) const; |
| jmar11 | 18:2bd595af51d2 | 47 | bool getCurVisited() const; |
| jmar11 | 18:2bd595af51d2 | 48 | int getSize() const; |
| jmar11 | 18:2bd595af51d2 | 49 | void printMap() const; |
| jmar11 | 18:2bd595af51d2 | 50 | ~R5Map(); |
| jmar11 | 18:2bd595af51d2 | 51 | |
| jmar11 | 18:2bd595af51d2 | 52 | private: |
| jmar11 | 18:2bd595af51d2 | 53 | static const int DEFAULT_SIZE = 5; |
| jmar11 | 18:2bd595af51d2 | 54 | Cell map[7][7]; |
| jmar11 | 18:2bd595af51d2 | 55 | int size; |
| jmar11 | 18:2bd595af51d2 | 56 | position pos; //X,Y |
| jmar11 | 18:2bd595af51d2 | 57 | position start; |
| jmar11 | 18:2bd595af51d2 | 58 | position fin; |
| jmar11 | 18:2bd595af51d2 | 59 | }; |
| jmar11 | 18:2bd595af51d2 | 60 | |
| jmar11 | 18:2bd595af51d2 | 61 | #endif |