[Echecs] Lisibilité système déplacement et ajout fou et dame
This commit is contained in:
parent
665b963193
commit
f71bf87a1f
|
@ -71,25 +71,19 @@ class LogiqueEchecs:
|
|||
return (self.ePionNoir(pion) and self.joueur == False) or \
|
||||
(self.ePionBlanc(pion) and self.joueur == True)
|
||||
|
||||
def mvtPossible(self, x1, y1, x2, y2):
|
||||
pion = self.grille[x1][y1]
|
||||
if self.aSonTour(pion):
|
||||
if (x1 != x2 or y1 != y2):
|
||||
if not self.aSonTour(self.grille[x2][y2]):
|
||||
tPion = pion % 10
|
||||
if tPion == 1: # Pion
|
||||
def mvtPossiblePion(self, x1, y1, x2, y2):
|
||||
if x1 == x2 and self.grille[x2][y2] <= 0: # Avance
|
||||
if self.joueur:
|
||||
if y2 == y1 - 1:
|
||||
return 1
|
||||
elif y1 == 6 and y2 == 4:
|
||||
elif y1 == 6 and y2 == 4 and self.grille[x1][5] == 0:
|
||||
return MVT_OK
|
||||
else:
|
||||
return MVT_N_AUTORISE
|
||||
else:
|
||||
if y2 == y1 + 1:
|
||||
return 1
|
||||
elif y1 == 1 and y2 == 3:
|
||||
elif y1 == 1 and y2 == 3 and self.grille[x1][2] == 0:
|
||||
return MVT_OK
|
||||
else:
|
||||
return MVT_N_AUTORISE
|
||||
|
@ -108,7 +102,8 @@ class LogiqueEchecs:
|
|||
return MVT_N_AUTORISE
|
||||
else:
|
||||
return MVT_N_AUTORISE
|
||||
elif tPion == 2:
|
||||
|
||||
def mvtPossibleTour(self, x1, y1, x2, y2):
|
||||
if y1 == y2:
|
||||
sens = (x2-x1)//abs(x2-x1)
|
||||
for x in range(x1+sens, x2, sens):
|
||||
|
@ -122,9 +117,56 @@ class LogiqueEchecs:
|
|||
else:
|
||||
return MVT_N_AUTORISE
|
||||
return MVT_OK
|
||||
|
||||
def mvtPossibleFou(self, x1, y1, x2, y2):
|
||||
if abs(x2-x1) == abs(y2-y1):
|
||||
sensX = (x2-x1)//abs(x2-x1)
|
||||
sensY = (y2-y1)//abs(y2-y1)
|
||||
x = x1
|
||||
y = y1
|
||||
dist = 0
|
||||
distTot = abs(x2-x1)
|
||||
while dist < distTot:
|
||||
dist += 1
|
||||
x += sensX
|
||||
y += sensY
|
||||
if self.grille[x][y] > 0:
|
||||
if dist == distTot:
|
||||
return MVT_OK # Saut
|
||||
else:
|
||||
return MVT_OBSTRUCTION
|
||||
return MVT_OK # Vide
|
||||
else:
|
||||
return MVT_N_AUTORISE
|
||||
|
||||
def mvtPossibleCavalier(self, x1, y1, x2, y2):
|
||||
return MVT_PION_INC
|
||||
|
||||
def mvtPossible(self, x1, y1, x2, y2):
|
||||
pion = self.grille[x1][y1]
|
||||
if self.aSonTour(pion):
|
||||
if (x1 != x2 or y1 != y2):
|
||||
if not self.aSonTour(self.grille[x2][y2]):
|
||||
tPion = pion % 10
|
||||
if tPion == 1: # Pion
|
||||
return self.mvtPossiblePion(x1, y1, x2, y2)
|
||||
elif tPion == 2: # Tour
|
||||
return self.mvtPossibleTour(x1, y1, x2, y2)
|
||||
elif tPion == 3: # Cavalier
|
||||
return self.mvtPossibleCavalier(x1, y1, x2, y2)
|
||||
elif tPion == 4: # Fou
|
||||
return self.mvtPossibleFou(x1, y1, x2, y2)
|
||||
elif tPion == 5: # Dame
|
||||
tour = self.mvtPossibleTour(x1, y1, x2, y2)
|
||||
fou = self.mvtPossibleFou(x1, y1, x2, y2)
|
||||
if tour == MVT_OK or fou == MVT_OK:
|
||||
return MVT_OK
|
||||
elif tour == MVT_OBSTRUCTION or fou == MVT_OBSTRUCTION:
|
||||
return MVT_OBSTRUCTION
|
||||
else:
|
||||
return MVT_N_AUTORISE
|
||||
elif tPion == 6: # Roi
|
||||
if x2 <= x1 + 1 and x2 >= x1 - 1 and y2 <= y1 + 1 and \
|
||||
y2 >= y1 - 1:
|
||||
if abs(x2-x1) <= 1 and abs(y2-y1) <= 1:
|
||||
return MVT_OK
|
||||
else:
|
||||
return MVT_N_AUTORISE
|
||||
|
@ -150,7 +192,7 @@ class LogiqueEchecs:
|
|||
test = self.mvtPossible(x1, y1, x2, y2)
|
||||
if test == MVT_OK:
|
||||
self.grille[x1][y1], self.grille[x2][y2] = 0, self.grille[x1][y1]
|
||||
self.joueur = not self.joueur
|
||||
# self.joueur = not self.joueur
|
||||
return test
|
||||
|
||||
# GUI
|
||||
|
|
Reference in a new issue