[Echecs] Dames : Saut correct
This commit is contained in:
parent
ccdb4c1657
commit
f32ce16e71
|
@ -99,6 +99,7 @@ class LogiqueDames(Logique):
|
||||||
|
|
||||||
MVT_INCONNU = 'Cause inconnue'
|
MVT_INCONNU = 'Cause inconnue'
|
||||||
MVT_OK = 'Valide'
|
MVT_OK = 'Valide'
|
||||||
|
MVT_SAUT = 'Saut'
|
||||||
MVT_SELECTION = 'Mauvais tour'
|
MVT_SELECTION = 'Mauvais tour'
|
||||||
MVT_SUR_PLACE = 'Immobile'
|
MVT_SUR_PLACE = 'Immobile'
|
||||||
MVT_N_AUTORISE = 'Non-autorisé'
|
MVT_N_AUTORISE = 'Non-autorisé'
|
||||||
|
@ -123,11 +124,11 @@ class LogiqueDames(Logique):
|
||||||
for y in range(0, 3+1):
|
for y in range(0, 3+1):
|
||||||
for x in range(0, self.CASES_COTE):
|
for x in range(0, self.CASES_COTE):
|
||||||
if not self.eCaseBlanche(x, y):
|
if not self.eCaseBlanche(x, y):
|
||||||
self.grille[x][y] = self.DECALAGE_NOIRS + self.PCE_PION
|
self.grille[x][y] = self.DECALAGE_NOIRS + self.PCE_DAME
|
||||||
for y in range(self.CASES_COTE-3-1, self.CASES_COTE):
|
for y in range(self.CASES_COTE-3-1, self.CASES_COTE):
|
||||||
for x in range(0, self.CASES_COTE):
|
for x in range(0, self.CASES_COTE):
|
||||||
if not self.eCaseBlanche(x, y):
|
if not self.eCaseBlanche(x, y):
|
||||||
self.grille[x][y] = self.DECALAGE_BLANCS + self.PCE_PION
|
self.grille[x][y] = self.DECALAGE_BLANCS + self.PCE_DAME
|
||||||
|
|
||||||
def deplPossiblePion(self, x1, y1, x2, y2):
|
def deplPossiblePion(self, x1, y1, x2, y2):
|
||||||
"""
|
"""
|
||||||
|
@ -138,6 +139,18 @@ class LogiqueDames(Logique):
|
||||||
return self.MVT_OK
|
return self.MVT_OK
|
||||||
else:
|
else:
|
||||||
return self.MVT_N_AUTORISE
|
return self.MVT_N_AUTORISE
|
||||||
|
elif abs(x2-x1) == 2 and abs(y2-y1) == 2:
|
||||||
|
xS = x1+(x2-x1)//2
|
||||||
|
yS = y1+(y2-y1)//2
|
||||||
|
if self.ePiece(self.grille[xS][yS]):
|
||||||
|
if self.aSonTour(self.grille[xS][yS]):
|
||||||
|
return self.MVT_SAUT_AMI
|
||||||
|
else:
|
||||||
|
return self.MVT_SAUT
|
||||||
|
else:
|
||||||
|
return self.MVT_N_AUTORISE
|
||||||
|
else:
|
||||||
|
return self.MVT_N_AUTORISE
|
||||||
|
|
||||||
def deplPossibleDame(self, x1, y1, x2, y2):
|
def deplPossibleDame(self, x1, y1, x2, y2):
|
||||||
"""
|
"""
|
||||||
|
@ -155,8 +168,8 @@ class LogiqueDames(Logique):
|
||||||
x += sensX
|
x += sensX
|
||||||
y += sensY
|
y += sensY
|
||||||
if self.ePiece(self.grille[x][y]):
|
if self.ePiece(self.grille[x][y]):
|
||||||
if dist == distTot:
|
if dist == distTot - 1 and not self.aSonTour(self.grille[x][y]):
|
||||||
return self.MVT_OK # Saut
|
return self.MVT_SAUT # Saut
|
||||||
else:
|
else:
|
||||||
return self.MVT_OBSTRUCTION
|
return self.MVT_OBSTRUCTION
|
||||||
return self.MVT_OK # Vide
|
return self.MVT_OK # Vide
|
||||||
|
@ -213,7 +226,8 @@ class LogiqueDames(Logique):
|
||||||
tableau = []
|
tableau = []
|
||||||
for x2 in range(0, self.CASES_COTE):
|
for x2 in range(0, self.CASES_COTE):
|
||||||
for y2 in range(0, self.CASES_COTE):
|
for y2 in range(0, self.CASES_COTE):
|
||||||
if self.deplPossible(x1, y1, x2, y2) == self.MVT_OK:
|
if self.deplPossible(x1, y1, x2, y2) == self.MVT_OK \
|
||||||
|
or self.mvtPossible(x1, y1, x2, y2) == self.MVT_SAUT:
|
||||||
tableau.append([x2, y2])
|
tableau.append([x2, y2])
|
||||||
return tableau
|
return tableau
|
||||||
|
|
||||||
|
@ -224,7 +238,8 @@ class LogiqueDames(Logique):
|
||||||
tableau = []
|
tableau = []
|
||||||
for x2 in range(0, self.CASES_COTE):
|
for x2 in range(0, self.CASES_COTE):
|
||||||
for y2 in range(0, self.CASES_COTE):
|
for y2 in range(0, self.CASES_COTE):
|
||||||
if self.mvtPossible(x1, y1, x2, y2) == self.MVT_OK:
|
if self.mvtPossible(x1, y1, x2, y2) == self.MVT_OK \
|
||||||
|
or self.mvtPossible(x1, y1, x2, y2) == self.MVT_SAUT:
|
||||||
tableau.append([x2, y2])
|
tableau.append([x2, y2])
|
||||||
return tableau
|
return tableau
|
||||||
|
|
||||||
|
@ -265,13 +280,15 @@ class LogiqueDames(Logique):
|
||||||
'deplacer': [], # Pièces à déplacer
|
'deplacer': [], # Pièces à déplacer
|
||||||
'supprimer': [], # Pièces à supprimer
|
'supprimer': [], # Pièces à supprimer
|
||||||
}
|
}
|
||||||
if test == self.MVT_OK:
|
if test in [self.MVT_OK, self.MVT_SAUT]:
|
||||||
|
if test == self.MVT_SAUT:
|
||||||
|
xS = x2-(x2-x1)//abs(x2-x1)
|
||||||
|
yS = y2-(y2-y1)//abs(y2-y1)
|
||||||
|
self.grille[xS][yS] = self.PCE_VIDE
|
||||||
|
retour['supprimer'].append([xS, yS])
|
||||||
retour['valide'] = True
|
retour['valide'] = True
|
||||||
if self.ePiece(self.grille[x2][y2]):
|
|
||||||
retour['supprimer'].append([x2, y2])
|
|
||||||
retour['deplacer'].append([x1, y1, x2, y2])
|
retour['deplacer'].append([x1, y1, x2, y2])
|
||||||
self.grille[x1][y1], self.grille[x2][
|
self.grille[x1][y1], self.grille[x2][y2] = self.PCE_VIDE, self.grille[x1][y1]
|
||||||
y2] = self.PCE_VIDE, self.grille[x1][y1]
|
|
||||||
self.joueur = not self.joueur
|
self.joueur = not self.joueur
|
||||||
self.vPartieFinie()
|
self.vPartieFinie()
|
||||||
return retour
|
return retour
|
||||||
|
|
Reference in a new issue