Mouse code for the MacroRat
Diff: main.h
- Revision:
- 26:d20f1adac2d3
- Parent:
- 20:82836745332e
- Child:
- 29:ec2c5a69acd6
--- a/main.h Sun May 21 08:52:43 2017 +0000 +++ b/main.h Sun May 21 09:58:54 2017 +0000 @@ -5,6 +5,9 @@ #include "ITG3200.h" #include "motor.h" #include "QEI.h" +#include <stack> // std::stack +#include <utility> // std::pair, std::make_pair + #define PULSES 3520 #define SAMPLE_NUM 100 @@ -72,6 +75,15 @@ void disableButton3(); void disableButton4(); +bool isWallInFront(int x, int y); +bool isWallInBack(int x, int y); +bool isWallOnRight(int x, int y); +bool isWallOnLeft(int x, int y); + +int chooseNextMovement(); +void changeManhattanDistance(bool headCenter); +bool hasVisited(int x, int y); + int dipFlags = 0; #define BUTTON1_FLAG 0x1 #define BUTTON2_FLAG 0x2 @@ -90,10 +102,20 @@ #define R_WALL 0x4 #define B_WALL 0x8 -int currDir = 100; // modulo this to keep track of the current direction of the mouse! +#define MAZE_LEN 16 + +int mouseX = 0; +int mouseY = 0; +bool justTurned = false; +bool goingToCenter = true; + +stack< pair<int, int> > cellsToVisit; + +int currDir = 102; // modulo this to keep track of the current direction of the mouse! +// 0 = forward, 1 = right, 2 = down, 3 = left int wallArray[16][16] = {0}; // array to keep track of the walls -int mouseLoc[16][16] = {0}; // array to keep track of the mouse's current location -int manhattanDist[16][16] = { +int visitedCells[16][16] = {0}; // array to keep track of the mouse's current location +int manhattanDistances[16][16] = { {14, 13, 12, 11, 10, 9, 8, 7, 7, 8, 9, 10, 11, 12, 13, 14}, {13, 12, 11, 10, 9, 8, 7, 6, 6, 7, 8, 9, 10, 11, 12, 13}, {12, 11, 10, 9, 8, 7, 6, 5, 5, 6, 7, 8, 9, 10, 11, 12},