Exemplo n.º 1
0
    def insert(self, text, index):
        if not len(text):
            return
        # Finding piece that overlaps the given index
        pieceIndex, pieceOffset = self.getPieceIndexAndOffset(index)
        current = self.pieces[pieceIndex]

        # Append text to added buffer
        added_offset = len(self.buffer)
        self.buffer += text
        self.textLength += len(text)

        # If insertion is at the end and the piece points to the end of the add buffer,
        # just increase the length
        if (current.inBuffer and pieceOffset == current.offset + current.length
                == added_offset):
            current.length += len(text)
            return

        # Spliting into three pieces
        insertPiece = []
        insertPiece.append(
            Piece(current.inBuffer, current.offset,
                  pieceOffset - current.offset))
        insertPiece.append(Piece(True, added_offset, len(text)))
        insertPiece.append(
            Piece(current.inBuffer, pieceOffset,
                  current.length - (pieceOffset - current.offset)))
        insertPiece = list(filter(lambda piece: piece.length > 0, insertPiece))
        self.pieces = self.replacePieces(pieceIndex, 1, insertPiece)
Exemplo n.º 2
0
 def create_active_piece(self):
     if len(self.next_piece.shape) < 1:
         self.active_piece = Piece(self.get_random_shape(), -1, 0)
         self.next_piece = Piece(self.get_random_shape(), -1, 0)
     else:
         self.active_piece = self.next_piece
         self.next_piece = Piece(self.get_random_shape(), -1, 0)
Exemplo n.º 3
0
	def __init__(self, name, color, ID, location, deathLoc):
		Piece.__init__(self, name, color, ID, location, deathLoc)
		self.just_moved_two = False
		self.updates_since_moved_two = 0
		self.on_fifth_rank = False
		self.can_en_passant_left = False
		self.can_en_passant_right = False
Exemplo n.º 4
0
 def __init__(self, board_square, color, board):
     Piece.__init__(self, board_square, color, board)
     if color == 'black':
         self.image = pygame.image.load("../Display/Black King.png")
     else:
         self.image = pygame.image.load("../Display/White King.png")
     self.has_moved = False
Exemplo n.º 5
0
    def move_piece(self, x1, y1, x2, y2, sym=False):
        """
        Moving piece on a board. If x2=='c' and y2=='a' then castling.
        :param x1: Int. First board's coordinate of piece player want to move.
        :param y1: Int. Second board's coordinate of piece player want to move.
        :param x2: Int. First board's coordinate of square that player want to move on.
        :param y2: Int. Second board's coordinate of square that player want to move on.
        :param sym: Boolean. Declaring if this function is called in simulation (default: False).
        :return: Boolean. True if move has been done, or false if hasn't.
        """
        if x2 + y2 == 'ca':
            return self.castling(x1, y1, self.turn)
        elif self._board[x1][y1].move(x2, y2, self.turn):
            self._board[x2][y2] = self._board[x1][y1]
            self._board[x1][y1] = Piece(x1, y1, self)
            if isinstance(self._board[x2][y2], Pawn):
                if (x2, y2) in self._board[x2][y2].fly:
                    self._board[x2][y2 - 1] = Piece(x2, y2 - 1, self)
            if isinstance(self._board[x2][y2],
                          Pawn) and (y2 == 0 or y2 == 7) and not sym:
                self.evolve(x2, y2)

            return True
        else:
            return False
Exemplo n.º 6
0
def newShadow(piece):
    global shadow_piece

    shadow = Piece(clock, piece=piece)
    shadow_sprites.add(shadow.getSprites())
    shadowMove(shadow, hard_drop_key)
    shadow_piece = shadow
Exemplo n.º 7
0
    def putPiece(self):  # put the Men in their place
        size = self.size / 8  # size of piece
        put = True
        for i in range(3):  # this for make AI's Men
            put = not put
            for j in range(self.cols):
                if put:
                    id = self.create_oval(j * size + 4,
                                          i * size + 4,
                                          j * size + size - 4,
                                          i * size + size - 4,
                                          fill="black")  # 4 is border
                    if not self.is_single_player:
                        self.tag_bind(id, "<ButtonPress-1>",
                                      self.onClick)  # on click handler
                    self.pieces[i][j] = Piece(i, j, True, id)
                put = not put
        put = False
        for i in range(7, 4, -1):  # this for make Player's men
            put = not put
            for j in range(self.cols):
                if put:
                    id = self.create_oval(j * size + 4,
                                          i * size + 4,
                                          j * size + size - 4,
                                          i * size + size - 4,
                                          fill="red")
                    self.tag_bind(id, "<ButtonPress-1>",
                                  self.onClick)  # on click handler
                    self.pieces[i][j] = Piece(i, j, False, id)

                put = not put
Exemplo n.º 8
0
    def __init__(self, color):
        """Initializes the piece with the passed color."""

        possible_moves = [[2, 2], [2, -2], [-2, 2], [-2, -2]]
        possible_jumps = [[[1, 1]], [[1, -1]], [[-1, 1]], [[-1, -1]]]

        Piece.__init__(self, color, "E", possible_moves, possible_jumps)
Exemplo n.º 9
0
 def initializePieces(self):
     #initialize both the object stored in Mattrix
     for i in initialPosition:
         for j in initialPosition[i]:
             self.pieces[j[1]][j[0]] = Piece(self.surf, i, 0, j[0], j[1],
                                             self.cellSize)
             self.pieces[self.Row - j[1]][j[0]] = Piece(
                 self.surf, i, 1, j[0], self.Row - j[1], self.cellSize)
    def initialise_pieces(self, size):
        
        # corener pieces
        top_left = Piece("flat", "outside", "outside", "flat")
        top_right = Piece("flat", "outside", "flat", "outside")
        bottom_left = Piece("outside", "flat", "outside", "flat")
        bottom_right = Piece("outside", "flat", "outside", "flat")

        pieces = [top_left, top_right, bottom_left, bottom_right]
Exemplo n.º 11
0
 def assignCoordinates(self):
     for row in range(self.BOARD_ROW_SIZE):
         for col in range(self.BOARD_COL_SIZE):
             if self.board[row][col] == 'X':
                 self.corner.addPiece(Piece("corner", col, row))
             elif self.board[row][col] == 'O':
                 self.white.addPiece(Piece("white", col, row))
             elif self.board[row][col] == '@':
                 self.black.addPiece(Piece("black", col, row))
Exemplo n.º 12
0
    def __init__(self, length=16):
        self.board = [[None for _ in range(length + 2)] for _ in range(length + 2)]
        for i in range(length + 2):
            self.board[0][i] = Piece(0, ['X'] * 4, Piece.DOWN, [-1, i - 1])
            self.board[length + 1][i] = Piece(0, ['X'] * 4, Piece.DOWN, [length, i - 1])

        for i in range(length):
            self.board[1 + i][0] = Piece(0, ['X'] * 4, Piece.DOWN, [i, -1])
            self.board[1 + i][length + 1] = Piece(0, ['X'] * 4, Piece.DOWN, [i, length])
Exemplo n.º 13
0
 def spawnPiece(self):
     p = None
     if self.nextPieceToCome == None:
         p = Piece(random.randint(1, 7), datetime.timestamp(datetime.now()))
     else:
         p = self.nextPieceToCome
     self.nextPieceToCome = Piece(random.randint(1, 7),
                                  datetime.timestamp(datetime.now()))
     p.move((4, 0))
     self.pieces.append(p)
     self.current_piece = p
Exemplo n.º 14
0
    def __init__(self, testBoard=None):
        """Creates standard starting position or custom position"""
        if (testBoard == None):
            self.blackPieces = self.getStartingBlackPieces()
            self.whitePieces = self.getStartingWhitePieces()
            self.blackKing = Piece("black", "king", 0,
                                   4)  #direct access to kings for
            self.whiteKing = Piece("black", "king", 7, 4)  #checkmate checks

        else:
            self.blackPieces = self.makeCustonBlackPieces(testBoard)
            self.whitePieces = self.makeCustonWhitePieces(testBoard)
Exemplo n.º 15
0
class Square(object):

	'''
	Docstring goes here

	'''


	def __init__(self, size, col, row, piece, **styles):

		'''
		Docstring goes here

		'''

		# TODO: Move styles to render method
		# TODO: Reduce to single expression or move to method
		self.styles = {
			# Tkinter
			'fill': ('grey', 'white')[col%2==row%2],
			'width': 0,

			# Other (will be removed during initialization)
			'hlFill': ('blue', 'cyan')[col%2==row%2]
		}

		self.styles.update(styles)

		self.size = size
		self.col = col
		self.row = row
		self.piece = Piece(piece) if piece != ' ' else None # TODO: Decide how to handle empty squares
		self.id = None # Canvas item ID

		# TODO: More generic handling of styles and highlighting
		self.highlighted = False
		self.hlFill = self.styles.pop('hlFill') # Highlight fill colour


	def render(self, canvas):
		
		'''
		Docstring goes here

		'''

		col, row, size = self.col, self.row, self.size

		self.coords = (col*size, row*size, (col+1)*size, (row+1)*size)
		self.id = canvas.create_rectangle(self.coords, **self.styles)
		if self.piece is not None:
			self.piece.render(canvas, size, self.col, self.row)
Exemplo n.º 16
0
def draw():
    running = True
    while running:
        for event in pygame.event.get():
            if event.type == QUIT:
                running = False
            if event.type == MOUSEBUTTONDOWN:
                try:
                    global boards, prev_data, prev_piece
                    piece_data = screen_to_piece(mouse.get_pos())  # Current pos
                    if not piece_data:
                        print("Selected nothing")
                        if prev_piece:
                            draw_piece(prev_piece)
                            prev_data = None
                            prev_piece = None
                        continue
                    piece_pos, board_pos = piece_data
                    current_board = boards[board_pos[1] + board_pos[0] * 2]
                    current_piece = current_board.get_piece(piece_pos)
                    if not prev_data:
                        if not current_piece:
                            print("Selected nothing")
                            continue
                        prev_data = piece_data
                        prev_piece = current_piece
                        draw_piece(Piece(Vector2(piece_pos), "select", Vector2(board_pos)))  # draw the select
                    else:
                        if prev_data == piece_data or board_pos != prev_data[1] or not piece_pos:
                            draw_piece(prev_piece)  # draw the select
                            print("2 bad")
                        else:
                            # TODO MAKE DIFFERENT COLOR
                            if board_pos[0] == 0:
                                empty_space = Piece(Vector2(prev_data[0]), "white_board", Vector2(prev_data[1]))
                            else:
                                empty_space = Piece(Vector2(prev_data[0]), "black_board", Vector2(prev_data[1]))
                            draw_piece(empty_space)
                            current_board.move_piece(prev_data[0], piece_pos)
                            current_piece = current_board.get_piece(piece_pos)
                            draw_piece(current_piece)

                            # print("3d pog", current_board)
                        prev_data = None



                except TypeError as E:
                    raise E
                    print("Cannot draw on black", E)
        display.flip()
    quit()
Exemplo n.º 17
0
    def __init__(self):
        self.board = Board()
        self.opponent_piece = Piece()
        self.piece = Piece()
        self.sock = Client()
        self.data = Data()

        self.sock.connect()

        self.addThread(self.checkMove)
        self.addThread(self.checkData)

        self.board.mainloop()
Exemplo n.º 18
0
    def MakeList(self, file, puzzleNum):
        # get all lines from input file
        lines = file.readlines()

        # split all idv input lines into lists
        for j in range(0, len(lines)):
            lines[j] = lines[j].split()

        if (puzzleNum == 1):
            startList = [None] * int(len(lines) - 1)
            dictionary = {}
        elif (puzzleNum == 2):
            startList = [None] * (len(lines))
            startList[0] = float(lines[0][0])
            dictionary = {(startList[0]): 1}
        elif (puzzleNum == 3):
            startList = [None] * (len(lines))
            startList[0] = Piece(lines[0][0], int(lines[0][1]),
                                 int(lines[0][2]), int(lines[0][3]), 0)
            dictionary = {startList[0].getDictKey(): 1}

        # assign values from lines into starting list
        for k in range(1, len(lines)):
            if (puzzleNum == 1):
                if (k == len(lines) - 1):
                    startList[k - 1] = int(lines[k][0])
                    dictionary = self.updateDictionary(dictionary,
                                                       int(lines[k][0]))
                    break

                startList[k - 1] = int(lines[k][0])
                dictionary = self.updateDictionary(dictionary,
                                                   int(lines[k][0]))

            elif (puzzleNum == 2):
                startList[k] = float(lines[k][0])
                dictionary = self.updateDictionary(dictionary,
                                                   float(lines[k][0]))
            elif (puzzleNum == 3):
                startList[k] = Piece(lines[k][0], int(lines[k][1]),
                                     int(lines[k][2]), int(lines[k][3]), k)
                dictionary = self.updateDictionary(dictionary,
                                                   startList[k].getDictKey())

        # Return a tuple of all important info
        if (puzzleNum == 1):
            return (startList, dictionary, int(lines[0][0]))
        elif (puzzleNum == 2):
            return (startList, dictionary, 0)
        elif (puzzleNum == 3):
            return (startList, dictionary, 0)
Exemplo n.º 19
0
    def delete(self, index, length):

        if length == 0:
            return
        if length < 0:
            self.delete(index + length, -length)
            return
        if index < 0:
            raise IndexError("Text index out of range")

        # Get overlapping pieces
        startIndex, startOffset = self.getPieceIndexAndOffset(index)
        stopIndex, stopOffset = self.getPieceIndexAndOffset(index + length)
        self.textLength -= length

        # If single piece, check if delete is at the start or end the piece
        if startIndex == stopIndex:
            piece = self.pieces[startIndex]

            if startOffset == piece.offset:
                piece.offset += length
                piece.length -= length
                return
            elif stopOffset == piece.offset + piece.length:
                piece.length -= length
                return

        startPiece = self.pieces[startIndex]
        endPiece = self.pieces[stopIndex]

        # Spliting into two pieces
        deletePieces = []
        deletePieces.append(
            Piece(startPiece.inBuffer, startPiece.offset,
                  startOffset - startPiece.offset))
        deletePieces.append(
            Piece(
                startPiece.inBuffer,
                startPiece.offset,
                startOffset - startPiece.offset,
            ))
        deletePieces.append(
            Piece(endPiece.inBuffer, stopOffset,
                  endPiece.length - (stopOffset - endPiece.offset)))

        deletePieces = list(
            filter(lambda piece: piece.length > 0, deletePieces))

        delete_count = stopIndex - startIndex + 1
        self.pieces = self.replacePieces(startIndex, delete_count,
                                         deletePieces)
Exemplo n.º 20
0
def test():
    board = Board()
    black_pieces = [Piece('black') for _ in range(8)]
    white_pieces = [Piece('white') for _ in range(8)]
    board.place(black_pieces.pop(), 2, 0)
    board.place(white_pieces.pop(), 2, 1)
    board.place(white_pieces.pop(), 2, 2)
    board.place(white_pieces.pop(), 2, 3)
    board.place(black_pieces.pop(), 2, 4)
    board.print_board()
    print('running flip_row')
    tiles = board.flip_rows(2, 0, 'p', 'y')
    print('flip_row done running')
    print(board)
Exemplo n.º 21
0
    def add_piece(self, piece: Piece, position: Position, player: Player):
        """Adds a piece on the board."""

        if piece.name == "King":
            if self.king_mask & 1 << player.value:
                return False
            else:
                self.king_mask |= 1 << player.value

        Guard.check_position(position, self.SIZE)

        piece.set_position(position)
        piece.set_player(player)
        self.board[piece.position.x][piece.position.y] = copy(piece)
Exemplo n.º 22
0
    def __init__(self,size = 3):
        '''
        :param size: Defines the size of the board
        '''
        self.size = size
        self.turn = 1 # Player 1 goes first
        self.player_1_pieces = list()
        for i in range(size):
            if i != size-1:
                self.player_1_pieces.append(Piece(color='black',position=(i,0)))

        self.player_2_pieces = list()
        for i in range(size):
            if i != 0:
                self.player_2_pieces.append(Piece(color='white',position=(size-1,i)))
Exemplo n.º 23
0
 def __init__(self, figure, color, screen):
     self.screen = screen
     width = 5
     height = 5
     self.ACTIVE_PIECE = 1
     self.spic_colors_act = [
         'red', 'blue', 'orange', 'brown', 'purple', 'green', 'yellow'
     ]
     self.next_figure = Piece(figure, 0, 0)
     self.color = color
     self.color += 1
     self.color %= 7
     super().__init__(width, height, left=375, top=115, cell_size=20)
     self.border_color = pygame.Color('white')
     self.render_next_piece()
Exemplo n.º 24
0
    def move(self, move):

        assert self[move.cord0], "%s %s" % (move, self.asFen())

        newBoard = self.clone()
        newBoard.board.applyMove(move.move)

        cord0, cord1 = move.cords
        flag = FLAG(move.move)

        newBoard[cord1] = newBoard[cord0]
        newBoard[cord0] = None

        if self.color == WHITE:
            if flag == QUEEN_CASTLE:
                newBoard[Cord(D1)] = newBoard[Cord(A1)]
                newBoard[Cord(A1)] = None
            elif flag == KING_CASTLE:
                newBoard[Cord(F1)] = newBoard[Cord(H1)]
                newBoard[Cord(H1)] = None
        else:
            if flag == QUEEN_CASTLE:
                newBoard[Cord(D8)] = newBoard[Cord(A8)]
                newBoard[Cord(A8)] = None
            elif flag == KING_CASTLE:
                newBoard[Cord(F8)] = newBoard[Cord(H8)]
                newBoard[Cord(H8)] = None

        if flag in PROMOTIONS:
            newBoard[cord1] = Piece(self.color, PROMOTE_PIECE(flag))

        elif flag == ENPASSANT:
            newBoard[Cord(cord1.x, cord0.y)] = None

        return newBoard
Exemplo n.º 25
0
    def load(self, iFileName):

        dutyDataExist = os.path.isfile(iFileName)

        if not dutyDataExist:
            file = open(iFileName, 'w+')
            file.close()
            return

        file = open(iFileName, 'r')

        for line in file:
            if line != '\n':
                lineSplit = line.split(';')

                taskId = lineSplit[0]
                taskPrjCode = lineSplit[1]
                title = lineSplit[2]

                currDtyDate = datetime.datetime.now()
                formatDateTime = '%Y-%m-%d %H:%M:%S'

                startTime = datetime.datetime.strptime(
                    currDtyDate + ' ' + lineSplit[3], formatDateTime)
                endTime = datetime.datetime.strptime(
                    currDtyDate + ' ' + lineSplit[4].rstrip('\n'),
                    formatDateTime)

                newTask = Task(taskPrjCode, title, taskId)
                newPiece = Piece(newTask, startTime, endTime)

                self.addPiece(newPiece)

        file.close()
Exemplo n.º 26
0
	def get_moves(piece, x, y, board):
		coords = [
			(x - 1, y),
			(x + 1, y),
			(x - 1, y + Piece.y_dir(piece)),
			(x, y + Piece.y_dir(piece)),
			(x + 1, y + Piece.y_dir(piece)),
			(x, y + -1 * Piece.y_dir(piece))
		]

		moves = []
	
		for coord in coords:
			if Piece.check(piece, coord[0], coord[1], board):
				moves += [coord]
		return moves
Exemplo n.º 27
0
    def is_checkmate(self, colour, board, depth):
        if colour == 'white':
            opponent_possible_moves = self.get_all_moves('black')
        else:
            opponent_possible_moves = self.get_all_moves('white')
        player_possible_moves = self.get_all_moves(colour)
        king_pos = ()
        # Gets all possible moves for each player
        for i in range(8):
            for j in range(8):
                piece = board.board[i][j]
                if piece is not None:
                    if piece.colour == colour and piece.type == 'king':
                        king_pos = (i, j)

        king = board.board[king_pos[0]][king_pos[1]]
        if king_pos in opponent_possible_moves:
            print('check')
            for move in king.get_moves(board, (king_pos[0], king_pos[1])):
                if (king_pos[0] + move[0],
                        king_pos[1] + move[1]) not in opponent_possible_moves:
                    return False
            if depth == 0:
                for move in player_possible_moves:
                    test_board = Board(self.board)
                    test_board.board[move[0]][move[1]] = Piece(
                        'pawn', 'white_pawn.png', colour)
                    if not self.is_checkmate(colour, test_board, 1):
                        return False
                    print('can kill to escape')
            print(colour, 'checkmate')
            return True
        else:
            return False
Exemplo n.º 28
0
def read(file):

    with open(file, 'r') as f:
        if os.stat(file).st_size == 0:
            raise FileNotFoundError
        lines = f.readlines()
        B = [[None for x in range(16)] for y in range(9)]
        for line in lines:
            line = line.strip('\n')
            l = line.split(';')
            x = int(int(l[1]) / 100)
            y = int(int(l[2]) / 100)
            if l[0] == 'wall':
                e = Wall(x, y)
                e.up = to_rgb(l[3])
                e.left = to_rgb(l[4])
                e.down = to_rgb(l[5])
                e.right = to_rgb(l[6])
                e.color = to_rgb(l[7])
                B[x][y] = e
            if l[0] == 'piece':
                e = Piece(x, y)
                e.up = to_rgb(l[3])
                e.left = to_rgb(l[4])
                e.down = to_rgb(l[5])
                e.right = to_rgb(l[6])
                if int(l[7]) == 1:
                    e.upside = True
                B[x][y] = e
            if l[0] == 'blank':
                e = Blank(x, y)
                B[x][y] = e
    return B
def test_add_ok():
    board = Board(3)
    piece = Piece()

    board.add(piece)

    assert len(board.pieces) == 1
    assert piece in board.pieces
Exemplo n.º 30
0
 def add(self, x, y):
     piece = Piece(self.TURN, x, y)
     if self.inBounds(piece) and self.board[piece.x][piece.y] == 0:
         self.board[piece.x][piece.y] = piece.player
         self.checkWin(piece)  # check for win after every piece is added
         self.TURN = -(self.TURN)  # switch player turns
         return True
     return False  # probably better to throw an exception
Exemplo n.º 31
0
 def hardDrop(self):
     while not self.board.checkIfSet(self.p):
         self.p.moveDown()
         self.board.addCellsTemp(self.p)
     self.board.addCells(self.p)
     self.gameover = self.board.checkIfGameOver()
     if self.gameover:
         x = 1
     self.board.checkCompleteRows()
     self.p = self.pNext
     self.pNext = Piece(self.width, self.height,
                        random.choice(self.pieceSelect), self.board)
     self.pNext.genBoard()
     self.board.addCellsTemp(self.p)
     while not self.shouldGameTick(self.steps):
         self.steps += 1
     self.steps += 1
Exemplo n.º 32
0
 def __init__(self, x_pos, y_pos, side_length, bgcolor):
     self.sprite = TileSprite(self)
     self.sprite.image = pygame.Surface([side_length, side_length])
     self.sprite.rect = pygame.Rect(x_pos, y_pos, side_length, side_length)
     self.sprite.image.fill(0x444444)
     self.bgcolor = bgcolor
     pygame.draw.rect(self.sprite.image, self.bgcolor, pygame.Rect(1, 1, side_length - 2, side_length - 2))
     self.contents = Piece(None)
Exemplo n.º 33
0
 def __init__(self):
     self.height = Consts.BOA_HEIGHT
     self.width = Consts.BOA_WIDTH
     self.nextPiece = Piece.nextPiece(Consts.BOA_DEFAULT_SPAWN)
     self.setCurrentPiece()
     self.storage = None
     self.acceleration = False
     self.field = array.array(Consts.BOA_FIELD_TYPECODE)
     self.__ResetBoard()
Exemplo n.º 34
0
	def __init__(self, image, team):
		Piece.__init__(self, image, team)
Exemplo n.º 35
0
 def __str__(self):
   return Piece.__str__(self).'Knight'
Exemplo n.º 36
0
    def move (self, move, lboard=None):
        """ Creates a new Board object cloning itself then applying
            the move.move to the clone Board's lboard.
            If lboard param was given, it will be used when cloning,
            and move will not be applyed, just the high level Piece
            objects will be adjusted.""" 

        # Sequence nubers of next newHoldingCord of WHITE and BLACK
        nth = [0, 0]

        flag = FLAG(move.move)
        if flag != DROP:
            assert self[move.cord0], "%s %s" % (move, self.asFen())
        
        newBoard = self.clone(lboard=lboard)
        if lboard is None:
            newBoard.board.applyMove (move.move)

        cord0, cord1 = move.cords

        if self[move.cord1] is not None or flag == ENPASSANT:
            if self.variant == CRAZYHOUSECHESS:
                piece = PAWN if flag == ENPASSANT or self[move.cord1].promoted else self[move.cord1].piece
                new_piece = Piece(self.color, piece)
            else:
                piece = PAWN if flag == ENPASSANT else self[move.cord1].piece
                new_piece = Piece(1-self.color, piece)
            nth[self.color] += 1
            newBoard[self.newHoldingCord(self.color, nth[self.color])] = new_piece
            
            if self.variant == ATOMICCHESS:
                from pychess.Variants.atomic import cordsAround
                for acord in cordsAround(move.cord1):
                    piece = self[acord]
                    if piece and piece.piece != PAWN and acord != cord0:
                        new_piece = Piece(piece.color, piece.piece)
                        nth[1-piece.color] += 1
                        newBoard[self.newHoldingCord(1-piece.color, nth[1-piece.color])] = new_piece
                        newBoard[acord] = None
        
        if flag == DROP:
            piece = FCORD(move.move)
            hc = self.getHoldingCord(self.color, piece)
            if hc is None:
                newBoard[cord1] = Piece(self.color, piece)
            else:
                newBoard[cord1] = newBoard[self.getHoldingCord(self.color, piece)]
                newBoard[self.getHoldingCord(self.color, piece)] = None
        else:
            if self.variant == ATOMICCHESS and (flag == ENPASSANT or self[move.cord1] is not None):
                piece = self[move.cord0].piece
                new_piece = Piece(self.color, piece)
                nth[1-self.color] += 1
                newBoard[self.newHoldingCord(1-self.color, nth[1-self.color])] = new_piece
                newBoard[cord1] = None
            else:
                newBoard[cord1] = newBoard[cord0]
            
        if flag != NULL_MOVE and flag != DROP:
            newBoard[cord0] = None
        
        if flag in (QUEEN_CASTLE, KING_CASTLE):
            side = flag - QUEEN_CASTLE
            if FILE(cord0.x) == 3 and self.board.variant in (WILDCASTLECHESS, WILDCASTLESHUFFLECHESS):
                side = 0 if side == 1 else 1
            inirook = self.board.ini_rooks[self.color][side]
            finrook = self.board.fin_rooks[self.color][side]
            newBoard[Cord(finrook)] = newBoard[Cord(inirook)]
            newBoard[Cord(inirook)] = None

        if flag in PROMOTIONS:
            new_piece = Piece(self.color, PROMOTE_PIECE(flag))
            new_piece.promoted = True
            newBoard[cord1] = new_piece
        
        elif flag == ENPASSANT:
            newBoard[Cord(cord1.x, cord0.y)] = None
        
        return newBoard
Exemplo n.º 37
0
    def check_free(self):
        # loop through each n-omino
        for ord_c in range(1,6):
            # get free pieces

            ominoes = self.get_pieces(ord_c)
            # loop through each piece
            for piece_i in range(len(ominoes)):
                piece = ominoes[piece_i]
                piece = [[int(math.ceil(float(col)/10)) for col in row] for row in piece]
                piece = Piece.remove_empty(piece)
                
                # check given piece against all other pieces
                for check_i in range(len(ominoes)):
                    # skip, if piece index is same as check index
                    if piece_i==check_i:
                        continue

                    # loop through all possible configurations (rotations/translations)
                    confs = range(0,8)
                    for conf_i in confs:
                        
                        # grab piece to check against
                        check = ominoes[check_i]
                        check = [[int(math.ceil(float(col)/10)) for col in row] for row in check]
                        check = Piece.remove_empty(check)
                        
                        if conf_i==0:
                            pass
                        elif conf_i==1:
                            check = Piece.rot_90(check)
                        elif conf_i==2:
                            check = Piece.rot_180(check)
                        elif conf_i==3:
                            check = Piece.rot_270(check)
                        elif conf_i==4:
                            check = Piece.mirror_horz(check)
                        elif conf_i==5:
                            check = Piece.mirror_horz(check)
                            check = Piece.rot_90(check)
                        elif conf_i==6:
                            check = Piece.mirror_vert(check)
                        elif conf_i==7:
                            check = Piece.mirror_vert(check)
                            check = Piece.rot_90(check)
                            
                        if piece==check:
                            print 'identical pieces found. {0},{1},{2},{3}'.format(
                                ord_c,piece_i,check_i,conf_i)
                            print piece
                            print check
Exemplo n.º 38
0
	def __init__(self,team):
		self.name = "Q" + str(team)
		Piece.__init__(self,team)
Exemplo n.º 39
0
 def __eq__(self, other):
   oldEq = Piece.__eq__(self, other)
   if oldEq and self.moved == other.moved:
     return True
   return False
Exemplo n.º 40
0
Arquivo: Rook.py Projeto: jadmz/PChess
	def __init__(self, xpos, ypos, team):
		Piece.__init__(self,xpos,ypos,team,"Rook", False, None)
Exemplo n.º 41
0
	def __init__(self, name, color, ID, location, deathLoc):
		Piece.__init__(self, name, color, ID, location, deathLoc)
		self.posMoves = [] #List of possible moves
Exemplo n.º 42
0
     for color_i in colors:
             
         # loop through each configuration
         for conf_i in confs:
 
             # skip configurations that aren't unique
             if ord_c<=1 and conf_i>=1:
                 continue
             if ord_c<=2 and conf_i>=2:
                 continue
             if ord_c<=3 and conf_i>=4:
                 continue
 
             # get current piece & remove empty rows/cols
             tiles = ominoes[omino_i];
             tiles = Piece.remove_empty(tiles)
             
             # rotate/mirror current piece
             if conf_i==0:
                 pass
             elif conf_i==1:
                 tiles = Piece.rot_90(tiles)
             elif conf_i==2:
                 tiles = Piece.rot_180(tiles)
             elif conf_i==3:
                 tiles = Piece.rot_270(tiles)
             elif conf_i==4:
                 tiles = Piece.mirror_horz(tiles);
             elif conf_i==5:
                 tiles = Piece.mirror_horz(tiles);
                 tiles = Piece.rot_90(tiles)
Exemplo n.º 43
0
	def __init__(self, name, color, ID, location, deathLoc):
		Piece.__init__(self, name, color, ID, location, deathLoc)
Exemplo n.º 44
0
	def __init__(self, col, row, color, piece = "king"):	# color 1 => BLACK / color 0 => WHITE
		Piece.__init__(self, col, row, color, piece)
Exemplo n.º 45
0
	def __init__(self, xpos, ypos,team):
		Piece.__init__(self,xpos,ypos,team, "Knight", True, None)
Exemplo n.º 46
0
	def __init__(self, xpos,ypos, team):
		Piece.__init__(self,xpos,ypos,team, "Bishop", False, None)
Exemplo n.º 47
0
	def __init__(self, image, orientation, team):
		Piece.__init__(self, image, team)
		self.orientation = orientation
Exemplo n.º 48
0
 def __str__(self):
   return Piece.__str__(self).'Bishop'
Exemplo n.º 49
0
	def __init__(self,xpos,ypos,team):

		Piece.__init__(self,xpos,ypos,team, "Queen", False, None)
Exemplo n.º 50
0
 def setCurrentPiece(self):
     self.currentPiece = self.nextPiece
     self.nextPiece = Piece.nextPiece(Consts.BOA_DEFAULT_SPAWN)