pb perte initialisation variable C++

pb perte initialisation variable C++ - C++ - Programmation

Marsh Posté le 24-01-2005 à 20:36:15    

Bonjour, alors voici mon pb :  
 
 
pDecrypter = new Computer(duplicates)  
un nouvel objet de type Computer est créé  
Computer::Computer(bool dupes):  
Decrypter(dupes), total(0), mySmartString(0)  
 
{  
}  
cela appelle constr Decrypter:ecrypter(bool dupes):  
round(0),  
duplicates (dupes)  
{  
}  
 
et les variables membres  mySmartString et total sont initialisées à 0  
 
Ensuite il ya pDecrypter->Play();  
A ce moment là pdecrypter affiche seulement les variables protected(de la classe DECRYPTER)  
cependant il va bien dans Computer:lay  
if (!mySmartString)  
      mySmartString = new SmartString(duplicates);  
et là je me rends compte avec stupéfaction que mySmartString est rempli avec n'importe quoi!!! et ça me plante tout!! segmentation defaultPouvez vous m'aider et me dire ce qui s'est passé.  
La variable total contient également n'importe quoi  
En fait juste avant la ligne pDecrypter->Play (qui est dans game.cpp), pDecrypter est considéré alors comme un objet de type DECRYPTER avec la definition de DECRYPTER ( c normal qu'il ne soit pas considéré comme computer?)et quand je me debranche dans COMPUTER :: PLAY, alors le pointeur this est considéré comme un objet COMPUTER mais là "smartstring" ET "total" sont initialisés avec n'importe quoi.  
 
J'ai donc appremment un pb de relation entre les classes Computer et Decrypter mais je ne vois pas c equi ne marche pas
Les classes human et computer sont des classes dérivées de Decrypter.
 
Voici le code en totalité:
 
1a) la classe Game

Code :
  1. #ifndef GAME_HPP
  2. #define GAME_HPP
  3. #include "defvals.hpp"
  4. #include "Gues1205.hpp"
  5. #include "SmartString1201.hpp"
  6. class Guess;
  7. class Decrypter;
  8. class Game
  9. {
  10. public:
  11.     Game();
  12.     ~Game()     {}
  13.      void Play();
  14.      static int howManyLetters;
  15.      static int howManyPositions;
  16. private:
  17.      void DisplayTime(int secs);
  18.      bool VerifyComputerChoices();
  19.      bool duplicates;
  20.      Decrypter *  pDecrypter;
  21. };
  22. #endif


1b) l'implémentation de la classe Game

Code :
  1. #include "game1103.hpp"
  2. #include "defvals.hpp"
  3. #include "decrypter1101.hpp"
  4. #include "human1105.hpp"
  5. #include "computer1109.hpp"
  6. #include "SmartString1201.hpp"
  7. #include<time.h>
  8. #include<windows.h>
  9. using namespace std;
  10. char * Accent(const char * mess) {
  11. static char retour [80];
  12. CharToOem (mess,retour);
  13. return retour;
  14.    }
  15. int Game::howManyLetters = 0;
  16. int Game::howManyPositions = 0 ;
  17. Game::Game()
  18. {
  19.    for( ;; )
  20.    {
  21.       // Récupération du choix de l'utilisateur
  22.       // pour le nombre de lettres possible
  23.       while (howManyLetters < minLetters
  24.          || howManyLetters > maxLetters)
  25.       {
  26.         cout << "Nombre de lettres ? (";
  27.         cout << minLetters << "-" << maxLetters << " ) : ";
  28.         cin >> howManyLetters;
  29.         if ( howManyLetters < minLetters
  30.            || howManyLetters > maxLetters)
  31.         {
  32.            cout << "Veuillez saisir un nombre compris entre ";
  33.            cout << minLetters <<" et " << maxLetters <<endl;
  34.         }
  35.       }
  36.       // Récupération du choix de l'utilisateur
  37.       // pour le nombre de positions
  38.       while (howManyPositions < minPos
  39.          || howManyPositions > maxPos)
  40.       {
  41.          cout << "Nombre de positions ? (";
  42.          cout << minPos << "-" << maxPos << " ) : ";
  43.          cin >> howManyPositions;
  44.          if ( howManyPositions < minPos
  45.           ||  howManyPositions > maxPos)
  46.          {
  47.             cout << "Veuillez saisir un nombre de positions compris entre ";
  48.             cout << minPos << " et " << maxPos << endl;
  49.          }
  50.        }
  51.        char choice = ' ';
  52.        while ( choice != 'o' && choice != 'n' )
  53.        {
  54.          cout << "Permettre les doublons (o/n) ? ";
  55.          cin >> choice;
  56.        }
  57.        duplicates = choice == 'o'? true: false;
  58.        if ( ! duplicates
  59.          && howManyPositions > howManyLetters)
  60.        {
  61.           cout << "Impossible de mettre " << howManyLetters << " lettres dans ";
  62.           cout << howManyPositions << " positions sans doublons !\n";
  63.           cout << Accent("Essayez à nouveau ... \n" );
  64.           howManyLetters = 0; howManyPositions = 0 ;
  65.           continue;
  66.        }
  67.        choice = ' ';
  68.        while( choice!= 'h' && choice != 'c' )
  69.        {
  70.          cout << "Qui devine. (H)umain";
  71.          cout << " ou (C)alculateur ? (h/c)? ";
  72.          cin >> choice;
  73.        }
  74.        bool ok = choice == 'h' ?
  75.          true : VerifyComputerChoices();
  76.        if (ok)
  77.        {
  78.            if (choice == 'h')
  79.              pDecrypter = new Human(duplicates);
  80.            else
  81.              pDecrypter = new Computer(duplicates);
  82.            break;
  83.        }
  84.     }
  85. }
  86. void Game::DisplayTime(int totalSeconds)
  87. {
  88.    int totalDays = totalSeconds / SecondsInDay;
  89.     int totalHours = totalSeconds / SecondsInHour;
  90.      int totalMinutes = totalSeconds / SecondsInMinute;
  91.      if ( totalDays > 1)
  92.       cout << totalDays << " jours ! " ;
  93.       else
  94.        if ( totalHours > 1)
  95.       cout << totalHours << " heures ! " ;
  96.       else
  97.        if ( totalMinutes > 1)
  98.       cout << totalMinutes << " minutes . " ;
  99.       else
  100.       cout << totalSeconds << " secondes. " ;
  101. }
  102. void Game::Play()
  103. {
  104. int start = time (NULL );
  105. pDecrypter->Play();
  106. //indique le temps passé
  107. int end = time(NULL );
  108. int totalSeconds = end - start;
  109. cout << "\nTemps total passé, pour ce jeu : ";
  110. DisplayTime(totalSeconds);
  111. cout <<"\n";
  112. howManyLetters = 0;
  113. howManyPositions = 0;
  114. }
  115. bool Game::VerifyComputerChoices()
  116. {
  117.   int totalGuesses = 1;
  118.   if (duplicates)
  119.     for(int i = 0; i < howManyPositions;i++)
  120.        totalGuesses *=howManyLetters;
  121.   else
  122.      for ( int i = howManyLetters; i > howManyLetters - howManyPositions;
  123.              i-- )
  124.          totalGuesses *=i;
  125.   int totalSeconds = totalGuesses/GUESSES_PER_SECOND;
  126.   if (totalSeconds > 2)
  127.   {
  128.    cout << "\n\nVous me demandez de deviner ";
  129.    cout << "parmi ";
  130.    cout << totalGuesses;
  131.    cout << " combinaisons possibles. " ;
  132.    cout << "\nJe peux venir à bout d'environ ";
  133.    cout << GUESSES_PER_SECOND;
  134.    cout << " combinaisons par seconde. ";
  135.    cout << Accent("Si l'énigme est difficile, " );
  136.    cout << "\nune seule proposition peut me prendre plus de ";
  137.    DisplayTime(totalSeconds);
  138.    char confirm = ' ';
  139.    while ( confirm != 'o' && confirm != 'n')
  140.    {
  141.      cout << Accent("\n\nEtes-vous sûr de vouloir continuer (o/n) ? " );
  142.      cin >> confirm;
  143.    }
  144.     if (confirm == 'n')
  145.     {
  146.       howManyLetters = 0 ;
  147.       howManyPositions = 0 ;
  148.       return false;
  149.     }
  150.   }
  151.   else
  152.   {
  153.     cout <<"Choix parmi " << totalGuesses;
  154.     cout << " combinaisons possibles...\n\n";
  155.   }
  156.   return true;
  157. }


 
2a) la classe Computer

Code :
  1. #ifndef COMPUTER_HPP
  2. #define COMPUTER_HPP
  3. #include "SmartString1201.hpp"
  4. #include "decrypter1101.hpp"
  5. class SmartString;
  6. class Computer : public Decrypter
  7. {
  8. public:
  9.    Computer (bool duplicates);
  10.    virtual ~Computer();
  11.    bool HandleFlag(char flag);
  12.    void Play() ;
  13. private:
  14.    void GenerateAGuess();
  15.    bool IsConsistent(vector<char> guess);
  16.    Guess OfferGuess();
  17.    void ShowHelp();
  18.    SmartString * mySmartString;
  19.    int total;
  20. };
  21. #endif


2b) l'implémentation de la classe Computer

Code :
  1. #include "computer1109.hpp"
  2. #include "game1103.hpp"
  3. #include "SmartString1201.hpp"
  4. #include<windows.h>
  5. using namespace std;
  6. char * AccentC(const char * mess) {
  7. static char retour [80];
  8. CharToOem (mess,retour);
  9. return retour;
  10.    }
  11. Computer::Computer(bool dupes):
  12. Decrypter(dupes), total(0), mySmartString(0)
  13. {
  14. }
  15. Computer :: ~Computer()
  16. {
  17. }
  18. void Computer::GenerateAGuess()
  19. {
  20.    bool ok = true;
  21.    int counter = 0;
  22.    int start = time(NULL );
  23.    do
  24.    {
  25.      counter++;
  26.      total++;
  27.      if (counter % 10000 == 00)
  28.        cout << ".";
  29.      ok = mySmartString->GetNext();
  30.      if (!ok)
  31.       {
  32.         cout << "Quelquechose ne va pas !";
  33.         cout << " Recommencez\n";
  34.         round = 0;
  35.         delete mySmartString;
  36.         mySmartString = new SmartString(duplicates);
  37.         ShowHistory();
  38.         cout <<"\n\n";
  39.         history.clear();
  40.         continue;
  41.        }
  42.    } while ( !IsConsistent(mySmartString->GetString()) );
  43.    int end = time(NULL );
  44.    int seconds = end-start;
  45.    cout << "(" << counter;
  46.    cout << AccentC(" chaînes éliminées pour ce tour ; " );
  47.    cout << total << " total.)";
  48.    if (seconds > 1)
  49.       cout << "(" << seconds << " secondes]";
  50.       cout << "\n";
  51. }
  52. // Gestion des indicateurs de l'utilisateur ( -?,-<, etc.)
  53. bool Computer::HandleFlag(char flag)
  54. {
  55.     bool quit =false;
  56.     switch (flag)
  57.     {
  58.          case 's':
  59.         ShowHistory();
  60.         break;
  61.          case '?':
  62.         ShowHelp();
  63.         break;
  64.          case 'q':
  65.         quit = true;
  66.         break;
  67.         default:
  68.         cout << AccentC(  "\nIndicateur inconnu.Ignoré.\n" );
  69.         break;
  70.     }
  71.     return quit ;
  72. }
  73. bool Computer::IsConsistent(vector<char> theGuess)
  74. {
  75.    if (!duplicates)
  76.    {
  77.      for(
  78.         vector<char>::const_iterator it =
  79.                  theGuess.begin();
  80.              it!= theGuess.end();
  81.              it++)
  82.      {
  83.        int HowMany =
  84.            count(theGuess.begin(),theGuess.end(), *it);
  85.            if (HowMany > 1)
  86.            return false;
  87.      }
  88.    }
  89.    bool isValid = true ;
  90.    int correct;
  91.    int position;
  92.    for ( vector<Guess>::const_iterator it=
  93.                      history.begin();
  94.                   it != history.end();
  95.                           it++)
  96.        {
  97.         vector <char> temp = it->GetString();
  98.         correct = 0;
  99.         position = 0;
  100.         for(int i = 0; i < Game::howManyLetters; i++)
  101.           {
  102.             int howManyInGuess =
  103.               count (theGuess.begin(),theGuess.end(),alpha[i]);
  104.             int howManyInAnswer =
  105.               count (temp.begin(),temp.end(),alpha[i]);
  106.             correct += min (howManyInGuess,howManyInAnswer);
  107.            }
  108.          for(int i = 0; i < Game::howManyPositions; i++)
  109.           {
  110.             if ( theGuess[i] = temp[i])
  111.              position ++;
  112.           }
  113.          if ( correct != it->GetScore().first ||
  114.                  position != it->GetScore().second )
  115.              {
  116.                isValid = false;
  117.                break;
  118.              }
  119.        }
  120.        return isValid;
  121. }
  122. Guess Computer::OfferGuess()
  123. {
  124.   vector<char> theGuess =
  125.     mySmartString->GetString();
  126.     round++;
  127.     int numCorrect, numInPosition;
  128.     cout <<"\n";
  129.     Display(theGuess);
  130.     cout << "Essai " << round << ". ";
  131.     cout << "Veuillez donner le score. \t";
  132.     cout << "Combien sont correctes ? ";
  133.     cin >> numCorrect;
  134.     cout << AccentC("\t\t\tVombien sont bien placées ?: " );
  135.     cin >> numInPosition;
  136.     Guess thisGuess(theGuess, numCorrect, numInPosition);
  137.     return thisGuess;
  138. }
  139. void Computer::Play()
  140. {
  141.    if (!mySmartString)
  142.       mySmartString = new SmartString(duplicates);
  143.    vector<char> theGuess;
  144.    history.clear();
  145.    bool deletedCharacters = false;
  146.    for (;;)
  147.    {
  148.       Guess theGuess = OfferGuess();
  149.       history.push_back(theGuess);
  150.        if ( theGuess.GetScore().second ==
  151.             Game::howManyPositions)
  152.            break;
  153.        if (
  154.             ! mySmartString->CanEliminateCharacters(theGuess)  ||
  155.             ! IsConsistent(mySmartString->GetString())
  156.            )
  157.               GenerateAGuess();
  158.     };
  159. }
  160. // Le joueur a entré -?
  161. void Computer::ShowHelp()
  162. {
  163.    cout << "\t-h Indice\n\t-s Afficher l'historique \n";
  164.    cout << "\t-? Aide\n\t-q Quitter\n" << endl;
  165. }


 
 
3a) la classe Human

Code :
  1. #ifndef HUMAN_HPP
  2. #define HUMAN_HPP
  3. #include "decrypter1101.hpp"
  4. class Human : public Decrypter
  5. {
  6. public:
  7.    Human (bool duplicates);
  8.    virtual ~Human();
  9.   vector<char> GetSolution() const;
  10.   bool HandleFlag(char flag);
  11.   bool IsValid (char c) const;
  12.   void Play() ;
  13.   void Score( vector<char> thisGuess, int & correct, int & position);
  14. private:
  15.    void ShowHelp();
  16.    void ShowHint();
  17.    int hintCtr;
  18.    vector<char> solution;
  19. };
  20. #endif


3b) l'implémentation de la classe Human

Code :
  1. #include "human1105.hpp"
  2. #include "game1103.hpp"
  3. #include<string>
  4. #include<windows.h>
  5. using namespace std;
  6. char * AccentH(const char * mess) {
  7. static char retour [80];
  8. CharToOem (mess,retour);
  9. return retour;
  10.    }
  11. Human::Human(bool dupes):
  12. Decrypter(dupes), hintCtr(0)
  13. {
  14. }
  15. Human :: ~Human()
  16. {
  17. }
  18. vector <char> Human::GetSolution() const
  19. {
  20. return solution;
  21. }
  22. // Gestion des indicateurs de l'utilisateur ( -?,-<, etc.)
  23. bool Human::HandleFlag(char flag)
  24. {
  25.     bool quit =false;
  26.     switch (flag)
  27.     {
  28.       case 'h':
  29.         ShowHint();
  30.         break;
  31.          case 's':
  32.         ShowHistory();
  33.         break;
  34.          case '?':
  35.         ShowHelp();
  36.         break;
  37.          case '!':
  38.         Display(GetSolution());
  39.         break;
  40.          case 'q':
  41.         quit = true;
  42.         break;
  43.         default:
  44.         cout << AccentH(  "\nIndicateur inconnu.Ignoré.\n" );
  45.         break;
  46.     }
  47.     return quit ;
  48. }
  49. bool Human::IsValid(char c) const
  50. {
  51. bool IsValid = false;
  52. for (int i = 0 ; i < Game::howManyLetters ; i++)
  53.         if (alpha[i]== c)
  54.         IsValid = true;
  55.   return IsValid;
  56. }
  57. void Human::Play()
  58. {
  59. vector<char> thisGuess;
  60. int correct = 0;
  61. int position = 0;
  62. bool quit = false;
  63. round ++;
  64. // alimentation du tableau solution
  65.    srand( (unsigned) time (NULL) );
  66.    for ( int i = 0 ; i < Game::howManyPositions;)
  67.        { int nextValue = rand () % (Game::howManyLetters);
  68.          char theChar = alpha[nextValue];
  69.          // lettre déjà existante?
  70.           if ( ! duplicates && i > 0 )
  71.           {
  72.             vector<char>::iterator where =
  73.               find(solution.begin(), solution.end(), theChar);
  74.               if (where != solution.end())
  75.                 continue;
  76.           }
  77.           solution.push_back(theChar);
  78.          i++;
  79.        }
  80.   while ( position < Game::howManyPositions)
  81.    {
  82.      thisGuess.clear();
  83.      string guess;
  84.      cout << "\nEssai " << round << ". Entrez -? ou ";
  85.      cout << Game::howManyPositions << " lettres entre ";
  86.      cout << alpha[0] << " et " << alpha[Game::howManyLetters-1] << " : ";
  87.      cin >> guess ;
  88.      if (guess[0] == '-')//c'est un indicateur
  89.       {
  90.         quit = HandleFlag(guess[1]);
  91.         if(quit)
  92.           break;
  93.           continue;
  94.       }
  95.      if ( guess.length() < Game::howManyPositions)
  96.       {
  97.         cout << "\n ** Veuillez entrer exactement " ;
  98.         cout << Game::howManyPositions << " lettres . ** \n";
  99.         continue;
  100.       }
  101.      bool lineIsValid = true;
  102.      for (int i = 0; i < Game::howManyPositions; i++)
  103.          {
  104.           lineIsValid = IsValid(guess[i]);
  105.           if ( ! lineIsValid)
  106.            break;
  107.          }
  108.      //création de la proposition pour l'affichage
  109.      if (lineIsValid)
  110.        for ( int i =0; i < Game::howManyPositions; i++)
  111.            thisGuess.push_back(guess[i]);
  112.      else
  113.         {
  114.          cout << "Veuillez entre uniquement des lettres entre ";
  115.          cout << alpha[0] << " et " << alpha[Game::howManyLetters-1] << "\n";
  116.          continue;
  117.         }
  118.        round++ ;
  119.      cout << "\nVotre proposition : ";
  120.      Display(thisGuess);
  121.      //calcul et affichage
  122.      Score(thisGuess,correct,position);
  123.      cout << "\t\t" << correct  << " correcte(s), ";
  124.      cout << position << AccentH( " bien placee(s) \n" );
  125.      // création d'un enregistrement et sauvegarde dans le vector history
  126.      Guess thisRound(thisGuess,correct,position);
  127.      history.push_back(thisRound);
  128.   }
  129.   if(!quit)
  130.   {
  131.     cout << "\nFelicitations ! Il vous a fallu ";
  132.     if (round <= 6)
  133.       cout <<  " seulement " ;
  134.       if (round-1 == 1)
  135.         cout << "un essai ! \n";
  136.     else
  137.       cout << round-1 << " essais. \n";
  138.    }
  139. }
  140. void Human::Score( vector<char> thisGuess, int &  correct, int & position)
  141.   {
  142.            correct  = 0;
  143.            position = 0;
  144.            // pour chaque lettre possible,
  145.            // combien sont dans la réponse et la proposition
  146.            for ( int i = 0; i < Game::howManyLetters; i++)
  147.              {
  148.              int  howManyinGuess = count ( thisGuess.begin(), thisGuess.end(),
  149.                                              alpha[i]) ;
  150.               int  howManyinAnswer = count(solution.begin(), solution.end(),
  151.                                              alpha [i]);
  152.               correct+= min(howManyinGuess,howManyinAnswer);
  153.               }
  154.             //Pour chaque proposition
  155.             // combien sont dans la solution
  156.             for ( int j = 0; j < Game::howManyPositions ;  j++)
  157.                 { if (thisGuess[j] == solution[j])
  158.                     position ++;
  159.                  }
  160.    }
  161. // Joueur humain, révéler cahque lettre une par une
  162. void Human::ShowHint()
  163. {
  164.    if (hintCtr<Game::howManyPositions)
  165.      {
  166.       cout << "\nIndice!! Position" << hintCtr+1;
  167.       cout <<": " << solution[hintCtr] << endl;
  168.       hintCtr++;
  169.      }
  170.   }
  171. //Si le joueur entre -?
  172. void Human::ShowHelp()
  173. {
  174.    cout << "\t-h Indice\n\t-s Afficher l'historique \n";
  175.    cout << "\t-? Aide\n\t-q Quitter\n" << endl;
  176. }


 
 
4a) la classe Decrypter

Code :
  1. #ifndef DECRYP_HPP
  2. #define DECRYP_HPP
  3. #include "defvals.hpp"
  4. #include "Gues1205.hpp"
  5. class Decrypter
  6. {
  7. public:
  8.    Decrypter(bool duplicates);
  9.    virtual ~Decrypter();
  10.   void Display( vector<char> charVec) const;
  11.   virtual bool HandleFlag(char flag) = 0 ;
  12.   virtual void Play() = 0 ;
  13.   virtual void ShowHelp() = 0;
  14.   void ShowHistory();
  15. protected:
  16.    bool duplicates;
  17.    vector<Guess> history;
  18.    int round;
  19. };
  20. #endif


4b) l'implémentation de la classe Decrypter

Code :
  1. #include "decrypter1101.hpp"
  2. Decrypter::Decrypter(bool dupes):
  3. round(0),
  4. duplicates (dupes)
  5. {
  6. }
  7. Decrypter::~Decrypter()
  8. {
  9. }
  10. void Decrypter::Display(vector<char> charVec) const
  11. {
  12.   copy(
  13.    charVec.begin(),
  14.    charVec.end(),
  15.    ostream_iterator<char>(cout," " ));
  16. }
  17. void Decrypter::ShowHistory()
  18. {
  19.     for (
  20.          vector<Guess>::const_iterator it = history.begin();
  21.          it != history.end();
  22.          it++)
  23.          {
  24.           it->Display();
  25.          }
  26. }


 
 
5a) la classe SmartSrting

Code :
  1. #ifndef SMARTSTRING_HPP
  2. #define SMARTSTRING_HPP
  3. #include "defvals.hpp"
  4. #include "smartchr1203.hpp"
  5. class Guess;
  6. class SmartString
  7. {
  8. public:
  9.    SmartString(bool dupes);
  10.    virtual ~SmartString();
  11.    bool CanEliminateCharacters(const Guess& theGuess);
  12.    bool GetNext();
  13.    vector<char> GetString();
  14.    bool RemoveCurrentCharacters();
  15.    bool RemoveCurrentCharactersInEveryPosition();
  16. private:
  17.    void ForceCharacters(const Guess& theGuess);
  18.    int CountForcedInGuess(const Guess& theGuess);
  19.    int CountUniqueLettersInGuess(const Guess & theGuess);
  20.    bool In(vector<char> vec, char target) const;
  21.    vector <char> deadCharacters;
  22.    bool duplicates;
  23.    vector<char> forcedCharacters;
  24.    vector<SmartChar> myString;
  25. };
  26. #endif


5b) l'implémentation de la classe SmartString

Code :
  1. #include "Gues1205.hpp"
  2. #include "game1103.hpp"
  3. #include "SmartString1201.hpp"
  4. #include<windows.h>
  5. using namespace std;
  6. SmartString::SmartString(bool dupes):
  7. duplicates(dupes)
  8. {
  9.    for (int i = 0; i < Game::howManyPositions; i++)
  10.      {
  11.        int j;
  12.        if (duplicates)
  13.         j = 0 ;
  14.        else
  15.         j = i;
  16.         SmartChar theChar(j);
  17.         myString.push_back(theChar);
  18.      }
  19. }
  20. SmartString :: ~SmartString()
  21. {
  22. }
  23. vector<char> SmartString::GetString()
  24. {
  25.   vector<char> outString;
  26.   for (vector<SmartChar>::iterator it = myString.begin();
  27.             it != myString.end();
  28.                     it ++)
  29.        {
  30.          char theChar = it->GetChar();
  31.          outString.push_back(theChar);
  32.        }
  33.   return outString;
  34. }
  35. bool SmartString::GetNext()
  36. {
  37.   vector<char> outString;
  38.   vector<SmartChar>::reverse_iterator rit;
  39.   rit = myString.rbegin();
  40.   bool rollover = rit->Increment();
  41.   while(rollover)
  42.   {
  43.     rit ++;
  44.     if (rit == myString.rend())
  45.     return false;
  46.     else
  47.     {
  48.       rollover = rit->Increment();
  49.     }
  50.   }
  51.   return true;
  52. }
  53. // enlève le character se trouvant actuellment
  54. // à une certaine position
  55. bool SmartString::RemoveCurrentCharacters()
  56. {
  57. char theChar;
  58. bool anyDeleted = false;
  59. for (vector<SmartChar>::iterator it = myString.begin();
  60.             it != myString.end();
  61.                     it ++)
  62.        {
  63.          theChar = it->GetChar();
  64.          if (! In(forcedCharacters, theChar) )
  65.          {
  66.            theChar = it->RemoveCurrent();
  67.            // "deadcharacters" ( caractères morts) évite la prise
  68.            // en compte de caractères déjà exclus
  69.            if ( ! In(deadCharacters, theChar) )
  70.            {
  71.              deadCharacters.push_back(theChar);
  72.              cout << "Elimination de " << theChar;
  73.              cout << " de la position actuelle" << endl;
  74.              anyDeleted = true;
  75.            }
  76.           }
  77.        }
  78.        return anyDeleted;
  79. }
  80. // enlève de n'importe quelle position le caractère
  81. // se trouvant à une certaine position
  82. bool SmartString::RemoveCurrentCharactersInEveryPosition()
  83. {
  84. char theChar;
  85. bool anyDeleted = false;
  86. vector<char> currentGuess;
  87. for (vector<SmartChar>::iterator it = myString.begin();
  88.             it != myString.end();
  89.                     it ++)
  90.        {
  91.          currentGuess.push_back(it->GetChar());
  92.        }
  93. for (vector<char>::iterator itc = currentGuess.begin();
  94.             itc != currentGuess.end();
  95.                     itc ++)
  96.        {
  97.          theChar = *itc;
  98.          if (! In(forcedCharacters, theChar) )
  99.          {
  100.             for (vector<SmartChar>::iterator it2 = myString.begin();
  101.             it2 != myString.end();
  102.                     it2 ++)
  103.             {
  104.               it2->Remove(theChar);
  105.               if ( ! In(deadCharacters, theChar) )
  106.                {
  107.                  deadCharacters.push_back(theChar);
  108.                  cout << "Elimination de " << theChar;
  109.                  anyDeleted = true;
  110.                }
  111.             }
  112.          }
  113.        }
  114.        return anyDeleted;
  115. }
  116. bool SmartString::CanEliminateCharacters(const Guess &theGuess)
  117. {
  118. bool anyDeleted = false;
  119. ForceCharacters(theGuess);
  120. int forcedInAnswer = CountForcedInGuess(theGuess);
  121. int overall = theGuess.GetScore().first;
  122. int inPos = theGuess.GetScore().second;
  123. if (overall == 0 || overall == forcedInAnswer)
  124. {
  125.    anyDeleted = RemoveCurrentCharactersInEveryPosition();
  126.    return anyDeleted; // nous avons effectivement éliminé des caractères
  127. }
  128. if (inPos == 0 )
  129. {
  130.    anyDeleted = RemoveCurrentCharacters();
  131.    return anyDeleted; // nous avons effectivement éliminé des caractères
  132. }
  133. return false;
  134. }
  135. void SmartString::ForceCharacters(const Guess &theGuess)
  136. {
  137. int numDifferentLetters =
  138.     CountUniqueLettersInGuess (theGuess);
  139. int score = theGuess.GetScore().first;
  140. if ( score >= numDifferentLetters)
  141.   {
  142.     vector <char> theString = theGuess.GetString();
  143.     for (vector<char>::const_iterator it = theString.begin();
  144.             it != theString.end();
  145.                     it ++)
  146.         {
  147.          if (In(forcedCharacters, *it) )
  148.             forcedCharacters.push_back(*it);
  149.         }
  150.   }
  151. }
  152. int SmartString::CountUniqueLettersInGuess(const Guess &theGuess)
  153. {
  154. vector<char> temp;
  155. vector <char> theString = theGuess.GetString();
  156. for (vector<char>::const_iterator it = theString.begin();
  157.             it != theString.end();
  158.                     it ++)
  159.          {
  160.            if (! In(temp, *it) )
  161.            temp.push_back(*it);
  162.          }
  163.        // temp contient maintenant toues les lettres uniques
  164.        return temp.size();
  165. }
  166. int SmartString::CountForcedInGuess(const Guess &theGuess)
  167. {
  168. int howManyForcedInGuess = 0;
  169. vector <char> theString = theGuess.GetString();
  170. for (vector<char>::const_iterator it = theString.begin();
  171.             it != theString.end();
  172.                     it ++)
  173.         {
  174.            if (In(forcedCharacters, *it) )
  175.               howManyForcedInGuess ++;
  176.         }
  177.        return howManyForcedInGuess;
  178. }
  179. bool SmartString::In(vector<char> vec , char target) const
  180. {
  181.      vector<char>::iterator where =
  182.                       find(vec.begin(), vec.end(), target);
  183.             return where != vec.end();
  184. }


 
 
6a) la classe SmartChar

Code :
  1. #ifndef SMARTCHAR_HPP
  2. #define SMARTCHAR_HPP
  3. #include "defvals.hpp"
  4. class SmartChar
  5. {
  6. public:
  7.    SmartChar(int letter = 0);
  8.    virtual ~SmartChar();
  9.    char GetChar() const;
  10.    bool Increment();
  11.    char RemoveCurrent();
  12.    bool Remove(char c);
  13. private:
  14.    int myChar;
  15.    vector<char> myCharacters;
  16. };
  17. #endif


6b) l'implémentation de la classe SmartChar

Code :
  1. #include "game1103.hpp"
  2. #include "smartchr1203.hpp"
  3. #include<windows.h>
  4. using namespace std;
  5. char * AccentSC(const char * mess) {
  6. static char retour [80];
  7. CharToOem (mess,retour);
  8. return retour;
  9.    }
  10. SmartChar::SmartChar(int letter):
  11. myChar(letter)
  12. {
  13.    for (int i = 0; i < Game::howManyLetters; i++)
  14.      {
  15.        myCharacters.push_back(alpha[i]);
  16.      }
  17. }
  18. SmartChar :: ~SmartChar()
  19. {
  20. }
  21. char SmartChar::GetChar() const
  22. {
  23.   return myCharacters[myChar];
  24. }
  25. bool SmartChar::Increment()
  26. {
  27.   if (++myChar >= myCharacters.size() )
  28.   {
  29.     myChar = 0;
  30.     return true;
  31.   }
  32.   return false;
  33. }
  34. char SmartChar::RemoveCurrent()
  35. {
  36.   char theChar = ' ';
  37.   if (myCharacters.size() > 1)
  38.   {
  39.     theChar = GetChar();
  40.     myCharacters.erase(myCharacters.begin() +myChar);
  41.     while ( myChar >= myCharacters.size() )
  42.       myChar--;
  43.    }
  44.   return theChar;
  45. }
  46. bool SmartChar::Remove (char theChar)
  47. {
  48.   if (myCharacters.size() > 1)
  49.       {
  50.         vector<char>::iterator where =
  51.               find ( myCharacters.begin(), myCharacters.end(), theChar);
  52.             if ( where != myCharacters.end())
  53.                 myCharacters.erase(where);
  54.             return true;
  55.        }
  56.        return false;
  57. }


 
 
7a) la classe Guess

Code :
  1. #ifndef GUESS_HPP
  2. #define GUESS_HPP
  3. #include <vector>
  4. #include "defvals.hpp"
  5. using namespace std ;
  6. class Guess
  7. {
  8. public:
  9. Guess();
  10. Guess(vector<char> guess , int howManyRight, int howManyInPosition);
  11. ~Guess(){};
  12. pair<int,int> GetScore() const {return score;}
  13. vector<char>  GetString() const {return myString;}
  14. void Display() const;
  15. private:
  16. vector<char>  myString ;
  17. pair<int,int> score;
  18. };
  19. #endif


7b) l'implémentation de la classe Guess

Code :
  1. #include "Gues1205.hpp"
  2. Guess::Guess(vector<char>guess, int howManyRight, int howManyInPosition):
  3.     myString(guess),
  4.     score(howManyRight, howManyInPosition)
  5. {
  6. }
  7. void Guess::Display()  const
  8. {
  9. copy ( myString.begin(),
  10. myString.end(),
  11. ostream_iterator<char>(cout, " " ) );
  12. cout << "\t";
  13. cout << score.first;
  14. cout << " correcte(s), ";
  15. cout << score.second;
  16. cout << " bien placee(s) \n";
  17. }


 
 
8a) la classe defvals

Code :
  1. #ifndef DEFVALS_HPP
  2. #define DEFVALS_HPP
  3.   #include <iostream>
  4.   #include <vector>
  5.   #include <iterator>
  6.   #include <algorithm>
  7.   #include <time.h>
  8.   #include <utility>
  9.    using namespace std;
  10.    const char alpha[]= "abcdefghijklmnopqrstuvwxyz";
  11.    const int minPos = 2;
  12.    const int maxPos = 10;
  13.    const int minLetters = 2;
  14.    const int maxLetters = 26;
  15.    const int SecondsInMinute = 60;
  16.    const int SecondsInHour = SecondsInMinute * 60;
  17.    const int SecondsInDay = SecondsInHour * 24;
  18.    const int GUESSES_PER_SECOND = 10000;
  19.    const int szInt = sizeof(int);
  20.    const int szChar = sizeof(char);
  21.    const int szBool = sizeof(bool);
  22. #endif


9b) le programme Main  

Code :
  1. #include <iostream>
  2. # include <windows.h>
  3. //programme gestionnaire pour montrer comment créer un jeu et démontre
  4. // et comment l'ordinateur devine la solution
  5. #include "defvals.hpp"
  6. #include "game1103.hpp"
  7. #include "Gues1205.hpp"
  8. using namespace std;
  9. char * AccentD(const char * mess) {
  10. static char retour [80];
  11. CharToOem (mess,retour);
  12. return retour;
  13.    }
  14. int main()
  15. {
  16. cout << "Decryptix. (c)Copyright 2000 Liberty ";
  17. cout << "Associates, Inc. Version 11 \n\n " << endl;
  18. cout << AccentD("Decryptix.  (c) Copyright 2000 Liberty " );
  19. cout << AccentD("Associates, Inc.  Version 0.2\n " )<<     endl;
  20. cout << AccentD("Il y a deux façons de jouer à Decryptix : " );
  21. cout << AccentD("en devinant un modèle créé par l'ordinateur, " );
  22. cout << AccentD("ou en laissant l'ordinateur deviner le vôtre. \n" );
  23. cout << AccentD("Si vous devinez, l'ordinateur va penser à une\n" );
  24. cout << AccentD("suite de lettres (e.g., abcde).\n\n" );
  25. cout << AccentD("A chaque tour, vous faites une proposition et\n" );
  26. cout << AccentD("l'ordinateur vous dit combien de lettres sont \n" );
  27. cout << AccentD("correctes, et combien parmi celles-ci occupent\n" );
  28. cout << AccentD("la position exacte dans le modèle.\n\n" );
  29. cout << AccentD("Le but est de décoder l'énigme aussi rapidement \n" );
  30. cout << AccentD("que possible. Vous décidez combien de lettres \n" );
  31. cout << AccentD("peuvent êre utilisées et le nombre de positions\n" );
  32. cout << AccentD("(e.g., 5 lettres possibles dans 4 positions) \n" );
  33. cout << AccentD("ainsi que si le modèle peut ou non contenir \n" );
  34. cout << AccentD("des lettres en double (e.g., aabcd).\n\n" );
  35. cout << AccentD("Si l'ordinateur devine, vous pensez à une suite de\n" );
  36. cout << AccentD("lettres et donnez le score de chaque réponse.\n\n" )
  37.                <<     endl;
  38. bool playAgain = true;
  39. while ( playAgain )
  40. {
  41. char choice = ' ';
  42. Game * g = new Game;
  43. g->Play();
  44. /* cout << "\nLa reponse : ";
  45. g->Display(g->GetSolution());
  46. cout << "\n\n" << endl;
  47. */
  48. delete g;
  49. while ( choice != 'o' && choice != 'n' )
  50. {
  51.    cout << "\nRejouez (o/n) ? : ";
  52.    cin >> choice;
  53.   }
  54.   playAgain = choice == 'o'? true: false;
  55. }
  56. system ( "PAUSE" );
  57. return 0;
  58. }


 
 
Je vous remercie pour votre aide

Reply

Marsh Posté le 24-01-2005 à 20:36:15   

Reply

Marsh Posté le 24-01-2005 à 21:11:32    

tu plaisantes là ?

Reply

Marsh Posté le 24-01-2005 à 21:27:44    

juste avec la molette, j'ai mis 32 secondes et des poussières pour atteindre la fin du post :o, qui dit mieux ?

Reply

Marsh Posté le 24-01-2005 à 21:59:40    

Je vais prendre une semaine de vacances et je vais m'en occuper [:dawa]

Reply

Marsh Posté le 24-01-2005 à 21:59:44    

effectivement, y doit y avoir un pb quelquepart

Reply

Marsh Posté le 24-01-2005 à 22:00:24    

[:rofl2]

Reply

Marsh Posté le 24-01-2005 à 22:03:15    

J'ai trouvé !
 
C'est dans ta boucle Do {...} while [:dawa]  
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 [:da_s_monk]

Reply

Marsh Posté le 24-01-2005 à 22:05:04    

++fab a écrit :

juste avec la molette, j'ai mis 32 secondes et des poussières pour atteindre la fin du post :o, qui dit mieux ?


MIEUX [:zytrayaisse]  
 
À la molette uniquement, 15s ! [:uriel]  
(mais j'ai mal à l'index maintenant :cry: )


Message édité par masklinn le 24-01-2005 à 22:06:56

---------------
Stick a parrot in a Call of Duty lobby, and you're gonna get a racist parrot. — Cody
Reply

Marsh Posté le 24-01-2005 à 22:07:13    

je crois qu'il te manque une parenthèse ! [:dawa]

Reply

Marsh Posté le 24-01-2005 à 22:10:31    

stiffler a écrit :

je crois qu'il te manque une parenthèse ! [:dawa]


 :non:  
une accolade [:aloy]

Reply

Marsh Posté le 24-01-2005 à 22:10:31   

Reply

Marsh Posté le 24-01-2005 à 22:10:48    

Masklinn a écrit :

MIEUX [:zytrayaisse]  
 
À la molette uniquement, 15s ! [:uriel]  
(mais j'ai mal à l'index maintenant :cry: )


 
t'étais accompagné d'un huissier ? :lol:

Reply

Marsh Posté le 24-01-2005 à 22:11:05    

Je t'aide si tu m'aide ! [:dawa]
 
 
 
 
 
 
 
Mon arbre binaire déconne , je sais pas pourquoi ? [:opus dei]
 

Code :
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #define TAILLEMAXASC 100
  5. #define M 12
  6. #define N 8
  7. typedef struct {
  8.   int x;
  9.   int y;
  10. } Coordonnees;
  11. typedef struct {
  12.   int M_Est;
  13.   int M_Sud;
  14.   int valeur;
  15. } Case_labyrinthe;
  16. typedef struct {
  17.   int valeur;
  18.   char provenance;
  19.   struct Arbre_chemins *Dir_N;
  20.   struct Arbre_chemins *Dir_E;
  21.   struct Arbre_chemins *Dir_S;
  22.   struct Arbre_chemins *Dir_O;
  23. } Arbre_chemins;
  24. Case_labyrinthe construction_labyrinthe(Case_labyrinthe
  25.     *tableau_labyrinthe[M][N],int
  26.     xcase_fin, int ycase_fin)
  27. {
  28.   /*declaration*/
  29.   int hauteur;
  30.   int longueur;
  31.   /*corps*/
  32.   for (hauteur = 0 ; hauteur < N ; hauteur++)
  33.     {
  34.       tableau_labyrinthe[M-1][hauteur] = (Case_labyrinthe *)calloc(1,sizeof(Case_labyrinthe));
  35.       tableau_labyrinthe[M-1][hauteur]->M_Sud = rand()%2;
  36.       tableau_labyrinthe[M-1][hauteur]->M_Est = 0;
  37.       tableau_labyrinthe[M-1][hauteur]->valeur = 0;
  38.     }
  39.  
  40.   for (longueur = 0 ; longueur < M ; longueur++)
  41.     {
  42.       tableau_labyrinthe[longueur][N-1] = (Case_labyrinthe *)calloc(1,sizeof(Case_labyrinthe));
  43.       tableau_labyrinthe[longueur][N-1]->M_Est = rand()%2;
  44.       tableau_labyrinthe[longueur][N-1]->M_Sud = 0;
  45.       tableau_labyrinthe[longueur][N-1]->valeur = 0;
  46.     }
  47.  
  48.   for (longueur = 0 ; longueur < (M-1) ; longueur++)
  49.     {
  50.       for (hauteur = 0; hauteur < (N-1) ; hauteur++)
  51. {
  52.   tableau_labyrinthe[longueur][hauteur] = (Case_labyrinthe
  53.         *)calloc(1,sizeof(Case_labyrinthe));
  54.   tableau_labyrinthe[longueur][hauteur]->M_Est = rand()%2;;
  55.   tableau_labyrinthe[longueur][hauteur]->M_Sud = rand()%2;
  56.   tableau_labyrinthe[longueur][hauteur]->valeur = 0;
  57. }
  58.     }
  59.   tableau_labyrinthe[M-1][N-1] = (Case_labyrinthe *)calloc(1,sizeof(Case_labyrinthe));
  60.   tableau_labyrinthe[M-1][N-1]->M_Est = 0;
  61.   tableau_labyrinthe[M-1][N-1]->M_Sud = 0;
  62.   tableau_labyrinthe[xcase_fin][ycase_fin]->valeur = -1;
  63.   return(*tableau_labyrinthe[M][N]);
  64. }
  65. void tracer_tableau(Case_labyrinthe *tableau_labyrinthe[M][N],Coordonnees
  66.      tab_ascendant[TAILLEMAXASC],int xcase_fin,int ycase_fin)
  67. {
  68. /*declaration*/
  69.   int hauteur;
  70.   int longueur;
  71.   int dedouble;
  72.   int num_parcours;
  73.   int compteur;
  74.   /* initialisation */
  75.   dedouble = 0;
  76.   num_parcours = 0;
  77.   /*corps*/
  78.    printf(" " );
  79.   for (longueur=1;longueur<M;longueur++)
  80.    {
  81.      printf("___" );
  82.    }
  83.   printf("__" );
  84.   printf("\n" );
  85.   for(hauteur = 0; hauteur < N ; hauteur++)
  86.     {
  87.       for (dedouble = 0; dedouble <2 ; dedouble++)
  88. {
  89.   for (longueur = 0; longueur < M ; longueur++)
  90.     {
  91.       if ((tableau_labyrinthe[longueur][hauteur]->M_Est == 0) &&
  92.    (tableau_labyrinthe[longueur][hauteur]->M_Sud == 0))
  93.  {
  94.    if (dedouble ==0)
  95.      {
  96.        if ((longueur == tab_ascendant[0].x) && (hauteur ==
  97.              tab_ascendant[0].y))
  98.   {
  99.     if (longueur == (M-1))
  100.       printf(" @|\n" );
  101.     else if (longueur == 0)
  102.       printf("| @|" );
  103.     else
  104.       printf(" @|" );
  105.   }
  106.        else if ((longueur == xcase_fin) && (hauteur == ycase_fin))
  107.   {
  108.     if (longueur == (M-1))
  109.       printf(" %c |\n",165);
  110.     else if (longueur == 0)
  111.       printf("| %c|",165);
  112.     else
  113.       printf(" %c|",165);
  114.   }
  115.        else
  116.   {
  117.     if (longueur == (M-1))
  118.   printf("  |\n" );
  119.        else if (longueur == 0)
  120.   printf("|  |" );
  121.        else
  122.   printf("  |" );
  123.   }
  124.       
  125.      }
  126.    if (dedouble ==1)
  127.      {
  128.        if (longueur == (M-1))
  129.   printf("__|\n" );
  130.        else if (longueur == 0)
  131.   printf("|__|" );
  132.        else
  133.   printf("__|" );
  134.      }
  135.  }
  136.       else if ((tableau_labyrinthe[longueur][hauteur]->M_Est == 0) &&
  137.         (tableau_labyrinthe[longueur][hauteur]->M_Sud == 1))
  138.  {
  139.    if (dedouble ==0)
  140.      {
  141.        if ((longueur == tab_ascendant[0].x) && (hauteur ==
  142.              tab_ascendant[0].y))
  143.   {
  144.     if (longueur == (M-1))
  145.       printf(" @|\n" );
  146.     else if (longueur == 0)
  147.       printf("| @|" );
  148.     else
  149.       printf(" @|" );
  150.   }
  151.        else if ((longueur == xcase_fin) && (hauteur == ycase_fin))
  152.   {
  153.     if (longueur == (M-1))
  154.       printf(" %c |\n",165);
  155.     else if (longueur == 0)
  156.       printf("| %c|",165);
  157.     else
  158.       printf(" %c|",165);
  159.   }
  160.        else
  161.   {if (longueur == (M-1))
  162.     printf("  |\n" );
  163.   else if (longueur == 0)
  164.     printf("|  |" );
  165.   else
  166.     printf("  |" );
  167.   }
  168.      }
  169.    if (dedouble == 1)
  170.      {
  171.        if (dedouble ==1) if (longueur == (M-1))
  172.   printf("  |\n" );
  173.        else if (longueur == 0)
  174.   printf("|  |" );
  175.        else
  176.   printf("  |" );
  177.      }
  178.  }
  179.       else if ((tableau_labyrinthe[longueur][hauteur]->M_Est == 1) &&
  180.         (tableau_labyrinthe[longueur][hauteur]->M_Sud == 0))
  181.  {
  182.    if (dedouble ==0)
  183.      {
  184.        if ((longueur == tab_ascendant[0].x) && (hauteur ==
  185.              tab_ascendant[0].y))
  186.   {
  187.     if (longueur == (M-1))
  188.       printf(" @|\n" );
  189.     else if (longueur == 0)
  190.       printf("| @ " );
  191.     else
  192.       printf(" @ " );
  193.   }
  194.        else if ((longueur == xcase_fin) && (hauteur == ycase_fin))
  195.   {
  196.     if (longueur == (M-1))
  197.       printf(" %c |\n",165);
  198.     else if (longueur == 0)
  199.       printf("| %c ",165);
  200.     else
  201.       printf(" %c ",165);
  202.   }
  203.        else
  204.   {
  205.     if (longueur == (M-1))
  206.       printf("   |\n" );
  207.     else if (longueur == 0)
  208.       printf("|   " );
  209.     else
  210.       printf("   " );
  211.   }
  212.      }
  213.    if (dedouble == 1)
  214.      {
  215.        if (longueur == (M-1))
  216.   printf("___\n" );
  217.        else if (longueur == 0)
  218.   printf("|___" );
  219.        else
  220.   printf("___" );
  221.      }
  222.  }
  223.       else if ((tableau_labyrinthe[longueur][hauteur]->M_Est == 1) &&
  224.         (tableau_labyrinthe[longueur][hauteur]->M_Sud == 1))
  225.  {
  226.     if (dedouble ==0)
  227.      {
  228.        if ((longueur == tab_ascendant[0].x) && (hauteur ==
  229.              tab_ascendant[0].y))
  230.   {
  231.     if (longueur == (M-1))
  232.       printf(" @|\n" );
  233.     else if (longueur == 0)
  234.       printf("| @ " );
  235.     else
  236.       printf(" @ " );
  237.   }
  238.        else if ((longueur == xcase_fin) && (hauteur == ycase_fin))
  239.   {
  240.     if (longueur == (M-1))
  241.       printf(" %c |\n",165);
  242.     else if (longueur == 0)
  243.       printf("| %c ",165);
  244.     else
  245.       printf(" %c ",165);
  246.   }
  247.        else
  248.   {
  249.     if (longueur == (M-1))
  250.       printf("   |\n" );
  251.     else if (longueur == 0)
  252.       printf("|   " );
  253.     else
  254.       printf("   " );
  255.   }
  256.      }
  257.     if (dedouble ==1 )
  258.       {
  259.         if (longueur == (M-1))
  260.    printf("   \n" );
  261.         else if (longueur == 0)
  262.    printf("|   " );
  263.         else
  264.    printf("   " );
  265.       }
  266.  }
  267.     }
  268. }
  269.     }
  270.     
  271. }
  272. Coordonnees construire_arbre(Arbre_chemins *racine,Case_labyrinthe *tableau_labyrinthe[M][N],Coordonnees tableau_chemin_plus_court[TAILLEMAXASC],Coordonnees tab_ascendant[TAILLEMAXASC],int valeur_case,char
  273.        provenance_case,int cpt,int i ,int j)
  274. {
  275.   /*declaration*/
  276.   Arbre_chemins *DN;
  277.   Arbre_chemins *DE;
  278.   Arbre_chemins *DS;
  279.   Arbre_chemins *DO;
  280.   int cpt_int;
  281.   int verif_ascendant;
  282.   int chemin_le_plus_court;
  283.   /*initialisation*/
  284.  
  285.   chemin_le_plus_court = TAILLEMAXASC;
  286.  
  287.   /*corps*/
  288.   if (cpt !=1)
  289.     {
  290.       for(cpt_int = 0; cpt_int < (cpt-1);cpt_int++)
  291. {
  292.   if ((tab_ascendant[cpt_int].x == i )&&(tab_ascendant[cpt_int].y == j ))
  293.     {
  294.       verif_ascendant = 0;
  295.     }
  296.   else
  297.     {
  298.       verif_ascendant = 1;
  299.     }
  300. }
  301.     }
  302.   if (verif_ascendant)
  303.     {
  304.       if (tableau_labyrinthe[i][j]->valeur != -1)
  305. {
  306.   if (( i!= (M-1)) && ( tableau_labyrinthe[i][j]->M_Est == 1 ) &&
  307.       (racine->provenance != 'E' ))
  308.     {
  309.       i++;
  310.       provenance_case = 'O';
  311.       valeur_case = tableau_labyrinthe[i][j]->valeur;
  312.       cpt++;
  313.       tab_ascendant[cpt].x = i;
  314.       tab_ascendant[cpt].y = j;
  315.       if (racine==NULL)
  316.  {
  317.    racine = (Arbre_chemins *)calloc(1,sizeof(Arbre_chemins));
  318.    racine->valeur = valeur_case;
  319.    racine->provenance = provenance_case;
  320.    racine->Dir_N = NULL;
  321.    racine->Dir_E = NULL;
  322.    racine->Dir_S = NULL;
  323.    racine->Dir_O = NULL;
  324.  }
  325.       else
  326.  construire_arbre(DE,tableau_labyrinthe,tableau_chemin_plus_court,tab_ascendant,valeur_case,provenance_case,cpt,i,j);
  327.     }
  328.   else if (( j!= (M-1)) && ( tableau_labyrinthe[i][j]->M_Sud == 1 ) && (racine->provenance != 'S' ))
  329.     {
  330.       j++;
  331.       provenance_case = 'N';
  332.       valeur_case = tableau_labyrinthe[i][j]->valeur;
  333.       cpt++;
  334.       tab_ascendant[cpt].x = i;
  335.       tab_ascendant[cpt].y = j;
  336.       if (racine==NULL)
  337.  {
  338.    racine = (Arbre_chemins *)calloc(1,sizeof(Arbre_chemins));
  339.    racine->valeur = valeur_case;
  340.    racine->provenance = provenance_case;
  341.    racine->Dir_N = NULL;
  342.    racine->Dir_E = NULL;
  343.    racine->Dir_S = NULL;
  344.    racine->Dir_O = NULL;
  345.  }
  346.       else
  347.  construire_arbre(DS,tableau_labyrinthe,tableau_chemin_plus_court,tab_ascendant,valeur_case,provenance_case,cpt,i,j);
  348.     }
  349.   else if (( i!= (1)) && ( tableau_labyrinthe[i-1][j]->M_Est == 1 ) && (racine->provenance != 'O' ))
  350.     {
  351.       i--;
  352.       provenance_case = 'E';
  353.       valeur_case = tableau_labyrinthe[i][j]->valeur;
  354.       cpt++;
  355.       tab_ascendant[cpt].x = i;
  356.       tab_ascendant[cpt].y = j;
  357.       if (racine==NULL)
  358.  {
  359.    racine = (Arbre_chemins *)calloc(1,sizeof(Arbre_chemins));
  360.    racine->valeur = valeur_case;
  361.    racine->provenance = provenance_case;
  362.    racine->Dir_N = NULL;
  363.    racine->Dir_E = NULL;
  364.    racine->Dir_S = NULL;
  365.    racine->Dir_O = NULL;
  366.  }
  367.       else
  368.  construire_arbre(DO,tableau_labyrinthe,tableau_chemin_plus_court,tab_ascendant,valeur_case,provenance_case,cpt,i,j);
  369.     }
  370.   else if (( j!= (1)) && ( tableau_labyrinthe[i][j-1]->M_Sud == 1 ) && (racine->provenance != 'N' ))
  371.     {
  372.       j--;
  373.       provenance_case = 'S';
  374.       valeur_case = tableau_labyrinthe[i][j]->valeur;
  375.       cpt++;
  376.       tab_ascendant[cpt].x = i;
  377.       tab_ascendant[cpt].y = j;
  378.       if (racine==NULL)
  379.  {
  380.    racine = (Arbre_chemins *)calloc(1,sizeof(Arbre_chemins));
  381.    racine->valeur = valeur_case;
  382.    racine->provenance = provenance_case;
  383.    racine->Dir_N = NULL;
  384.    racine->Dir_E = NULL;
  385.    racine->Dir_S = NULL;
  386.    racine->Dir_O = NULL;
  387.  }
  388.       else
  389.  construire_arbre(DN,tableau_labyrinthe,tableau_chemin_plus_court,tab_ascendant,valeur_case,provenance_case,cpt,i,j);
  390.     }
  391.   else
  392.     cpt--;
  393. }
  394.       else
  395. {
  396.   if (cpt < chemin_le_plus_court)
  397.     {
  398.       chemin_le_plus_court= cpt;
  399.       for (cpt_int =1; cpt_int < cpt; cpt_int++)
  400.  {
  401.    tableau_chemin_plus_court[cpt].x = tab_ascendant[cpt].x;
  402.    tableau_chemin_plus_court[cpt].y = tab_ascendant[cpt].y;
  403.  }
  404.       cpt = 2;
  405.     }
  406. }
  407.     }
  408.   return(tableau_chemin_plus_court[TAILLEMAXASC]);
  409. }
  410. int main()
  411. {
  412.   /*declarations*/
  413.   //  Arbre_chemins *racine;
  414.   int valeur_case;
  415.   char provenance_case;
  416.   int i;
  417.   int j;
  418.   int cpt;
  419.   int test;
  420.   int xcase_fin;
  421.   int ycase_fin;
  422.   Coordonnees tab_ascendant[TAILLEMAXASC];
  423.   Coordonnees tableau_chemin_plus_court[TAILLEMAXASC];
  424.   Case_labyrinthe *tableau_labyrinthe[M][N];
  425.   Arbre_chemins *racine;
  426.   /*initialisation*/
  427.   srand(time(NULL));
  428.   i = rand()%M;
  429.   j = rand()%N;
  430.   tab_ascendant[0].x= i;
  431.   tab_ascendant[0].y= j;
  432.   xcase_fin = rand()%M;
  433.   ycase_fin = rand()%N;
  434.   cpt = 1;
  435.   test = 0;
  436.   provenance_case = 'N';
  437.   valeur_case = -2;
  438.   racine = (Arbre_chemins *)calloc(1,sizeof(Arbre_chemins));
  439.   racine->valeur = -2 ;
  440.   racine->provenance = 'N';
  441.   racine->Dir_N = NULL;
  442.   racine->Dir_E = NULL;
  443.   racine->Dir_S = NULL;
  444.   racine->Dir_O = NULL;
  445.   tableau_labyrinthe[M][N] = (Case_labyrinthe *)calloc(1,sizeof(Case_labyrinthe));
  446.   /*Corps*/
  447.   *tableau_labyrinthe[M][N] = construction_labyrinthe(tableau_labyrinthe,xcase_fin,ycase_fin);
  448.  
  449.   // tableau_chemin_plus_court[TAILLEMAXASC] = construire_arbre(racine,tableau_labyrinthe,tableau_chemin_plus_court,tab_ascendant,valeur_case,provenance_case,cpt,i,j);
  450.   tracer_tableau(tableau_labyrinthe,tab_ascendant,xcase_fin,ycase_fin);
  451.   for (test = 0 ; test < TAILLEMAXASC ; test++)
  452.     {
  453.       printf("x : %d , y : %d\n",tableau_chemin_plus_court[test].x,tableau_chemin_plus_court[test].y);
  454.       test++;
  455.     }
  456.   // while((tableau_chemin_plus_court[test].x = xcase_fin) && (tableau_chemin_plus_court[test].y= ycase_fin));
  457.   return(0);
  458. }


Reply

Marsh Posté le 24-01-2005 à 22:12:46    

tet2neu a écrit :

:non:  
une accolade [:aloy]


Ha merde , je l'ai pas vu ! [:ohmyeyes]

Reply

Marsh Posté le 24-01-2005 à 22:13:33    

stiffler a écrit :

Ha merde , je l'ai pas vu ! [:ohmyeyes]


c'était pourtant flagrant [:civcortex]

Reply

Marsh Posté le 24-01-2005 à 22:32:26    

vite une nouvelle page

Reply

Marsh Posté le 24-01-2005 à 22:55:39    

Masklinn a écrit :

MIEUX [:zytrayaisse]  
 
À la molette uniquement, 15s ! [:uriel]  
(mais j'ai mal à l'index maintenant :cry: )


 
 
Molette uniquement, la page complete 7s.  :sol:  
 
Changez de souris les gars  :D

Reply

Marsh Posté le 24-01-2005 à 22:58:42    

Mackila a écrit :

Molette uniquement, la page complete 7s.  :sol:  
 
Changez de souris les gars  :D


Oui mais non, 15s c'était en défilement 3 lignes, moi aussi je peux aller vite si je modifie le réglage (~5.5s en réglage de défilement "écran", et c'est parce que mon PC rame un peu sous firefox)


Message édité par masklinn le 24-01-2005 à 22:59:14

---------------
Stick a parrot in a Call of Duty lobby, and you're gonna get a racist parrot. — Cody
Reply

Marsh Posté le 24-01-2005 à 23:47:48    

Pour qui tu me prends, je suis en 3 lignes aussi, souris optique microsoft "de base" (2 boutons + molette).
 
Le temps a été mesuré ainsi : page bloquée en haut, lancement d'une ziq sous winamp à la souris, clic sur la page, molettage à mort, une fois arrivé en bas arret de winamp à la souris, et matage du temps :P
 
Edit : Boarf je suis fatigué maintenant j'arrive pu à descendre en dessous de 9 secondes... :sleep:


Message édité par Mackila le 24-01-2005 à 23:49:42
Reply

Marsh Posté le 25-01-2005 à 01:37:36    

J'ai enfin réussi à identifier correctement l'erreur:
en fait quand je rentre dans void Human:: Play  je me plante sur l'instruction solution.push_back(theChar),il met segmentation default.
 
Le passage par solution.begin lui marche
Doù cela vient il?


Message édité par smag le 25-01-2005 à 01:58:56
Reply

Marsh Posté le 26-01-2005 à 22:55:23    

J'ai pas le courage de faire des copier coller de tous tes fichiers pour voir où serait le problème mais si tu utilises vc++5 ou 6, c'est peut-être un bug de la STL :
http://www.dinkumware.com/vc_fixes.html
 
Sinon tu dois corrompre ton vecteur quelque part ...

Reply

Marsh Posté le 26-01-2005 à 23:44:57    

C un peu indigeste comme question  si tu as un sln ou un dsp mets le projet ca sera plus simple.
Par contre, les retours de vecteurs sur la pile tu peux commencer par eviter ca sera deja une grosse amelioration

Reply

Marsh Posté le 27-01-2005 à 00:18:33    

En fait mon pb a changé d'aspect: ça ne viendrait pas du code mais de l'EDI cf message[url] http://forum.hardware.fr/hardwaref [...] 3477-1.htm[/url]

Reply

Marsh Posté le    

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed