예제 #1
0
    def validMove(self, board, x, y):
        if absPiece.outOfBounds(x, y):
            return False
        elif board.getPiece(x,y).getColor() == board.getPiece(self.xpos, self.ypos).getColor():
            return False
        elif x == self.xpos and y == self.ypos:
            return False
        elif self.pieceInWay(x,y,board):
            return False


        board2 = copy(board)
        board2.setPiece(Queen(x, y, self.color), x, y)
        board2.setPiece(NoPiece(self.xpos, self.ypos), self.xpos, self.ypos)

        if self.color == "white" and board2.whiteKingInCheck:
            return False
        elif self.color == "black" and board2.blackKingInCheck:
            return False

        if abs(y-self.ypos) - abs(x-self.xpos) == 0:
            return True
        if x == self.xpos or y == self.ypos:
            return True
        return True
예제 #2
0
    def validMove(self, board, x, y):
        if absPiece.outOfBounds(x, y):
            #print("out of bounds")
            return False
        elif board.getPiece(x, y).getColor() == self.color:
            #print("same color")
            return False
        elif self.pieceInWay(x, y, board):
            #print("piece in way")
            return False
        elif board.getPiece(x, y).getColor() == oppositeColor(
                self.color) and x - self.xpos == 0:
            #print("opposite color")
            return False
        elif x == self.xpos and y == self.ypos:
            #print("didnt move")
            return False
        elif abs(self.ypos - y) > 2:
            #print("y bigger than 2")
            return False
        elif abs(self.ypos - y) > 1 and self.xpos - x != 0:
            #print("y > 1 and change in x is not 0")
            return False
        elif self.ypos == y:
            # print("y doesnt change")
            return False
        elif abs(self.xpos - x) > 1:
            #print("more than 1")
            return False
        elif abs(self.xpos - x) * abs(self.ypos - y) == 1:
            if board.getPiece(x, y).getColor() == "none" or board.getPiece(
                    x, y).getColor() == self.color:
                #print("capture piece")
                return False

        if self.color == "white":
            if self.ypos - y < 0:
                #print("white piece going down")
                return False

        if self.color == "black":
            if self.ypos - y > 0:
                #print("black piece going up")
                return False

        if not (self.firstmove):
            if abs(y - self.ypos) != 1:
                #print("first move more then one")
                return False

        elif self.willKingInCheck(board, x, y):
            #print("will king in check")
            return False

        return True
예제 #3
0
 def validMove(self, board, x, y):
     if absPiece.outOfBounds(x, y):
         return False
     elif board.getPiece(x,y).getColor() == board.getPiece(self.xpos, self.ypos).getColor():
         return False
     elif abs(y - self.ypos) + abs(y - self.xpos) != 3:
         return False
     elif x == self.xpos and y == self.ypos:
         return False
     elif self.willKingInCheck(board, x, y):
         return False
     return True
예제 #4
0
파일: queen.py 프로젝트: EvanLerner/pychess
    def validMove(self, board, x, y):
        if absPiece.outOfBounds(x, y):
            return False
        elif board.getPiece(x,y).getColor() == board.getPiece(self.xpos, self.ypos).getColor():
            return False
        elif x == self.xpos and y == self.ypos:
            return False
        elif self.pieceInWay(x,y,board):
            return False
        elif not (x == self.xpos or y == self.ypos) and abs(x - self.xpos) != abs(y - self.ypos):
            return False
        elif self.willKingInCheck(board, x, y):
            return False

        return True
예제 #5
0
 def validMove(self, board, x, y):
     if absPiece.outOfBounds(x, y):
         #print("outtabounds")
         return False
     elif board.getPiece(x, y).getColor() == board.getPiece(
             self.xpos, self.ypos).getColor():
         #print("color")
         return False
     elif abs(y - self.ypos) * abs(x - self.xpos) != 2:
         #print("change in x * change in y != 2.... ")
         return False
     elif self.willKingInCheck(board, x, y):
         #print("king in check")
         return False
     return True
예제 #6
0
    def validMove(self, board, x, y):
        if absPiece.outOfBounds(x, y):
            return False
        elif board.getPiece(x, y).getColor() == self.color:
            return False
        elif self.pieceInWay(x, y, board):
            return False
        elif board.getPiece(x, y).getColor() == oppositeColor(
                self.color) and x - self.xpos == 0:
            return False
        elif x == self.xpos and y == self.ypos:
            return False
        elif abs(self.ypos - y) > 2:
            return False
        elif abs(self.ypos - y) > 1 and self.xpos - x != 0:
            return False
        elif self.ypos == y:
            return False
        elif abs(self.xpos - x) > 1:
            return False
        elif abs(self.xpos - x) * (self.ypos - y) == 1:
            if board.getPiece(x, y).getColor() == "none" or board.getPiece(
                    x, y).getColor() == self.color:
                return False

        if self.color == "white":
            if self.ypos - y < 0:
                # print("white piece going down")
                return False

        if self.color == "black":
            if self.ypos - y > 0:
                # print("black piece going up")
                return False

        if not (self.firstmove):
            if abs(y - self.ypos) != 1:
                # print("first move more then one")
                return False

        elif self.willKingInCheck(board, x, y):
            # print("will king in check")
            return False

        return True
예제 #7
0
    def validMove(self, board, x, y):
        if absPiece.outOfBounds(x, y):
            # print("first false")
            return False
        elif board.getPiece(x, y).getColor() == board.getPiece(self.xpos, self.ypos).getColor():
            # print("second false")
            return False
        elif self.pieceInWay(x, y, board):
            # print("third false")
            return False
        elif x == self.xpos and y == self.ypos:
            # print("fourth false")
            return False
        elif abs(x - self.xpos) != abs(y - self.ypos):
            # print("fifth false")
            return False
        elif self.willKingInCheck(board, x, y):
            return False

        return True