-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoi.cpp
More file actions
123 lines (102 loc) · 3.79 KB
/
Copy pathRoi.cpp
File metadata and controls
123 lines (102 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* Projet final :: INF1015 :: Livrable 3. Fichier qui définit les fonctions pour le roi.
* \file Roi.cpp
* \author Charles De Lafontaine & Benoit Dambrine & al.
* \date 9 mai 2021
* Créé le 31 mars 2021
*/
#include "Modele.h"
/**
* La pièce roi.
* \param [const Couleur&] couleur <La couleur de la pièce à instancier.>
*/
modele::Roi::Roi(const Couleur& couleur) :
Piece(couleur)
{
if (couleur == Couleur::Blanc)
caracterePiece_ = CARACTERE_ROI_BLANC;
else
caracterePiece_ = CARACTERE_ROI_NOIR;
}
/**
* Vérifie si un roi est en confrontation avec le roi adverse.
* \param [const pair<int, int>&] mouvementPossible <Le mouvement à évaluer.>
* \param [const pair<int, int>&] positionRoiAdverse <La position du roi adverse.>
* \return [bool] <Vrai si le mouvement est non conflictuel, faux autrement.>
*/
bool modele::Roi::estConfrontationRoiAdverse(const std::pair<int, int>& mouvementPossible, const std::pair<int, int>& positionRoiAdverse) const
{
//? Vérifier que notre mouvement ne rentre pas en confrontation avec l'autre roi (Pythagore entre la position des deux rois)
if (sqrt(pow(abs(mouvementPossible.first - positionRoiAdverse.first), FACTEUR_RACINE) + pow(abs(mouvementPossible.second - positionRoiAdverse.second), FACTEUR_RACINE)) >= LIMITE_CONFRONTATIONS_ROIS)
return false;
return true;
}
/**
* Calcule les mouvements possibles pour le roi.
* \param [const pair<int, int>&] positionInitiale <La position initiale du roi.>
* \param [Plateau*] plateau <L'échiquier.>
*/
void modele::Roi::calculerMouvementsPossibles(const std::pair<int, int>& positionInitiale, Plateau* plateau)
{
calculerMouvementsPossiblesSimples(positionInitiale, plateau);
}
/**
* Calcule les mouvements possibles simples pour le roi.
* \param [const pair<int, int>&] positionInitiale <La position initiale du roi.>
* \param [Plateau*] plateau <L'échiquier.>
*/
void modele::Roi::calculerMouvementsPossiblesSimples(const std::pair<int, int>& positionInitiale, Plateau* plateau)
{
using namespace std;
const vector<pair<const int, const int>> MOUVEMENTS_POSSIBLES = {
{ positionInitiale.first + 1, positionInitiale.second },
{ positionInitiale.first - 1, positionInitiale.second },
{ positionInitiale.first, positionInitiale.second + 1 },
{ positionInitiale.first, positionInitiale.second - 1 },
{ positionInitiale.first + 1, positionInitiale.second + 1 },
{ positionInitiale.first + 1, positionInitiale.second - 1 },
{ positionInitiale.first - 1, positionInitiale.second + 1 },
{ positionInitiale.first - 1, positionInitiale.second - 1 }
};
for (const pair<int, int>& mouvement : MOUVEMENTS_POSSIBLES) {
const pair<Case*, pair<int, int>> ROI_ADVERSE = plateau->trouverCase(CARACTERE_ROI_NOIR, true);
if (!estConfrontationRoiAdverse(mouvement, ROI_ADVERSE.second)) {
if (estInterieurBornes(mouvement)) {
if (plateau->getEtatEchec() == false) {
if (plateau->testEchecAuRoi(positionInitiale, mouvement)) {
//? Vérifier que nous ne mangeons pas nos propres pièces
if (plateau->trouverCase(mouvement)->getOccupation()) {
if (plateau->trouverCase(mouvement)->getPieceOccupante()->getCouleur() != plateau->getTour()) {
ajouterMouvement(mouvement);
}
}
else {
ajouterMouvement(mouvement);
}
}
}
else {
if (plateau->testEchecProtection(positionInitiale, mouvement)) {
ajouterMouvement(mouvement);
}
}
}
}
}
}
/**
* Définit le nom du roi sous forme d'un caractère.
* \return [char] <Le nom du roi lorsqu'il n'est pas initialisé.>
*/
char modele::Roi::getNom() const
{
return CARACTERE_ROI_NOIR;
}
/**
* Retourne le nom du roi sous forme d'un caractère.
* \return [char] <Le nom du roi lorsqu'il est initialisé.>
*/
char modele::Roi::getCaractere() const
{
return caracterePiece_;
}