Alexandre Salconi-Denis
/
ProjetOctopode
Programme de contrôle de l'octopode 4DOF, Theraphosa-Salconi.
CtrlBridge
- fonction quelquonque pour communiquer avec les module
- fonction quelquonque pour faire des recherche dans les module dispo
- autre fonction pour jouer avec MemRegistre
Version 1.2.0
- Ajout d'un mode de simulation pour tester le code avec seulement un contrôleur stm32
labyrinthe.cpp@37:f53e9f7a14df, 2015-09-29 (annotated)
- Committer:
- salco
- Date:
- Tue Sep 29 17:23:25 2015 +0000
- Revision:
- 37:f53e9f7a14df
- Parent:
- 36:474d4795aafa
- Child:
- 38:57d5f36a0333
modification de la fonction analiseMaze();
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
salco | 35:d81f6b927932 | 1 | /** |
salco | 35:d81f6b927932 | 2 | * @file labyrinthe.cpp |
salco | 35:d81f6b927932 | 3 | * @brief Regroupement de fonction pour enregistrer le millieu en 2D. |
salco | 35:d81f6b927932 | 4 | * @author Salco |
salco | 35:d81f6b927932 | 5 | * @version 2.00 |
salco | 35:d81f6b927932 | 6 | * @date 11 mars 2015 |
salco | 35:d81f6b927932 | 7 | */ |
salco | 28:ac5c6350ed9a | 8 | #include "labyrinthe.h" |
salco | 28:ac5c6350ed9a | 9 | |
salco | 36:474d4795aafa | 10 | typedef Labyrinthe::coordoner_t coordonerr; |
salco | 36:474d4795aafa | 11 | typedef Labyrinthe::case_t case_t; |
salco | 28:ac5c6350ed9a | 12 | |
salco | 28:ac5c6350ed9a | 13 | Labyrinthe::Labyrinthe() |
salco | 28:ac5c6350ed9a | 14 | { |
salco | 28:ac5c6350ed9a | 15 | direction=0; |
salco | 28:ac5c6350ed9a | 16 | mapDuLabyrinthe.clear(); |
salco | 28:ac5c6350ed9a | 17 | addMap(0,0); |
salco | 36:474d4795aafa | 18 | m_posX=1; |
salco | 36:474d4795aafa | 19 | m_posY=1; |
salco | 28:ac5c6350ed9a | 20 | } |
salco | 28:ac5c6350ed9a | 21 | |
salco | 28:ac5c6350ed9a | 22 | Labyrinthe::~Labyrinthe() |
salco | 28:ac5c6350ed9a | 23 | { |
salco | 28:ac5c6350ed9a | 24 | } |
salco | 28:ac5c6350ed9a | 25 | |
salco | 37:f53e9f7a14df | 26 | //modifie X et Y pour metre le bon formatage des coordoner et sort l'ID de la case |
salco | 37:f53e9f7a14df | 27 | //tout ca est qu'un formatage il ne garanti pas que la tuile existe |
salco | 37:f53e9f7a14df | 28 | coordonerr Labyrinthe::getCoordoner(signed char &x, signed char &y) |
salco | 28:ac5c6350ed9a | 29 | { |
salco | 36:474d4795aafa | 30 | coordonerr result = unset; |
salco | 37:f53e9f7a14df | 31 | signed char newPosX = (signed char)x; |
salco | 37:f53e9f7a14df | 32 | signed char newPosY = (signed char)y; |
salco | 36:474d4795aafa | 33 | |
salco | 36:474d4795aafa | 34 | #ifdef DEGUG_LABIRINTH_GET_COORDONER |
salco | 36:474d4795aafa | 35 | debug("\n\r----------getCoordoner------\n\r"); |
salco | 37:f53e9f7a14df | 36 | debug(" x: %i Y: %i\n\r",(signed char)x, (signed char)newPosY); |
salco | 36:474d4795aafa | 37 | #endif |
salco | 36:474d4795aafa | 38 | |
salco | 36:474d4795aafa | 39 | |
salco | 37:f53e9f7a14df | 40 | newPosX = 3*((((signed char)newPosX<0)? (signed char)newPosX-2:(signed char)newPosX)/3); // je veux le nobre de fois quil a fait un tours et donc seulment les entier |
salco | 37:f53e9f7a14df | 41 | newPosY = 3*((((signed char)newPosY<0)? (signed char)newPosY-2:(signed char)newPosY)/3); |
salco | 36:474d4795aafa | 42 | |
salco | 36:474d4795aafa | 43 | #ifdef DEGUG_LABIRINTH_GET_COORDONER |
salco | 37:f53e9f7a14df | 44 | debug(" newPosX: %i newPosY: %i\n\r",(signed char)newPosX,(signed char)newPosY); |
salco | 36:474d4795aafa | 45 | #endif |
salco | 28:ac5c6350ed9a | 46 | |
salco | 36:474d4795aafa | 47 | |
salco | 36:474d4795aafa | 48 | |
salco | 37:f53e9f7a14df | 49 | switch((signed char)x - (signed char)newPosX){ |
salco | 36:474d4795aafa | 50 | case 0: |
salco | 36:474d4795aafa | 51 | switch(y - newPosY){ |
salco | 36:474d4795aafa | 52 | case 0: |
salco | 36:474d4795aafa | 53 | result=C1; |
salco | 36:474d4795aafa | 54 | break; |
salco | 36:474d4795aafa | 55 | |
salco | 36:474d4795aafa | 56 | case 1: |
salco | 37:f53e9f7a14df | 57 | result=C4; |
salco | 36:474d4795aafa | 58 | break; |
salco | 36:474d4795aafa | 59 | |
salco | 36:474d4795aafa | 60 | case 2: |
salco | 37:f53e9f7a14df | 61 | result=C7; |
salco | 36:474d4795aafa | 62 | break; |
salco | 36:474d4795aafa | 63 | } |
salco | 36:474d4795aafa | 64 | break; |
salco | 36:474d4795aafa | 65 | |
salco | 36:474d4795aafa | 66 | case 1: |
salco | 36:474d4795aafa | 67 | switch(y - newPosY){ |
salco | 36:474d4795aafa | 68 | case 0: |
salco | 37:f53e9f7a14df | 69 | result=C2; |
salco | 36:474d4795aafa | 70 | break; |
salco | 36:474d4795aafa | 71 | |
salco | 36:474d4795aafa | 72 | case 1: |
salco | 36:474d4795aafa | 73 | result=C5; |
salco | 36:474d4795aafa | 74 | break; |
salco | 36:474d4795aafa | 75 | |
salco | 36:474d4795aafa | 76 | case 2: |
salco | 37:f53e9f7a14df | 77 | result=C8; |
salco | 36:474d4795aafa | 78 | break; |
salco | 36:474d4795aafa | 79 | } |
salco | 36:474d4795aafa | 80 | break; |
salco | 36:474d4795aafa | 81 | |
salco | 36:474d4795aafa | 82 | case 2: |
salco | 36:474d4795aafa | 83 | switch(y - newPosY){ |
salco | 36:474d4795aafa | 84 | case 0: |
salco | 37:f53e9f7a14df | 85 | result=C3; |
salco | 36:474d4795aafa | 86 | break; |
salco | 36:474d4795aafa | 87 | |
salco | 36:474d4795aafa | 88 | case 1: |
salco | 37:f53e9f7a14df | 89 | result=C6; |
salco | 36:474d4795aafa | 90 | break; |
salco | 36:474d4795aafa | 91 | |
salco | 36:474d4795aafa | 92 | case 2: |
salco | 36:474d4795aafa | 93 | result=C9; |
salco | 36:474d4795aafa | 94 | break; |
salco | 36:474d4795aafa | 95 | } |
salco | 36:474d4795aafa | 96 | break; |
salco | 36:474d4795aafa | 97 | } |
salco | 36:474d4795aafa | 98 | |
salco | 37:f53e9f7a14df | 99 | x = (signed char)newPosX; |
salco | 28:ac5c6350ed9a | 100 | y = newPosY; |
salco | 36:474d4795aafa | 101 | /*result =(coordonerr)( 2 + newPosX); |
salco | 28:ac5c6350ed9a | 102 | |
salco | 28:ac5c6350ed9a | 103 | switch(newPosY) { |
salco | 28:ac5c6350ed9a | 104 | case-1: |
salco | 28:ac5c6350ed9a | 105 | result = result + (3*2); |
salco | 28:ac5c6350ed9a | 106 | break; |
salco | 28:ac5c6350ed9a | 107 | |
salco | 28:ac5c6350ed9a | 108 | case 0: |
salco | 28:ac5c6350ed9a | 109 | result = result + (3*1); |
salco | 28:ac5c6350ed9a | 110 | break; |
salco | 28:ac5c6350ed9a | 111 | |
salco | 28:ac5c6350ed9a | 112 | case 1: |
salco | 28:ac5c6350ed9a | 113 | result = result + (3*0); |
salco | 28:ac5c6350ed9a | 114 | break; |
salco | 36:474d4795aafa | 115 | }*/ |
salco | 36:474d4795aafa | 116 | #ifdef DEGUG_LABIRINTH_GET_COORDONER |
salco | 37:f53e9f7a14df | 117 | //debug(" newPosX: %i newPosY: %i\n\r",newPosX,newPosY); |
salco | 36:474d4795aafa | 118 | //debug("\n\r result: X: %02d Y:%02d",newPosX,newPosY); |
salco | 36:474d4795aafa | 119 | debug("\n\r result: :%02d \n\r",result); |
salco | 37:f53e9f7a14df | 120 | debug("--------------------\n\r"); |
salco | 36:474d4795aafa | 121 | #endif |
salco | 28:ac5c6350ed9a | 122 | |
salco | 28:ac5c6350ed9a | 123 | return result; |
salco | 28:ac5c6350ed9a | 124 | } |
salco | 36:474d4795aafa | 125 | coordonerr Labyrinthe::getCoordoner(void) |
salco | 28:ac5c6350ed9a | 126 | { |
salco | 36:474d4795aafa | 127 | coordonerr result; |
salco | 37:f53e9f7a14df | 128 | signed char newPosX = m_posX; |
salco | 37:f53e9f7a14df | 129 | signed char newPosY = m_posY; |
salco | 36:474d4795aafa | 130 | |
salco | 36:474d4795aafa | 131 | result = getCoordoner(newPosX,newPosY); |
salco | 28:ac5c6350ed9a | 132 | |
salco | 28:ac5c6350ed9a | 133 | return result; |
salco | 28:ac5c6350ed9a | 134 | } |
salco | 28:ac5c6350ed9a | 135 | |
salco | 35:d81f6b927932 | 136 | string Labyrinthe::showMap(void) |
salco | 28:ac5c6350ed9a | 137 | { |
salco | 28:ac5c6350ed9a | 138 | return showMap(m_posX,m_posY); |
salco | 28:ac5c6350ed9a | 139 | } |
salco | 37:f53e9f7a14df | 140 | string Labyrinthe::showMap(signed char x, signed char y) |
salco | 28:ac5c6350ed9a | 141 | { |
salco | 28:ac5c6350ed9a | 142 | //bool result=false; |
salco | 28:ac5c6350ed9a | 143 | string theMap; |
salco | 28:ac5c6350ed9a | 144 | theMap.clear(); |
salco | 37:f53e9f7a14df | 145 | #ifdef DEBUG_LABYRINTHE_SHOW_MAP |
salco | 37:f53e9f7a14df | 146 | debug("\n\r----------showmap------\n\r"); |
salco | 37:f53e9f7a14df | 147 | #endif |
salco | 28:ac5c6350ed9a | 148 | /* char newPosX = x; |
salco | 28:ac5c6350ed9a | 149 | char newPosY = y; |
salco | 28:ac5c6350ed9a | 150 | |
salco | 28:ac5c6350ed9a | 151 | getCoordoner(newPosX,newPosY); |
salco | 28:ac5c6350ed9a | 152 | unsigned char templateX,templateY; |
salco | 28:ac5c6350ed9a | 153 | for(int i=0; ((i*DEFAULTLABLEIGHT)<mapDuLabyrinthe.size()) && (!result);i++) |
salco | 28:ac5c6350ed9a | 154 | { |
salco | 28:ac5c6350ed9a | 155 | templateX = (mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)])>>1; |
salco | 28:ac5c6350ed9a | 156 | templateY = ((mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)])&1)<<7; |
salco | 28:ac5c6350ed9a | 157 | templateY += ((mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)+1])>>2); |
salco | 28:ac5c6350ed9a | 158 | |
salco | 28:ac5c6350ed9a | 159 | if((templateX == newPosX) && (templateY == newPosY)) |
salco | 28:ac5c6350ed9a | 160 | { |
salco | 28:ac5c6350ed9a | 161 | result=true; |
salco | 28:ac5c6350ed9a | 162 | theMap.append(1,((mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)+1])& 3)); |
salco | 28:ac5c6350ed9a | 163 | } |
salco | 28:ac5c6350ed9a | 164 | }*/ |
salco | 28:ac5c6350ed9a | 165 | int stringPosition = searchCoord(x,y); |
salco | 28:ac5c6350ed9a | 166 | if(stringPosition != -1) { |
salco | 28:ac5c6350ed9a | 167 | theMap.append(1,((mapDuLabyrinthe[(stringPosition)+1]>>0)& 3)); |
salco | 28:ac5c6350ed9a | 168 | theMap.append(1,((mapDuLabyrinthe[(stringPosition)+2]>>6)& 3)); |
salco | 28:ac5c6350ed9a | 169 | theMap.append(1,((mapDuLabyrinthe[(stringPosition)+2]>>4)& 3)); |
salco | 28:ac5c6350ed9a | 170 | |
salco | 28:ac5c6350ed9a | 171 | theMap.append(1,((mapDuLabyrinthe[(stringPosition)+2]>>2)& 3)); |
salco | 28:ac5c6350ed9a | 172 | theMap.append(1,((mapDuLabyrinthe[(stringPosition)+2]>>0)& 3)); |
salco | 28:ac5c6350ed9a | 173 | theMap.append(1,((mapDuLabyrinthe[(stringPosition)+3]>>6)& 3)); |
salco | 28:ac5c6350ed9a | 174 | |
salco | 28:ac5c6350ed9a | 175 | theMap.append(1,((mapDuLabyrinthe[(stringPosition)+3]>>4)& 3)); |
salco | 28:ac5c6350ed9a | 176 | theMap.append(1,((mapDuLabyrinthe[(stringPosition)+3]>>2)& 3)); |
salco | 28:ac5c6350ed9a | 177 | theMap.append(1,((mapDuLabyrinthe[(stringPosition)+3]>>0)& 3)); |
salco | 28:ac5c6350ed9a | 178 | } |
salco | 35:d81f6b927932 | 179 | |
salco | 37:f53e9f7a14df | 180 | #ifdef DEBUG_LABYRINTHE_SHOW_MAP |
salco | 37:f53e9f7a14df | 181 | debug(" mapDuLabyrinthe size: %i \n\r",mapDuLabyrinthe.size()); |
salco | 35:d81f6b927932 | 182 | debug(" stringPosition: %i \n\r",stringPosition); |
salco | 35:d81f6b927932 | 183 | if(stringPosition != -1) { |
salco | 37:f53e9f7a14df | 184 | debug(" theMap size: %i \n\r",theMap.size()); |
salco | 36:474d4795aafa | 185 | debug(" (mapDuLabyrinthe[(stringPosition)+1]>>0): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+1]>>0),((mapDuLabyrinthe[(stringPosition)+1]>>0)& 3)); //c1 |
salco | 36:474d4795aafa | 186 | debug(" (mapDuLabyrinthe[(stringPosition)+2]>>6): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+2]>>6),((mapDuLabyrinthe[(stringPosition)+2]>>6)& 3)); //c2 |
salco | 36:474d4795aafa | 187 | debug(" (mapDuLabyrinthe[(stringPosition)+2]>>4): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+2]>>4),((mapDuLabyrinthe[(stringPosition)+2]>>4)& 3)); //c3 |
salco | 35:d81f6b927932 | 188 | debug(" \n\r"); |
salco | 36:474d4795aafa | 189 | debug(" (mapDuLabyrinthe[(stringPosition)+2]>>2): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+2]>>2),((mapDuLabyrinthe[(stringPosition)+2]>>2)& 3)); //c4 |
salco | 36:474d4795aafa | 190 | debug(" (mapDuLabyrinthe[(stringPosition)+2]>>0): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+2]>>0),((mapDuLabyrinthe[(stringPosition)+2]>>0)& 3)); //c5 |
salco | 36:474d4795aafa | 191 | debug(" (mapDuLabyrinthe[(stringPosition)+3]>>6): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+3]>>6),((mapDuLabyrinthe[(stringPosition)+3]>>6)& 3)); //c6 |
salco | 35:d81f6b927932 | 192 | debug(" \n\r"); |
salco | 36:474d4795aafa | 193 | debug(" (mapDuLabyrinthe[(stringPosition)+3]>>4): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+3]>>4),((mapDuLabyrinthe[(stringPosition)+3]>>4)& 3)); //c7 |
salco | 36:474d4795aafa | 194 | debug(" (mapDuLabyrinthe[(stringPosition)+3]>>2): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+3]>>2),((mapDuLabyrinthe[(stringPosition)+3]>>2)& 3)); //c8 |
salco | 36:474d4795aafa | 195 | debug(" (mapDuLabyrinthe[(stringPosition)+3]>>0): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+3]>>0),((mapDuLabyrinthe[(stringPosition)+3]>>0)& 3)); //c9 |
salco | 35:d81f6b927932 | 196 | debug(" \n\r"); |
salco | 35:d81f6b927932 | 197 | } |
salco | 35:d81f6b927932 | 198 | debug("\n\r----------------------\n\r"); |
salco | 35:d81f6b927932 | 199 | #endif |
salco | 28:ac5c6350ed9a | 200 | return theMap; |
salco | 28:ac5c6350ed9a | 201 | } |
salco | 28:ac5c6350ed9a | 202 | |
salco | 28:ac5c6350ed9a | 203 | bool Labyrinthe::updateMap(string mapUpdated) |
salco | 28:ac5c6350ed9a | 204 | { |
salco | 28:ac5c6350ed9a | 205 | return updateMap(mapUpdated,m_posX,m_posY); |
salco | 28:ac5c6350ed9a | 206 | } |
salco | 37:f53e9f7a14df | 207 | bool Labyrinthe::updateMap(string mapUpdated,signed char x, signed char y) |
salco | 28:ac5c6350ed9a | 208 | { |
salco | 37:f53e9f7a14df | 209 | #ifdef DEBUG_LABYRINTHE_GRAPHICAL_INTERFACE |
salco | 37:f53e9f7a14df | 210 | debug("\n\r----------updateMap------\n\r"); |
salco | 37:f53e9f7a14df | 211 | #endif |
salco | 28:ac5c6350ed9a | 212 | bool result = true; |
salco | 28:ac5c6350ed9a | 213 | int stringPosition = searchCoord(x,y); |
salco | 28:ac5c6350ed9a | 214 | |
salco | 28:ac5c6350ed9a | 215 | if(stringPosition == -1) |
salco | 37:f53e9f7a14df | 216 | result= false; |
salco | 28:ac5c6350ed9a | 217 | else { |
salco | 36:474d4795aafa | 218 | mapDuLabyrinthe[(stringPosition)+1] = ((mapDuLabyrinthe[(stringPosition)+1]) & 0xFC) | ((mapUpdated[0] &0x03)<<0); |
salco | 36:474d4795aafa | 219 | mapDuLabyrinthe[(stringPosition)+2] = ((mapDuLabyrinthe[(stringPosition)+2]) & 0x3F) | ((mapUpdated[1] &0x03)<<6); |
salco | 28:ac5c6350ed9a | 220 | mapDuLabyrinthe[(stringPosition)+2] = ((mapDuLabyrinthe[(stringPosition)+2]) & 0xCF) | ((mapUpdated[2] &0x03)<<4); |
salco | 28:ac5c6350ed9a | 221 | |
salco | 28:ac5c6350ed9a | 222 | mapDuLabyrinthe[(stringPosition)+2] = ((mapDuLabyrinthe[(stringPosition)+2]) & 0xF3) | ((mapUpdated[3] &0x03)<<2); |
salco | 28:ac5c6350ed9a | 223 | mapDuLabyrinthe[(stringPosition)+2] = ((mapDuLabyrinthe[(stringPosition)+2]) & 0xFC) | ((mapUpdated[4] &0x03)<<0); |
salco | 37:f53e9f7a14df | 224 | mapDuLabyrinthe[(stringPosition)+3] = ((mapDuLabyrinthe[(stringPosition)+3]) & 0x3F) | ((mapUpdated[5] &0x03)<<6); |
salco | 28:ac5c6350ed9a | 225 | |
salco | 37:f53e9f7a14df | 226 | mapDuLabyrinthe[(stringPosition)+3] = ((mapDuLabyrinthe[(stringPosition)+3]) & 0xCF) | ((mapUpdated[6] &0x03)<<4); |
salco | 37:f53e9f7a14df | 227 | mapDuLabyrinthe[(stringPosition)+3] = ((mapDuLabyrinthe[(stringPosition)+3]) & 0xF3) | ((mapUpdated[7] &0x03)<<2); |
salco | 37:f53e9f7a14df | 228 | mapDuLabyrinthe[(stringPosition)+3] = ((mapDuLabyrinthe[(stringPosition)+3]) & 0xFC) | ((mapUpdated[8] &0x03)<<0); |
salco | 28:ac5c6350ed9a | 229 | } |
salco | 37:f53e9f7a14df | 230 | |
salco | 37:f53e9f7a14df | 231 | #ifdef DEBUG_LABYRINTHE_GRAPHICAL_INTERFACE |
salco | 37:f53e9f7a14df | 232 | debug(" result: %i \n\r",result?1:0); |
salco | 37:f53e9f7a14df | 233 | debug(" stringPosition: %i \n\r",stringPosition); |
salco | 37:f53e9f7a14df | 234 | if(stringPosition != -1) { |
salco | 37:f53e9f7a14df | 235 | debug(" (mapDuLabyrinthe[(stringPosition)+1]>>0): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+1]>>0),((mapDuLabyrinthe[(stringPosition)+1]>>0)& 3)); //c1 |
salco | 37:f53e9f7a14df | 236 | debug(" (mapDuLabyrinthe[(stringPosition)+2]>>6): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+2]>>6),((mapDuLabyrinthe[(stringPosition)+2]>>6)& 3)); //c2 |
salco | 37:f53e9f7a14df | 237 | debug(" (mapDuLabyrinthe[(stringPosition)+2]>>4): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+2]>>4),((mapDuLabyrinthe[(stringPosition)+2]>>4)& 3)); //c3 |
salco | 37:f53e9f7a14df | 238 | debug(" \n\r"); |
salco | 37:f53e9f7a14df | 239 | debug(" (mapDuLabyrinthe[(stringPosition)+2]>>2): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+2]>>2),((mapDuLabyrinthe[(stringPosition)+2]>>2)& 3)); //c4 |
salco | 37:f53e9f7a14df | 240 | debug(" (mapDuLabyrinthe[(stringPosition)+2]>>0): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+2]>>0),((mapDuLabyrinthe[(stringPosition)+2]>>0)& 3)); //c5 |
salco | 37:f53e9f7a14df | 241 | debug(" (mapDuLabyrinthe[(stringPosition)+3]>>6): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+3]>>6),((mapDuLabyrinthe[(stringPosition)+3]>>6)& 3)); //c6 |
salco | 37:f53e9f7a14df | 242 | debug(" \n\r"); |
salco | 37:f53e9f7a14df | 243 | debug(" (mapDuLabyrinthe[(stringPosition)+3]>>4): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+3]>>4),((mapDuLabyrinthe[(stringPosition)+3]>>4)& 3)); //c7 |
salco | 37:f53e9f7a14df | 244 | debug(" (mapDuLabyrinthe[(stringPosition)+3]>>2): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+3]>>2),((mapDuLabyrinthe[(stringPosition)+3]>>2)& 3)); //c8 |
salco | 37:f53e9f7a14df | 245 | debug(" (mapDuLabyrinthe[(stringPosition)+3]>>0): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+3]>>0),((mapDuLabyrinthe[(stringPosition)+3]>>0)& 3)); //c9 |
salco | 37:f53e9f7a14df | 246 | debug(" \n\r"); |
salco | 37:f53e9f7a14df | 247 | } |
salco | 37:f53e9f7a14df | 248 | debug("\n\r----------------------\n\r"); |
salco | 37:f53e9f7a14df | 249 | #endif |
salco | 28:ac5c6350ed9a | 250 | |
salco | 28:ac5c6350ed9a | 251 | return result; |
salco | 28:ac5c6350ed9a | 252 | } |
salco | 37:f53e9f7a14df | 253 | bool Labyrinthe::addMap(signed char x, signed char y) |
salco | 28:ac5c6350ed9a | 254 | { |
salco | 28:ac5c6350ed9a | 255 | bool result = true; |
salco | 28:ac5c6350ed9a | 256 | x &= 0x7F; // on coupe le 8eme bit |
salco | 35:d81f6b927932 | 257 | y &= 0x7F; // |
salco | 28:ac5c6350ed9a | 258 | |
salco | 35:d81f6b927932 | 259 | mapDuLabyrinthe.append(1,((x<<1) | (y>>6)) );//x7,x6,x5,x4,x3,x2,x1,y7 |
salco | 37:f53e9f7a14df | 260 | mapDuLabyrinthe.append(1,y<<2); //y6,y5,y4,y3,y2,y1,[C1],[C1] |
salco | 35:d81f6b927932 | 261 | mapDuLabyrinthe.append(2,0); //add C2-C9 vide |
salco | 35:d81f6b927932 | 262 | |
salco | 35:d81f6b927932 | 263 | #ifdef DEBUG_LABYRINTHE_ADD_MAP |
salco | 35:d81f6b927932 | 264 | debug("----addMap----\n\r"); |
salco | 35:d81f6b927932 | 265 | debug("x = %i \n\r",x); |
salco | 35:d81f6b927932 | 266 | debug("y = %i \n\r",y); |
salco | 35:d81f6b927932 | 267 | debug("((x<<1) | (y>>6)) = %i \n\r",((x<<1) | (y>>6))); |
salco | 37:f53e9f7a14df | 268 | |
salco | 35:d81f6b927932 | 269 | debug("-------------\n\r"); |
salco | 35:d81f6b927932 | 270 | #endif |
salco | 28:ac5c6350ed9a | 271 | |
salco | 28:ac5c6350ed9a | 272 | return result; |
salco | 28:ac5c6350ed9a | 273 | } |
salco | 28:ac5c6350ed9a | 274 | |
salco | 36:474d4795aafa | 275 | //renvoi l'ID du 4 byte de la tuile dans le string |
salco | 37:f53e9f7a14df | 276 | // renvoi -1 en cas d'erreur |
salco | 37:f53e9f7a14df | 277 | int Labyrinthe::searchCoord(signed char posX,signed char posY) |
salco | 28:ac5c6350ed9a | 278 | { |
salco | 28:ac5c6350ed9a | 279 | bool result=false; |
salco | 37:f53e9f7a14df | 280 | signed char newPosX = posX; |
salco | 37:f53e9f7a14df | 281 | signed char newPosY = posY; |
salco | 37:f53e9f7a14df | 282 | signed char templateX = 0; |
salco | 37:f53e9f7a14df | 283 | signed char templateY = 0; |
salco | 36:474d4795aafa | 284 | int i=0; |
salco | 37:f53e9f7a14df | 285 | |
salco | 28:ac5c6350ed9a | 286 | //string theMap; |
salco | 28:ac5c6350ed9a | 287 | //theMap.clear(); |
salco | 37:f53e9f7a14df | 288 | debug(DEBUGLABSEARCHCOORD,"------Search coord------\n\r"); |
salco | 35:d81f6b927932 | 289 | debug(DEBUGLABSEARCHCOORD," posX: %i posY: %i \n\r",posX,posY); |
salco | 35:d81f6b927932 | 290 | |
salco | 36:474d4795aafa | 291 | |
salco | 28:ac5c6350ed9a | 292 | getCoordoner(newPosX,newPosY); |
salco | 35:d81f6b927932 | 293 | debug(DEBUGLABSEARCHCOORD," new posX: %i new posY: %i \n\r",newPosX,newPosY); |
salco | 36:474d4795aafa | 294 | |
salco | 35:d81f6b927932 | 295 | debug(DEBUGLABSEARCHCOORD," map size: %i \n\r",mapDuLabyrinthe.size()); |
salco | 36:474d4795aafa | 296 | |
salco | 35:d81f6b927932 | 297 | for( ; ((i*DEFAULTLABLEIGHT) < mapDuLabyrinthe.size()) && (!result); i++) { |
salco | 35:d81f6b927932 | 298 | |
salco | 28:ac5c6350ed9a | 299 | templateX = (mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)])>>1; |
salco | 37:f53e9f7a14df | 300 | templateY = (((mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)])&1)<<6) + ((mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)+1])>>2); |
salco | 37:f53e9f7a14df | 301 | |
salco | 37:f53e9f7a14df | 302 | //patch pour les nombre negatif vue que originelment on est sur un 7 bit |
salco | 37:f53e9f7a14df | 303 | if(templateX & 0x40) templateX |= 0x80; |
salco | 37:f53e9f7a14df | 304 | if(templateY & 0x40) templateY |= 0x80; |
salco | 37:f53e9f7a14df | 305 | |
salco | 36:474d4795aafa | 306 | //templateY += ((mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)+1])>>2); |
salco | 37:f53e9f7a14df | 307 | debug(DEBUGLABSEARCHCOORD," mapDuLabyrinthe par1: %i mapDuLabyrinthe part2: %i \n\r",mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)],mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)+1]); |
salco | 37:f53e9f7a14df | 308 | debug(DEBUGLABSEARCHCOORD," templateX: %i templateY: %i \n\r",templateX,templateY); |
salco | 28:ac5c6350ed9a | 309 | if((templateX == newPosX) && (templateY == newPosY)) { |
salco | 28:ac5c6350ed9a | 310 | result=true; |
salco | 28:ac5c6350ed9a | 311 | //theMap.append(1,((mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)+1])& 3)); |
salco | 28:ac5c6350ed9a | 312 | } |
salco | 28:ac5c6350ed9a | 313 | } |
salco | 36:474d4795aafa | 314 | i--; |
salco | 35:d81f6b927932 | 315 | debug(DEBUGLABSEARCHCOORD," templateX: %i \n\r",templateX); |
salco | 35:d81f6b927932 | 316 | debug(DEBUGLABSEARCHCOORD," templateY: %i \n\r",templateY); |
salco | 36:474d4795aafa | 317 | debug(DEBUGLABSEARCHCOORD," result: %i \n\r",result?1:0); |
salco | 36:474d4795aafa | 318 | debug(DEBUGLABSEARCHCOORD," i*DEFAULTLABLEIGHT: %i \n\r",i*DEFAULTLABLEIGHT); |
salco | 37:f53e9f7a14df | 319 | debug(DEBUGLABSEARCHCOORD,"--------------------\n\r"); |
salco | 36:474d4795aafa | 320 | return (result==false? -1:i*DEFAULTLABLEIGHT); |
salco | 28:ac5c6350ed9a | 321 | } |
salco | 28:ac5c6350ed9a | 322 | |
salco | 36:474d4795aafa | 323 | case_t Labyrinthe::getC(coordonerr cX) |
salco | 28:ac5c6350ed9a | 324 | { |
salco | 28:ac5c6350ed9a | 325 | return getC(m_posX, m_posY, cX); |
salco | 28:ac5c6350ed9a | 326 | } |
salco | 36:474d4795aafa | 327 | /** |
salco | 36:474d4795aafa | 328 | * @param x position X. |
salco | 36:474d4795aafa | 329 | * @param y position Y. |
salco | 36:474d4795aafa | 330 | * @return |
salco | 36:474d4795aafa | 331 | */ |
salco | 37:f53e9f7a14df | 332 | case_t Labyrinthe::getC(signed char x, signed char y) |
salco | 28:ac5c6350ed9a | 333 | { |
salco | 37:f53e9f7a14df | 334 | signed char newPosX = x; |
salco | 37:f53e9f7a14df | 335 | signed char newPosY = y; |
salco | 36:474d4795aafa | 336 | coordonerr maCoordoner; |
salco | 28:ac5c6350ed9a | 337 | maCoordoner=getCoordoner(newPosX,newPosY); |
salco | 28:ac5c6350ed9a | 338 | |
salco | 28:ac5c6350ed9a | 339 | return getC(x, y, maCoordoner); |
salco | 28:ac5c6350ed9a | 340 | } |
salco | 36:474d4795aafa | 341 | |
salco | 37:f53e9f7a14df | 342 | case_t Labyrinthe::getC(signed char x, signed char y, coordonerr cX) |
salco | 28:ac5c6350ed9a | 343 | { |
salco | 37:f53e9f7a14df | 344 | case_t myCoordoner = error; |
salco | 28:ac5c6350ed9a | 345 | string result = showMap(x,y); |
salco | 28:ac5c6350ed9a | 346 | if(result.size() != 0) { |
salco | 37:f53e9f7a14df | 347 | myCoordoner = case_t(result[cX]); |
salco | 37:f53e9f7a14df | 348 | } |
salco | 37:f53e9f7a14df | 349 | return myCoordoner; |
salco | 37:f53e9f7a14df | 350 | } |
salco | 37:f53e9f7a14df | 351 | void Labyrinthe::setC(case_t value, signed char x, signed char y, coordonerr cX) |
salco | 37:f53e9f7a14df | 352 | { |
salco | 37:f53e9f7a14df | 353 | #ifdef DEGUG_LABIRINTH_SET_COORDONER |
salco | 37:f53e9f7a14df | 354 | debug("------SetC coord------\n\r"); |
salco | 37:f53e9f7a14df | 355 | debug(" value: %i\n\r",value); |
salco | 36:474d4795aafa | 356 | debug("coordoner: %i\n\r",cX); |
salco | 37:f53e9f7a14df | 357 | debug(" X:%i Y:%i \n\r",x,y); |
salco | 37:f53e9f7a14df | 358 | #endif |
salco | 37:f53e9f7a14df | 359 | |
salco | 37:f53e9f7a14df | 360 | if(value != error){ |
salco | 37:f53e9f7a14df | 361 | string result = showMap(x,y); |
salco | 37:f53e9f7a14df | 362 | |
salco | 37:f53e9f7a14df | 363 | if(result.size() == 0) {//no map found so we create new tuile |
salco | 37:f53e9f7a14df | 364 | #ifdef DEGUG_LABIRINTH_SET_COORDONER |
salco | 37:f53e9f7a14df | 365 | debug(" no tuile found\n\r"); |
salco | 36:474d4795aafa | 366 | #endif |
salco | 37:f53e9f7a14df | 367 | signed char newPosX = x; |
salco | 37:f53e9f7a14df | 368 | signed char newPosY = y; |
salco | 37:f53e9f7a14df | 369 | |
salco | 37:f53e9f7a14df | 370 | getCoordoner(newPosX,newPosY); |
salco | 37:f53e9f7a14df | 371 | addMap(newPosX,newPosY); |
salco | 37:f53e9f7a14df | 372 | result = showMap(x,y); |
salco | 37:f53e9f7a14df | 373 | #ifdef DEGUG_LABIRINTH_SET_COORDONER |
salco | 37:f53e9f7a14df | 374 | debug(" result: %i\n\r",result.size()); |
salco | 37:f53e9f7a14df | 375 | #endif |
salco | 37:f53e9f7a14df | 376 | } |
salco | 36:474d4795aafa | 377 | |
salco | 37:f53e9f7a14df | 378 | if(result.size() != 0){ |
salco | 36:474d4795aafa | 379 | #ifdef DEGUG_LABIRINTH_SET_COORDONER |
salco | 37:f53e9f7a14df | 380 | debug(" tuile found\n\r"); |
salco | 36:474d4795aafa | 381 | #endif |
salco | 37:f53e9f7a14df | 382 | result[cX-1]=value; |
salco | 37:f53e9f7a14df | 383 | updateMap(result,x,y);//on remet les case modifier dans le string==map |
salco | 37:f53e9f7a14df | 384 | } |
salco | 28:ac5c6350ed9a | 385 | } |
salco | 37:f53e9f7a14df | 386 | |
salco | 37:f53e9f7a14df | 387 | #ifdef DEGUG_LABIRINTH_SET_COORDONER |
salco | 37:f53e9f7a14df | 388 | debug("---------------------\n\r"); |
salco | 37:f53e9f7a14df | 389 | #endif |
salco | 28:ac5c6350ed9a | 390 | } |
salco | 36:474d4795aafa | 391 | void Labyrinthe::setC(case_t value, coordonerr cX) |
salco | 28:ac5c6350ed9a | 392 | { |
salco | 28:ac5c6350ed9a | 393 | setC(value,m_posX, m_posY,cX); |
salco | 28:ac5c6350ed9a | 394 | } |
salco | 37:f53e9f7a14df | 395 | void Labyrinthe::setC(case_t value, signed char x, signed char y) |
salco | 28:ac5c6350ed9a | 396 | { |
salco | 37:f53e9f7a14df | 397 | signed char newPosX = x; |
salco | 37:f53e9f7a14df | 398 | signed char newPosY = y; |
salco | 36:474d4795aafa | 399 | coordonerr maCoordoner; |
salco | 28:ac5c6350ed9a | 400 | maCoordoner=getCoordoner(newPosX,newPosY); |
salco | 37:f53e9f7a14df | 401 | debug("-setcase tempo newPosX: %i, x: %i\n\r",newPosX,x); |
salco | 28:ac5c6350ed9a | 402 | setC(value,x,y,maCoordoner); |
salco | 28:ac5c6350ed9a | 403 | } |
salco | 36:474d4795aafa | 404 | void Labyrinthe::setC_Up(case_t value) |
salco | 28:ac5c6350ed9a | 405 | { |
salco | 28:ac5c6350ed9a | 406 | setC(value,m_posX, m_posY+1); |
salco | 28:ac5c6350ed9a | 407 | } |
salco | 36:474d4795aafa | 408 | void Labyrinthe::setC_Down(case_t value) |
salco | 28:ac5c6350ed9a | 409 | { |
salco | 28:ac5c6350ed9a | 410 | setC(value,m_posX, m_posY-1); |
salco | 28:ac5c6350ed9a | 411 | } |
salco | 36:474d4795aafa | 412 | void Labyrinthe::setC_Left(case_t value) |
salco | 28:ac5c6350ed9a | 413 | { |
salco | 28:ac5c6350ed9a | 414 | setC(value,m_posX-1, m_posY); |
salco | 28:ac5c6350ed9a | 415 | } |
salco | 36:474d4795aafa | 416 | void Labyrinthe::setC_Right(case_t value) |
salco | 28:ac5c6350ed9a | 417 | { |
salco | 28:ac5c6350ed9a | 418 | setC(value,m_posX+1, m_posY); |
salco | 35:d81f6b927932 | 419 | } |
salco | 36:474d4795aafa | 420 | void Labyrinthe::setMyPos(case_t value) |
salco | 35:d81f6b927932 | 421 | { |
salco | 35:d81f6b927932 | 422 | setC(value, m_posX, m_posY); |
salco | 28:ac5c6350ed9a | 423 | } |