Code to run the microcontrollers on the R5 competition bot
Dependencies: LineSensors mbed
r5map.h@15:150ec9448efc, 2015-04-18 (annotated)
- Committer:
- Hypna
- Date:
- Sat Apr 18 02:54:55 2015 +0000
- Revision:
- 15:150ec9448efc
experiment
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Hypna | 15:150ec9448efc | 1 | #ifndef R5_MAP |
Hypna | 15:150ec9448efc | 2 | #define R5_MAP |
Hypna | 15:150ec9448efc | 3 | |
Hypna | 15:150ec9448efc | 4 | #include <vector> |
Hypna | 15:150ec9448efc | 5 | |
Hypna | 15:150ec9448efc | 6 | using namespace std; |
Hypna | 15:150ec9448efc | 7 | |
Hypna | 15:150ec9448efc | 8 | struct position |
Hypna | 15:150ec9448efc | 9 | { |
Hypna | 15:150ec9448efc | 10 | position(int xx = 0, int yy = 0) : x(xx), y(yy) {} |
Hypna | 15:150ec9448efc | 11 | inline bool operator==(const typename ::position& rhs){return ((x==rhs.x) && (y==rhs.y)); } |
Hypna | 15:150ec9448efc | 12 | inline bool operator!=(const typename ::position& rhs){return !operator==(rhs);} |
Hypna | 15:150ec9448efc | 13 | int x,y; |
Hypna | 15:150ec9448efc | 14 | }; |
Hypna | 15:150ec9448efc | 15 | |
Hypna | 15:150ec9448efc | 16 | enum wallState { OPEN, CLOSED, UNKNOWN }; |
Hypna | 15:150ec9448efc | 17 | enum direction { NORTH, EAST, SOUTH, WEST }; |
Hypna | 15:150ec9448efc | 18 | |
Hypna | 15:150ec9448efc | 19 | struct Cell |
Hypna | 15:150ec9448efc | 20 | { |
Hypna | 15:150ec9448efc | 21 | Cell() : north(UNKNOWN), south(UNKNOWN), east(UNKNOWN), west(UNKNOWN), visited(false) {} |
Hypna | 15:150ec9448efc | 22 | wallState north; |
Hypna | 15:150ec9448efc | 23 | wallState south; |
Hypna | 15:150ec9448efc | 24 | wallState east; |
Hypna | 15:150ec9448efc | 25 | wallState west; |
Hypna | 15:150ec9448efc | 26 | bool visited ; |
Hypna | 15:150ec9448efc | 27 | int number; |
Hypna | 15:150ec9448efc | 28 | vector<char> symbols; |
Hypna | 15:150ec9448efc | 29 | }; |
Hypna | 15:150ec9448efc | 30 | |
Hypna | 15:150ec9448efc | 31 | class R5Map |
Hypna | 15:150ec9448efc | 32 | { |
Hypna | 15:150ec9448efc | 33 | public: |
Hypna | 15:150ec9448efc | 34 | R5Map(int conSize = DEFAULT_SIZE); |
Hypna | 15:150ec9448efc | 35 | void setPosition(position cell); |
Hypna | 15:150ec9448efc | 36 | void setStart(position newStart); |
Hypna | 15:150ec9448efc | 37 | void setFinish(position newFin); |
Hypna | 15:150ec9448efc | 38 | void setWall(position cell, direction dir, wallState state); |
Hypna | 15:150ec9448efc | 39 | void setCurWall(direction dir, wallState state); |
Hypna | 15:150ec9448efc | 40 | void setVisited(position cell); |
Hypna | 15:150ec9448efc | 41 | void setCurVisited(); |
Hypna | 15:150ec9448efc | 42 | void addSymbol(position cell, char symbol); |
Hypna | 15:150ec9448efc | 43 | void addCurSymbol(char symbol); |
Hypna | 15:150ec9448efc | 44 | position getPosition() const; |
Hypna | 15:150ec9448efc | 45 | position getStart() const; |
Hypna | 15:150ec9448efc | 46 | position getFinish() const; |
Hypna | 15:150ec9448efc | 47 | wallState getWall(position cell, direction dir) const; |
Hypna | 15:150ec9448efc | 48 | wallState getCurWall(direction dir) const; |
Hypna | 15:150ec9448efc | 49 | bool getVisited(position cell) const; |
Hypna | 15:150ec9448efc | 50 | bool getCurVisited() const; |
Hypna | 15:150ec9448efc | 51 | vector<char> getSymbols(position cell) const; |
Hypna | 15:150ec9448efc | 52 | vector<char> getCurSymbols() const; |
Hypna | 15:150ec9448efc | 53 | int getSize() const; |
Hypna | 15:150ec9448efc | 54 | void printMap() const; |
Hypna | 15:150ec9448efc | 55 | ~R5Map(); |
Hypna | 15:150ec9448efc | 56 | |
Hypna | 15:150ec9448efc | 57 | private: |
Hypna | 15:150ec9448efc | 58 | static const int DEFAULT_SIZE = 5; |
Hypna | 15:150ec9448efc | 59 | Cell map[7][7]; |
Hypna | 15:150ec9448efc | 60 | int size; |
Hypna | 15:150ec9448efc | 61 | position pos; //X,Y |
Hypna | 15:150ec9448efc | 62 | position start; |
Hypna | 15:150ec9448efc | 63 | position fin; |
Hypna | 15:150ec9448efc | 64 | }; |
Hypna | 15:150ec9448efc | 65 | |
Hypna | 15:150ec9448efc | 66 | #endif |