Skip to content

Instantly share code, notes, and snippets.

Created October 11, 2012 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/91d47ba7f1bb47b9d23e to your computer and use it in GitHub Desktop.
Save anonymous/91d47ba7f1bb47b9d23e to your computer and use it in GitHub Desktop.
bool Plateau::stackUsable(int nStack){
/*bool present = false;
if(nStack >= 0 && nStack<Config::nbPile){
for(unsigned i=0; i<this->plateau.at(nStack).size(); i++){
if(this->plateau.at(nStack).at(i) == Outils::BLANC)
present = true;
}
}
return present;*/
return true; // debug time !
}
void Plateau::play(int nStack){
// vérifier qu'il existe un autre stack qui peut recevoir le stack sélectionner
// ou alors vérifier plus haut via une méthode playable() qui renvoit true si au min
// 2 stack ne sont pas vides
int lastStackUsed = -1; // vérifier où on a placer le dernier pion
int i = nStack; // le stack courant qu'on vérifie
if(nStack >= 0 && nStack < this->plateau.size() && stackUsable(nStack)){
while(!this->plateau.at(nStack).empty()){
i = bouclage(++i);
if(!this->plateau.at(i).empty()){
this->plateau.at(i).push_back(this->plateau.at(nStack).front());
this->plateau.at(nStack).pop_front();
lastStackUsed = i;
}
if(i == nStack)
viderStack(nStack, lastStackUsed);
}
}else{
// throw error out of bound ?
}
}
void Plateau::viderStack(int source, int destination){
while(!this->plateau.at(source).empty()){
this->plateau.at(destination).push_back(this->plateau.at(source).front());
this->plateau.at(source).pop_front();
}
}
int Plateau::bouclage(int n){
cout << "bouclage " << n << endl;
if(n >= this->plateau.size())
return 0;
return n;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment