[Echecs] Ajout LogiqueDameAnglaises
This commit is contained in:
parent
a1f3dfb769
commit
e31d7aae8f
|
@ -84,7 +84,7 @@ class Logique:
|
|||
|
||||
class LogiqueDames(Logique):
|
||||
"""
|
||||
Logique du jeu de Dames
|
||||
Logique du jeu de Dames (International)
|
||||
"""
|
||||
CASES_COTE = 10
|
||||
RANGEES = 4
|
||||
|
@ -105,15 +105,19 @@ class LogiqueDames(Logique):
|
|||
MVT_SUR_PLACE = 'Immobile'
|
||||
MVT_N_AUTORISE = 'Non-autorisé'
|
||||
MVT_CASE_BLANCHE = 'Case blanche'
|
||||
MVT_PRISE_ARRIERE = 'Prise arrière'
|
||||
MVT_SAUT_AMI = 'Saut ami'
|
||||
MVT_DEST_OCC = 'Destination occupée'
|
||||
MVT_OBSTRUCTION = 'Pièce en chemin'
|
||||
MVT_SOUFFLER = 'Souffler n\'est pas jouer'
|
||||
MVT_PIECE_INC = 'Pièce inconnue'
|
||||
|
||||
PRISE_ARRIERE = True
|
||||
DEPL_LONG_DAME = True
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
Constructeur de LogiqueEchecs
|
||||
Constructeur de LogiqueDames
|
||||
"""
|
||||
Logique.__init__(self)
|
||||
self.remplirGrille()
|
||||
|
@ -145,6 +149,9 @@ class LogiqueDames(Logique):
|
|||
xS = x1+(x2-x1)//2
|
||||
yS = y1+(y2-y1)//2
|
||||
if self.ePiece(self.grille[xS][yS]):
|
||||
if not self.PRISE_ARRIERE and (self.joueur == self.BLANC and y1 < y2) or \
|
||||
(self.joueur == self.NOIR and y1 > y2):
|
||||
return self.MVT_PRISE_ARRIERE
|
||||
if self.aSonTour(self.grille[xS][yS]):
|
||||
return self.MVT_SAUT_AMI
|
||||
else:
|
||||
|
@ -158,28 +165,44 @@ class LogiqueDames(Logique):
|
|||
"""
|
||||
Vérifie si le déplacement est possible pour une dame.
|
||||
"""
|
||||
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.ePiece(self.grille[x][y]):
|
||||
if dist == distTot - 1 and not self.aSonTour(self.grille[x][y]):
|
||||
return self.MVT_SAUT
|
||||
else:
|
||||
return self.MVT_OBSTRUCTION
|
||||
if self.rafle:
|
||||
return self.MVT_SOUFFLER
|
||||
if self.DEPL_LONG_DAME:
|
||||
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.ePiece(self.grille[x][y]):
|
||||
if dist == distTot - 1 and not self.aSonTour(self.grille[x][y]):
|
||||
return self.MVT_SAUT
|
||||
else:
|
||||
return self.MVT_OBSTRUCTION
|
||||
if self.rafle:
|
||||
return self.MVT_SOUFFLER
|
||||
else:
|
||||
return self.MVT_OK
|
||||
else:
|
||||
return self.MVT_OK
|
||||
return self.MVT_N_AUTORISE
|
||||
else:
|
||||
return self.MVT_N_AUTORISE
|
||||
if abs(x2-x1) == 1 and abs(y2-y1) == 1 and not self.rafle:
|
||||
return self.MVT_OK
|
||||
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
|
||||
|
||||
# TODO Utiliser la gestion d'erreurs de Python ?
|
||||
def deplPossible(self, x1, y1, x2, y2):
|
||||
|
@ -319,6 +342,21 @@ class LogiqueDames(Logique):
|
|||
self.vPartieFinie()
|
||||
return retour
|
||||
|
||||
class LogiqueDamesAnglaises(LogiqueDames):
|
||||
"""
|
||||
Logique du jeu de Dames (Anglaises)
|
||||
"""
|
||||
CASES_COTE = 8
|
||||
RANGEES = 3
|
||||
PRISE_ARRIERE = False
|
||||
DEPL_LONG_DAME = False
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
Constructeur de LogiqueDamesAnglaises
|
||||
"""
|
||||
LogiqueDames.__init__(self)
|
||||
|
||||
class LogiqueEchecs(Logique):
|
||||
"""
|
||||
Logique du jeu d'Échecs
|
||||
|
|
Reference in a new issue