From 52f84dc593bb66b0f6906c5a82be225295b451bf Mon Sep 17 00:00:00 2001 From: Arnaud Cadot Date: Tue, 15 Mar 2016 13:55:43 +0100 Subject: [PATCH] Found the bug --- stm32/include/hardware/krabipacket.h | 4 +-- stm32/src/hardware/krabipacket.cpp | 4 +-- stm32/src/initialisation.cpp | 2 +- stm32/src/strategie/krabi2016.cpp | 45 ++++------------------------ stm32/src/strategie/strategiev3.cpp | 22 +++++++++----- 5 files changed, 25 insertions(+), 52 deletions(-) diff --git a/stm32/include/hardware/krabipacket.h b/stm32/include/hardware/krabipacket.h index 531fcb5e..dc14adbd 100644 --- a/stm32/include/hardware/krabipacket.h +++ b/stm32/include/hardware/krabipacket.h @@ -78,7 +78,7 @@ public: KrabiPacket(QByteArray data); #endif - void addData(const void* data, uint8_t size); + void addData(void* data, uint8_t size); void copyData(void* dest, uint8_t size); // args @@ -102,7 +102,7 @@ public: return mCursor + sizeof(T) < mLength; } - void addString(const char* data); + void addString(char *data); char* getString(); void setId(uint8_t id); diff --git a/stm32/src/hardware/krabipacket.cpp b/stm32/src/hardware/krabipacket.cpp index e90e9204..8f8f70bb 100644 --- a/stm32/src/hardware/krabipacket.cpp +++ b/stm32/src/hardware/krabipacket.cpp @@ -74,7 +74,7 @@ bool KrabiPacket::isValid() return mValid; } -void KrabiPacket::addData(const void* data, uint8_t size) +void KrabiPacket::addData(void* data, uint8_t size) { if (mCursor + size + KRABIPACKET_SUFFIX_SIZE > KRABIPACKET_MAXSIZE) return; @@ -93,7 +93,7 @@ void KrabiPacket::copyData(void* dest, uint8_t size) mCursor += size; } -void KrabiPacket::addString(const char* data) +void KrabiPacket::addString(char* data) { int size = 0; while( data[size] != '\0' ) diff --git a/stm32/src/initialisation.cpp b/stm32/src/initialisation.cpp index a0a211dd..063026de 100644 --- a/stm32/src/initialisation.cpp +++ b/stm32/src/initialisation.cpp @@ -27,7 +27,7 @@ extern "C" void SysTick_Handler() Odometrie::odometrie->update(); - //StrategieV2::update(); + //sStrategieV2::update(); Tourelle::getSingleton()->update(); diff --git a/stm32/src/strategie/krabi2016.cpp b/stm32/src/strategie/krabi2016.cpp index 3de5b80c..40fc61b9 100644 --- a/stm32/src/strategie/krabi2016.cpp +++ b/stm32/src/strategie/krabi2016.cpp @@ -11,8 +11,6 @@ Krabi2016::Krabi2016(bool isYellow) : StrategieV3(isYellow) //Initialisation des tableaux d'étapes this->numeroEtapeGarage = ETAPE_GARAGE; tableauEtapesTotal = Etape::initTableauEtapeTotal(NOMBRE_ETAPES);//new Etape*[NOMBRE_ETAPES]; - //actionEtape = new MediumLevelAction*[NOMBRE_ETAPES]; - //actionGoto = new ActionGoTo[NOMBRE_ETAPES]; // Création des étapes @@ -60,55 +58,24 @@ Krabi2016::Krabi2016(bool isYellow) : StrategieV3(isYellow) // Etape::get(4)->setNumeroEtapeFinAction(43); //Clapet notre côté vers notre bord - // Voisins -/* Etape::get(0)->addVoisin(1, false); - - Etape::get(1)->addVoisins(3, 8, 31); - Etape::get(1)->addVoisins(12, 21, 45); */ - - this->nombreEtapes = Etape::getTotalEtapes(); // Lancer Dijkstra startDijkstra(); } -int Krabi2016::getScoreEtape(int i){ - /* TODO : Supprimer le modificateur temporel et inclure directement un coefficient dans le score pour les actions longues - Plus tard : pourquoi pas changer le système en ayant les FEU etc... fils de Etape, ça éviterait aussi le switch dans updateStock(). - Juste faire attention à comment transmettre le stock à update. - */ +int Krabi2016::getScoreEtape(int i) +{ + switch (this->tableauEtapesTotal[i]->getEtapeType()) { case Etape::DEPART : return 0; - case Etape::CLAP : - return 10; -// return 1000000; - case Etape::TAPIS : - return 1000;//STRATEGIE -// return 0; - - case Etape::CABINE : - return 0;//STRATEGIE - - case Etape::AMPOULE : - return 0; - - case Etape::DEPOSER_GOBELET : - /*if (!Pinces::getSingleton()->getEstDispo()) - return 40; - else*/ - return 0; - case Etape::COIN_GAUCHE_HAUT : - return 0; - case Etape::SPOT_SOLITAIRE_COIN : - return 0; - case Etape::COIN_GAUCHE_BAS : - return 0; + /*case Etape::TYPE_ACTION: + return NB_POINTS_ACTION; */ case Etape::POINT_PASSAGE : return 0; default : - return 0; + return 10; /* DEBUG (0 sinon) */ } } diff --git a/stm32/src/strategie/strategiev3.cpp b/stm32/src/strategie/strategiev3.cpp index 54f360f7..ab1188e5 100644 --- a/stm32/src/strategie/strategiev3.cpp +++ b/stm32/src/strategie/strategiev3.cpp @@ -36,6 +36,7 @@ int StrategieV3::update() //this->actionEtape[this->etapeEnCours]->reset(); //this->actionGoto[this->etapeEnCours].reset(); + tableauEtapesTotal[this->etapeEnCours]->reset(); //Si on est en train d'éviter, on revient à l'étape précédente, et on marque l'étape comme à éviter @@ -103,6 +104,8 @@ int StrategieV3::update() this->enTrainEviterReculant = false; this->enTrainEviterAvancant = false; + qDebug() << "Status strat: " << statusStrat; + if(this->statusStrat==2)//Si on vient d'arriver à une étape intermédiare { this->updateIntermedaire(); @@ -128,6 +131,8 @@ int StrategieV3::update() this->etapeEnCours = this->tableauEtapesTotal[this->etapeEnCours]->getNumeroEtapeFinAction() == -1 ? this->etapeEnCours : this->tableauEtapesTotal[this->etapeEnCours]->getNumeroEtapeFinAction(); + + qDebug() << "Etape en cours: " << etapeEnCours; } @@ -139,6 +144,7 @@ int StrategieV3::update() // Sinon, il y a risque de prendre un avertissement pour anti-jeu (évité de peu pour le premier match de Krabi 2014) if(!resteDesChosesAFaire) { + qDebug() << "Trucs à faire 1"; for(int i = 0 ; i < this->nombreEtapes ; i++) { this->tableauEtapesTotal[i]->oublieRobotVu(); @@ -148,6 +154,7 @@ int StrategieV3::update() //S'il n'y a VRAIMENT plus rien à faire if(!resteDesChosesAFaire) { + qDebug() << "Trucs à faire 2"; //Si on est au garage, on s'arrête if(this->etapeEnCours == this->numeroEtapeGarage) { @@ -213,6 +220,8 @@ int StrategieV3::update() this->updateIntermedaire();//On y va } } + + qDebug() << "Update finished"; return this->statusStrat; } @@ -244,7 +253,7 @@ void StrategieV3::updateIntermedaire() if(((this->tableauEtapesTotal[this->etapeEnCours]->getParent()->getNumero())) == etapeOuOnVientDArriver) { #ifndef ROBOTHW - qDebug() << "la prochaine etape est le goal\n"; + qDebug() << "la prochaine etape est le goal\n" << etapeOuOnVientDArriver; #endif this->statusStrat = 1; } @@ -253,13 +262,7 @@ void StrategieV3::updateIntermedaire() //On cherche l'etape suivant vers l'etape - but while(((this->tableauEtapesTotal[this->etapeEnCours]->getParent()->getNumero())) != etapeOuOnVientDArriver) { - #ifndef ROBOTHW - qDebug() << "On cherche l'etape suivant vers l'etape - but" << this->etapeEnCours << "\n"; - qDebug() << "tableauEtapesTotal[0]" << (this->tableauEtapesTotal[0]->getEtapeType()); - qDebug() << "tableauEtapesTotal[10]" << (this->tableauEtapesTotal[10]->getEtapeType()); - qDebug() << "tableauEtapesTotal[36]" << (this->tableauEtapesTotal[36]->getEtapeType()); - qDebug() << "tableauEtapesTotal[36]" << (this->tableauEtapesTotal[36]->getPosition().getX()); - #endif + this->nextStep = this->etapeEnCours; this->etapeEnCours = ((this->tableauEtapesTotal[this->etapeEnCours]->getParent()->getNumero())); @@ -267,6 +270,7 @@ void StrategieV3::updateIntermedaire() if(this->statusStrat == 1) { + qDebug() << "Okay ici"; //On réalise l'action de l'étape - but StrategieV2::addTemporaryAction(tableauEtapesTotal[this->etapeEnCours]->getAction()); } @@ -410,6 +414,8 @@ bool StrategieV3::updateScores() { resteDesChosesAFaire = true; } + qDebug() << "Etape " << i << " Score: " << scoreTypeEtape; + this->tableauEtapesTotal[i]->setScore(scoreTypeEtape); } return resteDesChosesAFaire; -- GitLab