示例#1
0
    def _finish_move(self, piece, dest, p1, p2):
        enemy = self.get_enemy(piece.colour)
        if piece.colour == 'black':
            self.fullmove_number += 1
        self.halfmove_clock += 1
        self.player_turn = enemy
        abbr = piece.symbol
        if abbr == 'P':
            abbr = ''
            self.halfmove_clock = 0
        if dest is None:
            movetext = abbr + p2.lower()
        else:
            movetext = abbr + 'x' + p2.lower()
            self.halfmove_clock = 0
        if isinstance(piece, pieces.King):
            if piece.colour == 'white':
                self.whitekmove = True
            if piece.colour == 'black':
                self.blackkmove = True

        if isinstance(piece, pieces.Rook):
            if piece.colour == 'white':
                if p1 == "H1":
                    self.whitermove[1] = True
                elif p1 == "A1":
                    self.whitermove[0] = True
            if piece.colour == 'black':
                if p1 == "H8":
                    self.blackrmove[1] = True
                elif p1 == "H1":
                    self.blackrmove[0] = True
        if isinstance(piece, pieces.Pawn):
            new_piece = ""
            if piece.colour == "white":
                if p2[1] == "8":
                    while new_piece == "":
                        new_piece = input(
                            "Your pawn has reached the other end! Upgrade to: "
                        ).upper()
                        if new_piece not in ["P", "R", "N", "B", "Q"]:
                            new_piece = ""
                            print("Enter a valid upgrade!")
                    self[p2] = pieces.piece(new_piece.upper())
                    self[p2].place(self)

            if piece.colour == "black":
                if p2[1] == "1":
                    while new_piece == "":
                        new_piece = input(
                            "Your pawn has reached the other end! Upgrade to: "
                        ).lower()
                        if new_piece not in ["p", "r", "n", "b", "q"]:
                            new_piece = ""
                            print("Enter a valid upgrade!")
                    self[p2] = pieces.piece(new_piece.lower())
                    self[p2].place(self)

        self.history.append(movetext)
示例#2
0
文件: board.py 项目: Crysris/algo
    def load(self, fen):
        '''
            Import state from FEN notation
        '''
        self.clear()
        # Split data
        fen = fen.split(' ')

        # Expand blanks
        def expand(match):
            return ' ' * int(match.group(0))

        fen[0] = re.compile(r'\d').sub(expand, fen[0])

        for x, row in enumerate(fen[0].split('/')):
            for y, letter in enumerate(row):
                if letter == ' ':
                    continue
                coord = self.letter_notation((7 - x, y))
                self[coord] = pieces.piece(letter)
                self[coord].place(self)

        if fen[1] == 'w':
            self.player_turn = 'white'
        else:
            self.player_turn = 'black'

        self.castling = fen[2]
        self.en_passant = fen[3]
        self.halfmove_clock = int(fen[4])
        self.fullmove_number = int(fen[5])
示例#3
0
    def __init__(
            self,
            fen='rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'):
        self.clear()
        fen = fen.split(' ')

        def expand(match):
            return ' ' * int(match.group(0))

        fen[0] = re.compile(r'\d').sub(expand, fen[0])
        for x, row in enumerate(fen[0].split('/')):
            for y, letter in enumerate(row):
                if letter == ' ':
                    continue
                coord = self.letter_notation((7 - x, y))
                self[coord] = pieces.piece(letter)
                self[coord].place(self)
        if fen[1] == 'w':
            self.player_turn = 'white'
        else:
            self.player_turn = 'black'
        self.castling = fen[2]
        self.en_passant = fen[3]
        self.halfmove_clock = int(fen[4])
        self.fullmove_number = int(fen[5])
示例#4
0
    def load(self, fen):
        '''
            Import state from FEN notation
        '''
        self.clear()
        # Split data
        fen = fen.split(' ')
        # Expand blanks
        def expand(match): return ' ' * int(match.group(0))

        fen[0] = re.compile(r'\d').sub(expand, fen[0])

        for x, row in enumerate(fen[0].split('/')):
            for y, letter in enumerate(row):
                if letter == ' ': continue
                coord = self.letter_notation((7-x,y))
                self[coord] = pieces.piece(letter)
                self[coord].place(self)

        if fen[1] == 'w': self.player_turn = 'white'
        else: self.player_turn = 'black'

        self.castling = fen[2]
        self.en_passant = fen[3]
        self.halfmove_clock = int(fen[4])
        self.fullmove_number = int(fen[5])
示例#5
0
    def render(self, context):
        """
        """
        offset = 0
        matrix = context.get_matrix()
        x = (self.pos[0] - 4) * self.scene.squareSize
        y = (3 - self.pos[1]) * self.scene.squareSize
        context.translate(x, y)
        context.translate(self.scene.squareSize / 2, self.scene.squareSize / 2)
        context.rotate(-self.scene.angle)
        context.translate(-self.scene.squareSize / 2, -self.scene.squareSize / 2)

        # If Face to Face mode is enabled, we rotate the black player's pieces by 180 degrees
        if self.scene.faceToFace and self.name.find('black') != -1:
            context.rotate(math.pi)
            offset -= self.scene.pieceSize
        pieces.piece(self.name, context, self.scene.pieceSize, offset, offset)
        context.fill()
        context.set_matrix(matrix)
示例#6
0
    def render(self, context):
        """
        """
        offset = 0
        matrix = context.get_matrix()
        x = (self.pos[0] - 4) * self.scene.squareSize
        y = (3 - self.pos[1]) * self.scene.squareSize
        context.translate(x, y)
        context.translate(self.scene.squareSize / 2, self.scene.squareSize / 2)
        context.rotate(-self.scene.angle)
        context.translate(-self.scene.squareSize / 2,
                          -self.scene.squareSize / 2)

        # If Face to Face mode is enabled, we rotate the black player's pieces by 180 degrees
        if self.scene.faceToFace and self.name.find('black') != -1:
            context.rotate(math.pi)
            offset -= self.scene.pieceSize
        pieces.piece(self.name, context, self.scene.pieceSize, offset, offset)
        context.fill()
        context.set_matrix(matrix)
示例#7
0
文件: chessboard.py 项目: Calarey/gui
 def expand_whitespaces(match):
     return " " * int(match.group(0))
     patt[0] = re.compile(r'\d').sub(expand_whitespaces, patt[0])
     for x, row in enumerate(patt[0].split('/')):
         for y, alphabet in enumerate(row):
             if alphabet == " ": continue
             xycoord = self.alpha_notation(7 - x, y)
             self[xycoord] = pieces.piece(alphabet)
             self[xycoord].ref(self)
         if patt[1] == "w":
             self.player_turn = "white"
         else:
             self.player_turn = "black"
示例#8
0
#!/opt/local/bin/python
import os
import itertools
import time
import numpy as np
from pieces import piece

#get the pieces from the file
pieces = {}
for i in os.listdir('.'):
	if i.count('piece') and i.count('dat'):
		pieces[int(i.split('piece')[1].split('.dat')[0])]={'p0':piece(filename=i)}

#Compute all possible orientations for each piece
print "Calculating orientations"
for i in pieces:
	pieces[i]['ori'] = []
	#rotate about axis 1 to access all four faces
	for j in [0,90,180,270]:
		P=pieces[i]['p0'].rotate(1,j)
		for k in [0,90,180,270]:
			pieces[i]['ori'].append(P.rotate(0,k))
	for j in [90,270]:
		P=pieces[i]['p0'].rotate(2,j)
		for k in [0,90,180,270]:
			pieces[i]['ori'].append(P.rotate(0,k))

#compute all possible solutions
print "padding with zeros"
for i in pieces:
	pieces[i]['confs'] = []
示例#9
0
    "d2": board[6][3],
    "e2": board[6][4],
    "f2": board[6][5],
    "g2": board[6][6],
    "h2": board[6][7],
    "a1": board[7][0],
    "b1": board[7][1],
    "c1": board[7][2],
    "d1": board[7][3],
    "e1": board[7][4],
    "f1": board[7][5],
    "g1": board[7][6],
    "h1": board[7][7],
}

white_pawn = pieces.piece("white", "pawn")
white_horse = pieces.piece("white", "horse")
white_bishop = pieces.piece("white", "bishop")
white_rook = pieces.piece("white", "rook")
white_queen = pieces.piece("white", "queen")
white_king = pieces.piece("white", "king")

black_pawn = pieces.piece("black", "pawn")
black_horse = pieces.piece("black", "horse")
black_bishop = pieces.piece("black", "bishop")
black_rook = pieces.piece("black", "rook")
black_queen = pieces.piece("black", "queen")
black_king = pieces.piece("black", "king")


def input_move_white(player_white, board_coord, turn, current_board):