ya encore des bugs la dedens... tentaive de debogguage
This commit is contained in:
parent
ae6fca99a4
commit
709606ac32
2 changed files with 24 additions and 22 deletions
|
@ -12,7 +12,7 @@ struct PlateauSafari : public Plateau {
|
|||
|
||||
// Pareil que deplacementValide mais est utilisable avec des coordonnées
|
||||
bool deplacementValideCoor(const int x1, const int y1, const int x2,
|
||||
const int y2) const;
|
||||
const int y2, const bool debug = false) const;
|
||||
|
||||
// Vérifie que le déplacement est valide
|
||||
bool deplacementValide(const int destX, const int destY) const;
|
||||
|
|
|
@ -149,32 +149,33 @@ void PlateauSafari::afficherPlateau(std::ostream &out, const bool d) const {
|
|||
}
|
||||
|
||||
bool PlateauSafari::deplacementValideCoor(const int x1, const int y1,
|
||||
const int x2, const int y2) const {
|
||||
const int x2, const int y2,
|
||||
const bool d) const {
|
||||
// Vérifier qu'il n'y a pas de barrière sur le chemin
|
||||
for (PieceSafari *barriere : barrieres) {
|
||||
Position pos1 = barriere->getPos();
|
||||
Position pos2 = barriere->getPos2();
|
||||
|
||||
// Plus lointaine position en fonction de l'orientation
|
||||
std::pair<float, float> posBarriere;
|
||||
|
||||
// Horizontale
|
||||
if (pos1.first == pos2.first) {
|
||||
posBarriere =
|
||||
std::make_pair(pos1.first, std::min(pos1.second, pos2.second) + 0.5);
|
||||
if (d) {
|
||||
std::cout << std::boolalpha << "barriere" << pos1.first << ","
|
||||
<< pos1.second << "|" << pos2.first << "," << pos2.second
|
||||
<< " et pieces" << x1 << "," << y1 << "|" << x2 << "," << y2
|
||||
<< "=> "
|
||||
<< (std::max(pos1.first, pos2.first) >= std::max(x1, x2)) << " "
|
||||
<< (std::min(pos1.first, pos2.first) <= std::min(x1, x2)) << " "
|
||||
<< (std::max(pos1.second, pos2.second) >= std::max(y1, y2))
|
||||
<< " "
|
||||
<< (std::min(pos1.second, pos2.second) <= std::min(y1, y2))
|
||||
<< " " << std::endl;
|
||||
}
|
||||
// Verticale
|
||||
else {
|
||||
posBarriere =
|
||||
std::make_pair(std::min(pos1.first, pos2.first) + 0.5, pos1.second);
|
||||
}
|
||||
|
||||
// Vérifier les conditions pour le point posBarriere sur
|
||||
// le segment posInitiale - (x, y)
|
||||
if (posBarriere.first >= std::min(x1, x2) &&
|
||||
posBarriere.first <= std::max(x1, x2) &&
|
||||
posBarriere.second >= std::min(y1, y2) &&
|
||||
posBarriere.second <= std::max(y1, y2)) {
|
||||
if ( // Gauche vers droite
|
||||
std::max(pos1.first, pos2.first) >= std::max(x1, x2)
|
||||
// Droite vers gauche
|
||||
&& std::min(pos1.first, pos2.first) <= std::min(x1, x2)
|
||||
// Haut vers bas / Descendre
|
||||
&& std::max(pos1.second, pos2.second) >= std::max(y1, y2)
|
||||
// Bas vers haut / Monter
|
||||
&& std::min(pos1.second, pos2.second) <= std::min(y1, y2)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -189,7 +190,8 @@ bool PlateauSafari::deplacementValide(const int x, const int y) const {
|
|||
|
||||
Position posInitiale = selection->getPos();
|
||||
|
||||
return deplacementValideCoor(posInitiale.first, posInitiale.second, x, y);
|
||||
return deplacementValideCoor(posInitiale.first, posInitiale.second, x, y,
|
||||
true);
|
||||
}
|
||||
|
||||
Position PlateauSafari::getPlaceholderBarriere() const {
|
||||
|
|
Reference in a new issue