Ejemplo n.º 1
0
 def saveFile(self, filename):
     if filename != "":
         file = open(filename, 'w')
         for Y in range(0, 8):
             for X in range(0, 8):
                 pion = self.getPion(X, Y)
                 if (pion != None):
                     file.write(str(X)+","+str(Y)+","+pion.getLetter()+"," + str(pion.getColor()) + "\n")
         file.close()
Ejemplo n.º 2
0
 def checkPat(self, color):
     array = set()
     for X in range(0, 8):
         for Y in range(0, 8):
             pion = self.getPion(X, Y)
             if pion != None and pion.getColor() == color:
                 self._selectedPion = pion
                 pion.move(X, Y, self, array)
                 if len(array) > 0:
                     return False
     return True
Ejemplo n.º 3
0
    def checkMat(self):
	# Find the position of the King to check if he can be in mat position
        for X in range(0, 8):
            for Y in range(0, 8):
                pion = self.getPion(X, Y)
                if type(pion) == roi and ((pion.getColor() == piece._players['NOIR'] and self._curPlayer == -1) or (pion.getColor() == piece._players['BLANC'] and self._curPlayer == 1)):
                    roi_X = X
                    roi_Y = Y
        # Check if by moving a piece, there is still mat position
        for X in range(0, 8):
            for Y in range(0, 8):
                pion = self.getPion(X, Y)
                if pion != None:
                    if (pion.getColor() * self._curPlayer) < 0:
                        posPion = set()
                        pion.move(X, Y, self, posPion)
                        for (posPion_X, posPion_Y) in posPion:
                            oldValue = self.getPion(posPion_X, posPion_Y)
                            self.setPion(posPion_X, posPion_Y, pion)
                            self.setPion(X, Y, None)
                            # compute Possible
                            possibleBlanc = set()
                            possibleNoir = set()
                            self.computePossible(piece._players['NOIR'], possibleNoir)
                            self.computePossible(piece._players['BLANC'], possibleBlanc)
                            self.setPion(X, Y, pion)
                            self.setPion(posPion_X, posPion_Y, oldValue)
                            if (type(pion) == roi):
                                if self._curPlayer == 1 and not self.isPossible(posPion_X, posPion_Y, possibleNoir):
                                    return False
                                if self._curPlayer == -1 and not self.isPossible(posPion_X, posPion_Y, possibleBlanc):
                                    return False
                            else:
                                if self._curPlayer == 1 and not self.isPossible(roi_X, roi_Y, possibleNoir):
                                    return False
                                if self._curPlayer == -1 and not self.isPossible(roi_X, roi_Y, possibleBlanc):
                                    return False
        return True
Ejemplo n.º 4
0
 def checkEchec(self):
     possibleBlanc = set()
     possibleNoir = set()
     self.computePossible(piece._players['NOIR'], possibleNoir)
     self.computePossible(piece._players['BLANC'], possibleBlanc)
     noirEchec=False
     blancEchec=False
     for X in range(0, 8):
         for Y in range(0, 8):
             pion = self.getPion(X, Y)
             if (type(pion) is roi):
                 if (pion.getColor() == piece._players['NOIR'] and self.isPossible(X, Y, possibleBlanc) == 1):
                     noirEchec=True
                 if (pion.getColor() == piece._players['BLANC'] and self.isPossible(X, Y, possibleNoir) == 1):
                     blancEchec=True
     if (noirEchec and blancEchec): #pragma: no cover 
         return self._curPlayer
     elif (noirEchec):
         return piece._players['NOIR']
     elif (blancEchec):
         return piece._players['BLANC']
     else:              
         return 0
Ejemplo n.º 5
0
 def computePossible(self, color, array):
     for X in range(0, 8):
         for Y in range(0, 8):
             pion = self.getPion(X, Y)
             if pion != None and pion.getColor() == color:
                 pion.move(X, Y, self, array)
Ejemplo n.º 6
0
 def setPromoted(self, pion):
     if self._curPlayer != pion.getColor(): #pragma: no cover
         return 0
     self.setPion(self._init_x, self._init_y, pion)