asdf

Dependencies:   L3GD20 LSM303DLHC mbed

Committer:
goy5022
Date:
Thu Apr 03 23:58:04 2014 +0000
Revision:
8:ce5b1bf38077
Parent:
7:95ebadc83fc7
asdf

Who changed what in which revision?

UserRevisionLine numberNew contents of line
goy5022 0:c2ec30f28676 1 #ifndef MAPPING_H
goy5022 0:c2ec30f28676 2 #define MAPPING_H
goy5022 0:c2ec30f28676 3
goy5022 0:c2ec30f28676 4 const unsigned char EMPTY = 0x00;
goy5022 0:c2ec30f28676 5 const unsigned char LEFT = 0x01;
goy5022 0:c2ec30f28676 6 const unsigned char RIGHT = 0x02;
goy5022 0:c2ec30f28676 7 const unsigned char BOTTOM = 0x04;
goy5022 0:c2ec30f28676 8 const unsigned char TOP = 0x08;
goy5022 0:c2ec30f28676 9 const unsigned char FULL = 0x0F;
goy5022 2:997f57aee3b7 10 const unsigned char visited = 0x10;
goy5022 2:997f57aee3b7 11 const unsigned char x = 0x20;
goy5022 2:997f57aee3b7 12 const unsigned char y = 0x40;
goy5022 2:997f57aee3b7 13 const unsigned char z = 0x80;
goy5022 2:997f57aee3b7 14 const unsigned char all = 0xF0;
goy5022 0:c2ec30f28676 15
goy5022 0:c2ec30f28676 16 enum ORIENTATION
goy5022 0:c2ec30f28676 17 {
goy5022 0:c2ec30f28676 18 NORTH,
goy5022 0:c2ec30f28676 19 EAST,
goy5022 0:c2ec30f28676 20 SOUTH,
goy5022 0:c2ec30f28676 21 WEST
goy5022 0:c2ec30f28676 22 };
goy5022 2:997f57aee3b7 23 //unsigned char MAP[16][16];
goy5022 7:95ebadc83fc7 24 int cells_traveled = 0;
goy5022 2:997f57aee3b7 25 /// X Y
goy5022 7:95ebadc83fc7 26 unsigned char MAP1[16][16] = {
goy5022 2:997f57aee3b7 27
goy5022 2:997f57aee3b7 28 // Y --->
goy5022 2:997f57aee3b7 29 // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
goy5022 2:997f57aee3b7 30 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, //1
goy5022 2:997f57aee3b7 31 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, //2
goy5022 2:997f57aee3b7 32 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, //3
goy5022 2:997f57aee3b7 33 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, //4
goy5022 2:997f57aee3b7 34 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, //5
goy5022 2:997f57aee3b7 35 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, //6
goy5022 2:997f57aee3b7 36 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, //7
goy5022 2:997f57aee3b7 37 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, //8
goy5022 2:997f57aee3b7 38 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, //9 X
goy5022 2:997f57aee3b7 39 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, //10
goy5022 2:997f57aee3b7 40 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, //11
goy5022 2:997f57aee3b7 41 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, //12
goy5022 2:997f57aee3b7 42 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, //13
goy5022 2:997f57aee3b7 43 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, //14
goy5022 2:997f57aee3b7 44 {0xF3, 0xF5, 0xF0, 0xFC, 0xF6, 0xF7, 0xF7, 0xF5, 0xF0, 0xFC, 0xF0, 0xF0, 0xFC, 0xFC, 0xFE, 0xF7}, //15
goy5022 2:997f57aee3b7 45 {0xF5, 0xFC, 0xF4, 0xFC, 0xFC, 0xFE, 0xFD, 0xFC, 0xF4, 0xFC, 0xF6, 0xF5, 0xFC, 0xFC, 0xFC, 0xFE} //16
goy5022 2:997f57aee3b7 46 };
goy5022 0:c2ec30f28676 47
goy5022 7:95ebadc83fc7 48 unsigned char MAP[16][16] = {
goy5022 7:95ebadc83fc7 49
goy5022 7:95ebadc83fc7 50 // Y --->
goy5022 7:95ebadc83fc7 51 // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
goy5022 7:95ebadc83fc7 52 {0x09, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0A}, //1
goy5022 7:95ebadc83fc7 53 {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}, //2
goy5022 7:95ebadc83fc7 54 {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}, //3
goy5022 7:95ebadc83fc7 55 {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}, //4
goy5022 7:95ebadc83fc7 56 {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}, //5
goy5022 7:95ebadc83fc7 57 {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}, //6
goy5022 7:95ebadc83fc7 58 {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}, //7
goy5022 7:95ebadc83fc7 59 {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}, //8
goy5022 7:95ebadc83fc7 60 {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}, //9 | X
goy5022 7:95ebadc83fc7 61 {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}, //10 |
goy5022 7:95ebadc83fc7 62 {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}, //11|
goy5022 7:95ebadc83fc7 63 {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}, //12
goy5022 7:95ebadc83fc7 64 {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}, //13
goy5022 7:95ebadc83fc7 65 {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}, //14
goy5022 7:95ebadc83fc7 66 {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}, //15
goy5022 7:95ebadc83fc7 67 {0x07, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x06} //16
goy5022 7:95ebadc83fc7 68 };
goy5022 7:95ebadc83fc7 69
goy5022 7:95ebadc83fc7 70 ORIENTATION orientation = NORTH;
goy5022 0:c2ec30f28676 71 unsigned char Xpos;
goy5022 0:c2ec30f28676 72 unsigned char Ypos;
goy5022 0:c2ec30f28676 73
goy5022 0:c2ec30f28676 74 void initMapping()
goy5022 0:c2ec30f28676 75 {
goy5022 0:c2ec30f28676 76 for(int i = 0; i < 16; i++)
goy5022 0:c2ec30f28676 77 for(int j = 0; j < 16; j++)
goy5022 2:997f57aee3b7 78 MAP[i][j] = EMPTY;
goy5022 0:c2ec30f28676 79
goy5022 7:95ebadc83fc7 80 Xpos = 15;
goy5022 0:c2ec30f28676 81 Ypos = 0;
goy5022 0:c2ec30f28676 82
goy5022 2:997f57aee3b7 83 orientation = NORTH;
goy5022 0:c2ec30f28676 84 }
goy5022 0:c2ec30f28676 85
goy5022 2:997f57aee3b7 86 int getXpos() { return Xpos; }
goy5022 2:997f57aee3b7 87
goy5022 2:997f57aee3b7 88 int getYpos() { return Ypos; }
goy5022 0:c2ec30f28676 89
goy5022 0:c2ec30f28676 90 bool validDimen(unsigned char x, unsigned char y)
goy5022 0:c2ec30f28676 91 {
goy5022 0:c2ec30f28676 92 return ((unsigned char)0 <= x && x < (unsigned char)16 && (unsigned char)0 <= y && y < (unsigned char)16);
goy5022 0:c2ec30f28676 93 }
goy5022 0:c2ec30f28676 94
goy5022 0:c2ec30f28676 95 bool getTopWall(unsigned char x, unsigned char y)
goy5022 0:c2ec30f28676 96 {
goy5022 0:c2ec30f28676 97 return MAP[x][y] & TOP;
goy5022 0:c2ec30f28676 98 }
goy5022 0:c2ec30f28676 99
goy5022 0:c2ec30f28676 100 bool getBottomWall(unsigned char x, unsigned char y)
goy5022 0:c2ec30f28676 101 {
goy5022 0:c2ec30f28676 102 return MAP[x][y] & BOTTOM;
goy5022 0:c2ec30f28676 103 }
goy5022 0:c2ec30f28676 104
goy5022 0:c2ec30f28676 105 bool getLeftWall(unsigned char x, unsigned char y)
goy5022 0:c2ec30f28676 106 {
goy5022 0:c2ec30f28676 107 return MAP[x][y] & LEFT;
goy5022 0:c2ec30f28676 108 }
goy5022 0:c2ec30f28676 109
goy5022 0:c2ec30f28676 110 bool getRightWall(unsigned char x, unsigned char y)
goy5022 0:c2ec30f28676 111 {
goy5022 0:c2ec30f28676 112 return MAP[x][y] & RIGHT;
goy5022 0:c2ec30f28676 113 }
goy5022 0:c2ec30f28676 114
goy5022 2:997f57aee3b7 115 void setTopWall(unsigned char x, unsigned char y, bool wall)
goy5022 0:c2ec30f28676 116 {
goy5022 0:c2ec30f28676 117 if(validDimen(x, y))
goy5022 2:997f57aee3b7 118 if(wall)
goy5022 2:997f57aee3b7 119 MAP[x][y] |= TOP;
goy5022 2:997f57aee3b7 120 else
goy5022 2:997f57aee3b7 121 MAP[x][y] &= ~TOP;
goy5022 0:c2ec30f28676 122 }
goy5022 0:c2ec30f28676 123
goy5022 2:997f57aee3b7 124 void setBottomWall(unsigned char x, unsigned char y, bool wall)
goy5022 0:c2ec30f28676 125 {
goy5022 0:c2ec30f28676 126 if(validDimen(x, y))
goy5022 2:997f57aee3b7 127 if(wall)
goy5022 2:997f57aee3b7 128 MAP[x][y] |= BOTTOM;
goy5022 2:997f57aee3b7 129 else
goy5022 2:997f57aee3b7 130 MAP[x][y] &= ~BOTTOM;
goy5022 0:c2ec30f28676 131 }
goy5022 0:c2ec30f28676 132
goy5022 2:997f57aee3b7 133 void setLeftWall(unsigned char x, unsigned char y, bool wall)
goy5022 0:c2ec30f28676 134 {
goy5022 0:c2ec30f28676 135 if(validDimen(x, y))
goy5022 2:997f57aee3b7 136 if(wall)
goy5022 2:997f57aee3b7 137 MAP[x][y] |= LEFT;
goy5022 2:997f57aee3b7 138 else
goy5022 2:997f57aee3b7 139 MAP[x][y] &= ~LEFT;
goy5022 0:c2ec30f28676 140 }
goy5022 0:c2ec30f28676 141
goy5022 2:997f57aee3b7 142 void setRightWall(unsigned char x, unsigned char y, bool wall)
goy5022 0:c2ec30f28676 143 {
goy5022 0:c2ec30f28676 144 if(validDimen(x, y))
goy5022 2:997f57aee3b7 145 if(wall)
goy5022 2:997f57aee3b7 146 MAP[x][y] |= RIGHT;
goy5022 2:997f57aee3b7 147 else
goy5022 2:997f57aee3b7 148 MAP[x][y] &= ~RIGHT;
goy5022 0:c2ec30f28676 149 }
goy5022 2:997f57aee3b7 150 //done
goy5022 0:c2ec30f28676 151 void orientation_turnAround()
goy5022 0:c2ec30f28676 152 {
goy5022 0:c2ec30f28676 153 switch(orientation)
goy5022 0:c2ec30f28676 154 {
goy5022 0:c2ec30f28676 155 case NORTH:
goy5022 0:c2ec30f28676 156 orientation = SOUTH;
goy5022 0:c2ec30f28676 157 break;
goy5022 0:c2ec30f28676 158 case WEST:
goy5022 0:c2ec30f28676 159 orientation = EAST;
goy5022 0:c2ec30f28676 160 break;
goy5022 0:c2ec30f28676 161 case SOUTH:
goy5022 0:c2ec30f28676 162 orientation = NORTH;
goy5022 0:c2ec30f28676 163 break;
goy5022 0:c2ec30f28676 164 case EAST:
goy5022 0:c2ec30f28676 165 orientation = WEST;
goy5022 0:c2ec30f28676 166 break;
goy5022 0:c2ec30f28676 167 }
goy5022 0:c2ec30f28676 168 }
goy5022 0:c2ec30f28676 169
goy5022 2:997f57aee3b7 170
goy5022 0:c2ec30f28676 171 void orientation_turnLeft()
goy5022 0:c2ec30f28676 172 {
goy5022 0:c2ec30f28676 173 switch(orientation)
goy5022 0:c2ec30f28676 174 {
goy5022 0:c2ec30f28676 175 case NORTH:
goy5022 0:c2ec30f28676 176 orientation = WEST;
goy5022 0:c2ec30f28676 177 break;
goy5022 0:c2ec30f28676 178 case WEST:
goy5022 0:c2ec30f28676 179 orientation = SOUTH;
goy5022 0:c2ec30f28676 180 break;
goy5022 0:c2ec30f28676 181 case SOUTH:
goy5022 0:c2ec30f28676 182 orientation = EAST;
goy5022 0:c2ec30f28676 183 break;
goy5022 0:c2ec30f28676 184 case EAST:
goy5022 0:c2ec30f28676 185 orientation = NORTH;
goy5022 0:c2ec30f28676 186 break;
goy5022 0:c2ec30f28676 187 }
goy5022 0:c2ec30f28676 188 }
goy5022 0:c2ec30f28676 189
goy5022 2:997f57aee3b7 190
goy5022 2:997f57aee3b7 191 //done
goy5022 0:c2ec30f28676 192 void orientation_turnRight()
goy5022 0:c2ec30f28676 193 {
goy5022 0:c2ec30f28676 194 switch(orientation)
goy5022 0:c2ec30f28676 195 {
goy5022 0:c2ec30f28676 196 case NORTH:
goy5022 0:c2ec30f28676 197 orientation = EAST;
goy5022 0:c2ec30f28676 198 break;
goy5022 0:c2ec30f28676 199 case WEST:
goy5022 0:c2ec30f28676 200 orientation = NORTH;
goy5022 0:c2ec30f28676 201 break;
goy5022 0:c2ec30f28676 202 case SOUTH:
goy5022 0:c2ec30f28676 203 orientation = WEST;
goy5022 0:c2ec30f28676 204 break;
goy5022 0:c2ec30f28676 205 case EAST:
goy5022 0:c2ec30f28676 206 orientation = SOUTH;
goy5022 0:c2ec30f28676 207 break;
goy5022 0:c2ec30f28676 208 }
goy5022 0:c2ec30f28676 209 }
goy5022 0:c2ec30f28676 210
goy5022 2:997f57aee3b7 211 //DONE
goy5022 2:997f57aee3b7 212 void setFront(unsigned char x, unsigned char y, bool w)
goy5022 0:c2ec30f28676 213 {
goy5022 0:c2ec30f28676 214 switch(orientation)
goy5022 0:c2ec30f28676 215 {
goy5022 0:c2ec30f28676 216 case NORTH:
goy5022 2:997f57aee3b7 217 setTopWall(x, y, w);
goy5022 2:997f57aee3b7 218 setBottomWall(x - 1, y, w);
goy5022 0:c2ec30f28676 219 break;
goy5022 0:c2ec30f28676 220 case EAST:
goy5022 2:997f57aee3b7 221 setRightWall(x, y, w);
goy5022 2:997f57aee3b7 222 setLeftWall(x, y + 1, w);
goy5022 0:c2ec30f28676 223 break;
goy5022 0:c2ec30f28676 224 case WEST:
goy5022 2:997f57aee3b7 225 setLeftWall(x, y, w);
goy5022 2:997f57aee3b7 226 setRightWall(x, y - 1, w);
goy5022 0:c2ec30f28676 227 break;
goy5022 0:c2ec30f28676 228 case SOUTH:
goy5022 2:997f57aee3b7 229 setBottomWall(x, y, w);
goy5022 2:997f57aee3b7 230 setTopWall(x + 1, y, w);
goy5022 0:c2ec30f28676 231 break;
goy5022 0:c2ec30f28676 232 }
goy5022 0:c2ec30f28676 233 }
goy5022 0:c2ec30f28676 234
goy5022 2:997f57aee3b7 235 //DONE
goy5022 2:997f57aee3b7 236 void setRight(unsigned char x, unsigned char y, bool w)
goy5022 0:c2ec30f28676 237 {
goy5022 0:c2ec30f28676 238 switch(orientation)
goy5022 0:c2ec30f28676 239 {
goy5022 0:c2ec30f28676 240 case WEST:
goy5022 2:997f57aee3b7 241 setTopWall(x, y, w);
goy5022 2:997f57aee3b7 242 setBottomWall(x - 1, y, w);
goy5022 0:c2ec30f28676 243 break;
goy5022 0:c2ec30f28676 244 case NORTH:
goy5022 2:997f57aee3b7 245 setRightWall(x, y, w);
goy5022 2:997f57aee3b7 246 setLeftWall(x, y + 1, w);
goy5022 0:c2ec30f28676 247 break;
goy5022 0:c2ec30f28676 248 case SOUTH:
goy5022 2:997f57aee3b7 249 setLeftWall(x, y, w);
goy5022 2:997f57aee3b7 250 setRightWall(x, y - 1, w);
goy5022 0:c2ec30f28676 251 break;
goy5022 0:c2ec30f28676 252 case EAST:
goy5022 2:997f57aee3b7 253 setBottomWall(x, y, w);
goy5022 2:997f57aee3b7 254 setTopWall(x + 1, y, w);
goy5022 0:c2ec30f28676 255 break;
goy5022 0:c2ec30f28676 256 }
goy5022 0:c2ec30f28676 257 }
goy5022 0:c2ec30f28676 258
goy5022 2:997f57aee3b7 259 //DONE
goy5022 2:997f57aee3b7 260 void setLeft(unsigned char x, unsigned char y, bool w)
goy5022 0:c2ec30f28676 261 {
goy5022 0:c2ec30f28676 262 switch(orientation)
goy5022 0:c2ec30f28676 263 {
goy5022 0:c2ec30f28676 264 case EAST:
goy5022 2:997f57aee3b7 265 setTopWall(x, y, w);
goy5022 2:997f57aee3b7 266 setBottomWall(x - 1, y, w);
goy5022 0:c2ec30f28676 267 break;
goy5022 0:c2ec30f28676 268 case SOUTH:
goy5022 2:997f57aee3b7 269 setRightWall(x, y, w);
goy5022 2:997f57aee3b7 270 setLeftWall(x, y + 1, w);
goy5022 0:c2ec30f28676 271 break;
goy5022 0:c2ec30f28676 272 case NORTH:
goy5022 2:997f57aee3b7 273 setLeftWall(x, y, w);
goy5022 2:997f57aee3b7 274 setRightWall(x, y - 1, w);
goy5022 0:c2ec30f28676 275 break;
goy5022 0:c2ec30f28676 276 case WEST:
goy5022 2:997f57aee3b7 277 setBottomWall(x, y, w);
goy5022 2:997f57aee3b7 278 setTopWall(x + 1, y, w);
goy5022 0:c2ec30f28676 279 break;
goy5022 0:c2ec30f28676 280 }
goy5022 0:c2ec30f28676 281 }
goy5022 0:c2ec30f28676 282
goy5022 2:997f57aee3b7 283 void setLeft(bool exists)
goy5022 0:c2ec30f28676 284 {
goy5022 2:997f57aee3b7 285 setLeft(Xpos, Ypos, exists);
goy5022 0:c2ec30f28676 286 }
goy5022 0:c2ec30f28676 287
goy5022 2:997f57aee3b7 288 void setRight(bool exists)
goy5022 0:c2ec30f28676 289 {
goy5022 2:997f57aee3b7 290 setRight(Xpos, Ypos, exists);
goy5022 0:c2ec30f28676 291 }
goy5022 0:c2ec30f28676 292
goy5022 2:997f57aee3b7 293 void setFront(bool exists)
goy5022 0:c2ec30f28676 294 {
goy5022 2:997f57aee3b7 295 setFront(Xpos, Ypos, exists);
goy5022 0:c2ec30f28676 296 }
goy5022 0:c2ec30f28676 297
goy5022 5:9e504a5a1f48 298 void printMap(Serial out)
goy5022 5:9e504a5a1f48 299 {
goy5022 5:9e504a5a1f48 300 for(int i = 0; i < 16; i++)
goy5022 5:9e504a5a1f48 301 {
goy5022 5:9e504a5a1f48 302 for(int j = 0; j < 16; j++)
goy5022 5:9e504a5a1f48 303 {
goy5022 5:9e504a5a1f48 304 out.printf("%-2i ", MAP[i][j]);
goy5022 5:9e504a5a1f48 305 }
goy5022 5:9e504a5a1f48 306
goy5022 5:9e504a5a1f48 307 out.printf("\r");
goy5022 5:9e504a5a1f48 308 }
goy5022 5:9e504a5a1f48 309 out.printf("\n\r");
goy5022 5:9e504a5a1f48 310 }
goy5022 5:9e504a5a1f48 311
goy5022 7:95ebadc83fc7 312 float round(double r)
goy5022 7:95ebadc83fc7 313 {
goy5022 7:95ebadc83fc7 314 double f = floor(r);
goy5022 7:95ebadc83fc7 315 if(r > f + 0.5)
goy5022 7:95ebadc83fc7 316 r = ceil(r);
goy5022 7:95ebadc83fc7 317 else
goy5022 7:95ebadc83fc7 318 r = f;
goy5022 7:95ebadc83fc7 319 return r;
goy5022 7:95ebadc83fc7 320 }
goy5022 7:95ebadc83fc7 321
goy5022 7:95ebadc83fc7 322
goy5022 7:95ebadc83fc7 323 void updateMaze()
goy5022 7:95ebadc83fc7 324 {
goy5022 7:95ebadc83fc7 325 //int cells_traveled = (int)round(time/0.3351);
goy5022 7:95ebadc83fc7 326 while(cells_traveled > 1)
goy5022 7:95ebadc83fc7 327 {
goy5022 7:95ebadc83fc7 328 //increment position along direction
goy5022 7:95ebadc83fc7 329 setRight(true);
goy5022 7:95ebadc83fc7 330 setLeft(true);
goy5022 7:95ebadc83fc7 331 cells_traveled--;
goy5022 7:95ebadc83fc7 332 }
goy5022 7:95ebadc83fc7 333 //increment position along direction
goy5022 7:95ebadc83fc7 334 if(wallRight())
goy5022 7:95ebadc83fc7 335 setRight(true);
goy5022 7:95ebadc83fc7 336 else
goy5022 7:95ebadc83fc7 337 setRight(false);
goy5022 7:95ebadc83fc7 338 if(wallLeft())
goy5022 7:95ebadc83fc7 339 setLeft(true);
goy5022 7:95ebadc83fc7 340 else
goy5022 7:95ebadc83fc7 341 setLeft(false);
goy5022 7:95ebadc83fc7 342 if(wallFront())
goy5022 7:95ebadc83fc7 343 setFront(true);
goy5022 7:95ebadc83fc7 344 else
goy5022 7:95ebadc83fc7 345 setFront(false);
goy5022 7:95ebadc83fc7 346 }
goy5022 7:95ebadc83fc7 347
goy5022 7:95ebadc83fc7 348
goy5022 7:95ebadc83fc7 349
goy5022 0:c2ec30f28676 350 #endif