[Echecs] Modification système déplacement et ajout deplacement tour
This commit is contained in:
parent
55680ad032
commit
665b963193
|
@ -1,5 +1,14 @@
|
|||
CASES_COTE = 8
|
||||
|
||||
MVT_INCONNU = -42
|
||||
MVT_OK = 1
|
||||
MVT_ROQUE = 2
|
||||
MVT_SELECTION = -1
|
||||
MVT_SUR_PLACE = -2
|
||||
MVT_SAUT_AMI = -3
|
||||
MVT_PION_INC = -4
|
||||
MVT_N_AUTORISE = -5
|
||||
MVT_OBSTRUCTION = -501
|
||||
|
||||
class LogiqueEchecs:
|
||||
|
||||
|
@ -65,74 +74,84 @@ class LogiqueEchecs:
|
|||
def mvtPossible(self, x1, y1, x2, y2):
|
||||
pion = self.grille[x1][y1]
|
||||
if self.aSonTour(pion):
|
||||
if pion > 0:
|
||||
tPion = pion % 10
|
||||
if tPion == 1: # Pion
|
||||
if x1 == x2 and self.grille[x2][y2] <= 0: # Avance
|
||||
if self.joueur:
|
||||
if y2 == y1 - 1:
|
||||
return [None, True]
|
||||
elif y1 == 6 and y2 == 4:
|
||||
return [None, True]
|
||||
if (x1 != x2 or y1 != y2):
|
||||
if not self.aSonTour(self.grille[x2][y2]):
|
||||
tPion = pion % 10
|
||||
if tPion == 1: # Pion
|
||||
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:
|
||||
return MVT_OK
|
||||
else:
|
||||
return MVT_N_AUTORISE
|
||||
else:
|
||||
return -4
|
||||
if y2 == y1 + 1:
|
||||
return 1
|
||||
elif y1 == 1 and y2 == 3:
|
||||
return MVT_OK
|
||||
else:
|
||||
return MVT_N_AUTORISE
|
||||
elif abs(x1-x2) == 1: # Saut
|
||||
if self.joueur:
|
||||
if y2 == y1 - 1 and \
|
||||
self.ePionNoir(self.grille[x2][y2]):
|
||||
return MVT_OK
|
||||
else:
|
||||
return MVT_N_AUTORISE
|
||||
else:
|
||||
if y2 == y1 + 1 and \
|
||||
self.ePionBlanc(self.grille[x2][y2]):
|
||||
return MVT_OK
|
||||
else:
|
||||
return MVT_N_AUTORISE
|
||||
else:
|
||||
if y2 == y1 + 1:
|
||||
return [None, True]
|
||||
elif y1 == 1 and y2 == 3:
|
||||
return [None, True]
|
||||
else:
|
||||
return -4
|
||||
elif abs(x1-x2) == 1: # Saut
|
||||
if self.joueur:
|
||||
if y2 == y1 - 1 and \
|
||||
self.ePionNoir(self.grille[x2][y2]):
|
||||
return [[x2, y2], True] # Saute un noir
|
||||
else:
|
||||
return -4
|
||||
return MVT_N_AUTORISE
|
||||
elif tPion == 2:
|
||||
if y1 == y2:
|
||||
sens = (x2-x1)//abs(x2-x1)
|
||||
for x in range(x1+sens, x2, sens):
|
||||
if self.grille[x][y1] > 0:
|
||||
return MVT_OBSTRUCTION
|
||||
elif x1 == x2:
|
||||
sens = (y2-y1)//abs(y2-y1)
|
||||
for y in range(y1+sens, y2, sens):
|
||||
if self.grille[x1][y] > 0:
|
||||
return MVT_OBSTRUCTION
|
||||
else:
|
||||
if y2 == y1 + 1 and \
|
||||
self.ePionBlanc(self.grille[x2][y2]):
|
||||
return [[x2, y2], True] # Saute un blanc
|
||||
else:
|
||||
return -4
|
||||
|
||||
return MVT_N_AUTORISE
|
||||
return MVT_OK
|
||||
elif tPion == 6: # Roi
|
||||
if x2 <= x1 + 1 and x2 >= x1 - 1 and y2 <= y1 + 1 and \
|
||||
y2 >= y1 - 1:
|
||||
return MVT_OK
|
||||
else:
|
||||
return MVT_N_AUTORISE
|
||||
else:
|
||||
return -4
|
||||
elif tPion == 6:
|
||||
if x2 <= x1 + 1 and x2 >= x1 - 1 and y2 <= y1 + 1 and \
|
||||
y2 >= y1 - 1 \
|
||||
and (x1 != x2 or y1 != y2):
|
||||
return [None, True]
|
||||
else:
|
||||
return -4
|
||||
return MVT_PION_INC
|
||||
else:
|
||||
return -3
|
||||
|
||||
return [None, True]
|
||||
return MVT_SAUT_AMI
|
||||
else:
|
||||
return -2
|
||||
return MVT_SUR_PLACE
|
||||
else:
|
||||
return -1
|
||||
return MVT_SELECTION
|
||||
return MVT_INCONNU
|
||||
|
||||
def mvtsPossibles(self, x1, y1):
|
||||
tableau = []
|
||||
for x2 in range(0, CASES_COTE):
|
||||
for y2 in range(0, CASES_COTE):
|
||||
if type(self.mvtPossible(x1, y1, x2, y2)) is list:
|
||||
if self.mvtPossible(x1, y1, x2, y2) == MVT_OK:
|
||||
tableau.append([x2, y2])
|
||||
return tableau
|
||||
|
||||
def dPion(self, x1, y1, x2, y2):
|
||||
test = self.mvtPossible(x1, y1, x2, y2)
|
||||
if type(test) is list:
|
||||
self.grille[x2][y2] = self.grille[x1][y1]
|
||||
self.grille[x1][y1] = 0
|
||||
if test[1]:
|
||||
self.joueur = not self.joueur
|
||||
return test
|
||||
else:
|
||||
return test
|
||||
if test == MVT_OK:
|
||||
self.grille[x1][y1], self.grille[x2][y2] = 0, self.grille[x1][y1]
|
||||
self.joueur = not self.joueur
|
||||
return test
|
||||
|
||||
# GUI
|
||||
|
||||
|
@ -375,9 +394,9 @@ class PlateauTk:
|
|||
|
||||
def dPion(self, x1, y1, x2, y2):
|
||||
test = self.logique.dPion(x1, y1, x2, y2)
|
||||
if type(test) is list: # Si déplacement possible
|
||||
if type(test[0]) is list: # Si saut → Animation effacement
|
||||
self.animerF(self.grillePions[test[0][0]][test[0][1]])
|
||||
if test == MVT_OK: # Si déplacement possible
|
||||
if self.grillePions[x2][y2]: # Si saut → Animation effacement
|
||||
self.animerF(self.grillePions[x2][y2])
|
||||
self.grillePions[x2][y2], self.grillePions[x1][y1] = \
|
||||
self.grillePions[x1][y1], False
|
||||
self.animerD((x1 + .5) * COTE_CASE, (y1 + .5) * COTE_CASE, \
|
||||
|
|
Reference in a new issue