Example #1
0
 def _built_board(self):
     colors = ["white", "black"] * (self.cols + 2)
     self.board = [[
         square.Square(i, j, colors[j + i % 2]) for j in range(self.cols)
     ] for i in range(self.rows)]
     # Black pieces
     # Rook, Knight, Bishop, King, Queen, Pawns
     self.board[0][0].set_piece(piece.Rook(self.board[0][0], Board.black))
     self.board[0][7].set_piece(piece.Rook(self.board[0][7], Board.black))
     self.board[0][1].set_piece(piece.Knight(self.board[0][1], Board.black))
     self.board[0][6].set_piece(piece.Knight(self.board[0][6], Board.black))
     self.board[0][2].set_piece(piece.Bishop(self.board[0][2], Board.black))
     self.board[0][5].set_piece(piece.Bishop(self.board[0][5], Board.black))
     self.board[0][3].set_piece(piece.King(self.board[0][3], Board.black))
     self.board[0][4].set_piece(piece.Queen(self.board[0][4], Board.black))
     for j in xrange(0, self.cols):
         self.board[1][j].set_piece(
             piece.Pawn(self.board[1][j], Board.black))
     # White pieces
     # Rook, Knight, Bishop, King, Queen, Pawns
     self.board[7][0].set_piece(piece.Rook(self.board[7][0], Board.white))
     self.board[7][7].set_piece(piece.Rook(self.board[7][7], Board.white))
     self.board[7][1].set_piece(piece.Knight(self.board[7][1], Board.white))
     self.board[7][6].set_piece(piece.Knight(self.board[7][6], Board.white))
     self.board[7][2].set_piece(piece.Bishop(self.board[7][2], Board.white))
     self.board[7][5].set_piece(piece.Bishop(self.board[7][5], Board.white))
     self.board[7][4].set_piece(piece.King(self.board[7][4], Board.white))
     self.board[7][3].set_piece(piece.Queen(self.board[7][3], Board.white))
     for j in xrange(0, self.cols):
         self.board[6][j].set_piece(
             piece.Pawn(self.board[6][j], Board.white))
     self.kings = [self.board[0][3], self.board[7][4]]
Example #2
0
 def initiate(self):
     self.append_piece(piece.Rook('b'), 0, 0)
     self.append_piece(piece.Knight('b'), 0, 1)
     self.append_piece(piece.Bishop('b'), 0, 2)
     self.append_piece(piece.Queen('b'), 0, 3)
     self.append_piece(piece.King('b'), 0, 4)
     self.append_piece(piece.Bishop('b'), 0, 5)
     self.append_piece(piece.Knight('b'), 0, 6)
     self.append_piece(piece.Rook('b'), 0, 7)
     self.append_piece(piece.Pawn('b'), 1, 0)
     self.append_piece(piece.Pawn('b'), 1, 1)
     self.append_piece(piece.Pawn('b'), 1, 2)
     self.append_piece(piece.Pawn('b'), 1, 3)
     self.append_piece(piece.Pawn('b'), 1, 4)
     self.append_piece(piece.Pawn('b'), 1, 5)
     self.append_piece(piece.Pawn('b'), 1, 6)
     self.append_piece(piece.Pawn('b'), 1, 7)
     self.append_piece(piece.Rook('w'), 7, 0)
     self.append_piece(piece.Knight('w'), 7, 1)
     self.append_piece(piece.Bishop('w'), 7, 2)
     self.append_piece(piece.Queen('w'), 7, 3)
     self.append_piece(piece.King('w'), 7, 4)
     self.append_piece(piece.Bishop('w'), 7, 5)
     self.append_piece(piece.Knight('w'), 7, 6)
     self.append_piece(piece.Rook('w'), 7, 7)
     self.append_piece(piece.Pawn('w'), 6, 0)
     self.append_piece(piece.Pawn('w'), 6, 1)
     self.append_piece(piece.Pawn('w'), 6, 2)
     self.append_piece(piece.Pawn('w'), 6, 3)
     self.append_piece(piece.Pawn('w'), 6, 4)
     self.append_piece(piece.Pawn('w'), 6, 5)
     self.append_piece(piece.Pawn('w'), 6, 6)
     self.append_piece(piece.Pawn('w'), 6, 7)
Example #3
0
	def __init__ (self):
		self.board = [[None for _ in range(8)] for _ in range(8)]
		
		self.board[0][0] = ColoredChessPiece("W", piece.Rook(1,1))
		self.board[0][7] = ColoredChessPiece("W", piece.Rook(8,1))
		
		self.board[0][1] = ColoredChessPiece("W", piece.Knight(2,1))
		self.board[0][6] = ColoredChessPiece("W", piece.Knight(7,1))
		
		self.board[0][2] = ColoredChessPiece("W", piece.Bishop(3,1))
		self.board[0][5] = ColoredChessPiece("W", piece.Bishop(6,1))
				
		self.board[0][3] = ColoredChessPiece("W", piece.Queen(4,1))
		self.board[0][4] = ColoredChessPiece("W", piece.King(5,1,5,1))
		
		self.board[1][0] = ColoredChessPiece("W", piece.Pawn(1,2,2))
		self.board[1][1] = ColoredChessPiece("W", piece.Pawn(2,2,2))
		self.board[1][2] = ColoredChessPiece("W", piece.Pawn(3,2,2))
		self.board[1][3] = ColoredChessPiece("W", piece.Pawn(4,2,2))
		self.board[1][4] = ColoredChessPiece("W", piece.Pawn(5,2,2))
		self.board[1][5] = ColoredChessPiece("W", piece.Pawn(6,2,2))
		self.board[1][6] = ColoredChessPiece("W", piece.Pawn(7,2,2))
		self.board[1][7] = ColoredChessPiece("W", piece.Pawn(8,2,2))
		
		
		self.board[7][0] = ColoredChessPiece("B", piece.Rook(1,8))
		self.board[7][7] = ColoredChessPiece("B", piece.Rook(8,8))
		
		self.board[7][1] = ColoredChessPiece("B", piece.Knight(2,8))
		self.board[7][6] = ColoredChessPiece("B", piece.Knight(7,8))
		
		self.board[7][2] = ColoredChessPiece("B", piece.Bishop(3,8))
		self.board[7][5] = ColoredChessPiece("B", piece.Bishop(6,8))
				
		self.board[7][3] = ColoredChessPiece("B", piece.Queen(4,8))
		self.board[7][4] = ColoredChessPiece("B", piece.King(5,8,5,8))
		
		self.board[6][0] = ColoredChessPiece("B", piece.Pawn(1,7,7))
		self.board[6][1] = ColoredChessPiece("B", piece.Pawn(2,7,7))
		self.board[6][2] = ColoredChessPiece("B", piece.Pawn(3,7,7))
		self.board[6][3] = ColoredChessPiece("B", piece.Pawn(4,7,7))
		self.board[6][4] = ColoredChessPiece("B", piece.Pawn(5,7,7))
		self.board[6][5] = ColoredChessPiece("B", piece.Pawn(6,7,7))
		self.board[6][6] = ColoredChessPiece("B", piece.Pawn(7,7,7))
		self.board[6][7] = ColoredChessPiece("B", piece.Pawn(8,7,7))
		
		self.__white_king_moved__ = False
		self.__black_king_moved__ = False
		self.__white_a_rook_moved__ = False
		self.__white_e_rook_moved__ = False
		self.__black_a_rook_moved__ = False
		self.__black_e_rook_moved__ = False
		
		self.__en_passant_possible__ = -1
Example #4
0
 def _built_board(self):
     colors = ["white", "black"] * (self.cols + 2)
     self.board = [[
         square.Square(i, j, colors[j + i % 2]) for j in range(self.cols)
     ] for i in range(self.rows)]
     # Black pieces
     self.board[0][0].set_piece(piece.King(self.board[0][0], Board.black))
     # White pieces
     self.board[7][7].set_piece(piece.King(self.board[7][7], Board.white))
     self.board[0][2].set_piece(piece.Rook(self.board[0][2], Board.white))
     self.board[2][0].set_piece(piece.Rook(self.board[2][0], Board.white))
     self.board[4][0].set_piece(piece.Queen(self.board[4][0], Board.white))
     self.kings = [self.board[7][7], self.board[0][0]]
Example #5
0
 def spawnPiece(self, piecetype, team, x, y, z, d):
     col = color.white
     if (team == 1):
         col = color.red
     if (piecetype == 'pawn'):
         self.addPiece(x, y, z, d,
                       piece.Pawn(vector(x, y, z), col, self.spots))
     if (piecetype == 'knight'):
         self.addPiece(x, y, z, d,
                       piece.Knight(vector(x, y, z), col, self.spots))
     if (piecetype == 'rook'):
         self.addPiece(x, y, z, d,
                       piece.Rook(vector(x, y, z), col, self.spots))
     if (piecetype == 'bishop'):
         self.addPiece(x, y, z, d,
                       piece.Bishop(vector(x, y, z), col, self.spots))
     if (piecetype == 'king'):
         self.addPiece(x, y, z, d,
                       piece.King(vector(x, y, z), col, self.spots))
         if (col == color.red):
             self.redkingpos = fvec.Fvector(x, y, z, d)
         else:
             self.whitekingpos = fvec.Fvector(x, y, z, d)
     if (piecetype == 'queen'):
         self.addPiece(x, y, z, d,
                       piece.Queen(vector(x, y, z), col, self.spots))
Example #6
0
    def init_board_array(self):
        temp = [[
            piece.Rook((0, 0), False, 'r'),
            piece.Knight((0, 1), False, 'n'),
            piece.Bishop((0, 2), False, 'b'),
            piece.Queen((0, 3), False, 'q'),
            piece.King((0, 4), False, 'k'),
            piece.Bishop((0, 5), False, 'b'),
            piece.Knight((0, 6), False, 'n'),
            piece.Rook((0, 7), False, 'r')
        ],
                [
                    piece.Pawn((1, 0), False, 'p'),
                    piece.Pawn((1, 1), False, 'p'),
                    piece.Pawn((1, 2), False, 'p'),
                    piece.Pawn((1, 3), False, 'p'),
                    piece.Pawn((1, 4), False, 'p'),
                    piece.Pawn((1, 5), False, 'p'),
                    piece.Pawn((1, 6), False, 'p'),
                    piece.Pawn((1, 7), False, 'p')
                ], [None, None, None, None, None, None, None, None],
                [None, None, None, None, None, None, None, None],
                [None, None, None, None, None, None, None, None],
                [None, None, None, None, None, None, None, None],
                [
                    piece.Pawn((6, 0), True, 'P'),
                    piece.Pawn((6, 1), True, 'P'),
                    piece.Pawn((6, 2), True, 'P'),
                    piece.Pawn((6, 3), True, 'P'),
                    piece.Pawn((6, 4), True, 'P'),
                    piece.Pawn((6, 5), True, 'P'),
                    piece.Pawn((6, 6), True, 'P'),
                    piece.Pawn((6, 7), True, 'P')
                ],
                [
                    piece.Rook((7, 0), 1, 'R'),
                    piece.Knight((7, 1), True, 'N'),
                    piece.Bishop((7, 2), True, 'B'),
                    piece.Queen((7, 3), True, 'Q'),
                    piece.King((7, 4), True, 'K'),
                    piece.Bishop((7, 5), True, 'B'),
                    piece.Knight((7, 6), True, 'N'),
                    piece.Rook((7, 7), True, 'R')
                ]]

        return temp
Example #7
0
 def populate(self):
     self.positions['a'][7] = piece.Rook('bR', 'Black', 'a', '7')
     self.positions['b'][7] = piece.Knight('bKn', 'Black', 'b', '7')
     self.positions['c'][7] = piece.Bishop('bB', 'Black', 'c', '7')
     self.positions['d'][7] = piece.Queen('bQ', 'Black', 'd', '7')
     self.positions['e'][7] = piece.King('bK', 'Black', 'e', '7')
     self.positions['f'][7] = piece.Bishop('bB', 'Black', 'f', '7')
     self.positions['g'][7] = piece.Knight('bKn', 'Black', 'g', '7')
     self.positions['h'][7] = piece.Rook('bR', 'Black', 'h', '7')
     self.positions['a'][0] = piece.Rook('wR', 'White', 'a', '0')
     self.positions['b'][0] = piece.Knight('wKn', 'White', 'b', '0')
     self.positions['c'][0] = piece.Bishop('wB', 'White', 'c', '0')
     self.positions['d'][0] = piece.Queen('wQ', 'White', 'd', '0')
     self.positions['e'][0] = piece.King('wK', 'White', 'e', '0')
     self.positions['f'][0] = piece.Bishop('wB', 'White', 'f', '0')
     self.positions['g'][0] = piece.Knight('wKn', 'White', 'g', '0')
     self.positions['h'][0] = piece.Rook('wR', 'White', 'h', '0')
     for letter in self.letters:
         self.positions[letter][6] = piece.Pawn('bP', 'Black', letter, '6')
         self.positions[letter][1] = piece.Pawn('wP', 'White', letter, '1')
     for letter in self.letters:
         for num in self.positions[letter]:
             if type(num) != str:
                 self.pieces.append(num)
Example #8
0
    def move(self, pieceToMove, newPosition, catchTree):
        """
        Move a piece
        """
        self.newKing = None
        if (pieceToMove is None):
            return
        valid, tree = pieceToMove.validMoves()
        if (not newPosition in valid):
            print(newPosition)
            print(pieceToMove.name, pieceToMove.color, pieceToMove.x,
                  pieceToMove.y)
            print(pc.Piece.board.getPiece(pieceToMove.x, pieceToMove.y))
            pc.Piece.board.save("boardError.csv")
            print("The suggested move is not valid!")
            exit()
            return
        pieceCaptured = np.abs(newPosition[1] - pieceToMove.y) > 1
        self.movedFrom = [pieceToMove.x, pieceToMove.y]
        self.pieceMoved = pieceToMove
        self.piecesRemoved = []

        if (pieceCaptured):
            moves = catchTree.getPath(newPosition[0], newPosition[1])
            for i in range(0, len(moves) - 1):
                middleX = int((moves[i][0] + moves[i + 1][0]) / 2)
                middleY = int((moves[i][1] + moves[i + 1][1]) / 2)
                newEmptyPiece = pc.Piece()
                newEmptyPiece.x = middleX
                newEmptyPiece.y = middleY
                pieceToRemove = pc.Piece.board.getPiece(middleX, middleY)
                self.piecesRemoved.append(pieceToRemove)
                if (pieceToRemove.name == "empty"
                        or pieceToRemove.color == pieceToMove.color):
                    print("==== ERROR INFORMATION ======")
                    print(moves)
                    print(pieceToRemove.x, pieceToRemove.y)
                    print(pieceToMove.x, pieceToMove.y)
                    print(pieceToMove.color, pieceToRemove.color)
                    print(pieceToMove.name, pieceToMove.name)
                    pc.Piece.board.save("boardError.csv")
                    print("Abort! Error when removing piece")
                    exit()
                try:
                    if (self.playerToMove == self.p1):
                        self.p2.pieces.remove(pieceToRemove)
                    else:
                        self.p1.pieces.remove(pieceToRemove)
                except Exception as exc:
                    print(pieceToRemove.name, pieceToRemove.color,
                          pieceToRemove.x, pieceToRemove.y)
                    print(pieceToMove.name, pieceToMove.color, pieceToMove.x,
                          pieceToMove.y, newPosition)
                    pc.Piece.board.save("LastBoardBeforeError.csv")
                    raise exc
                pc.Piece.board.setPiece(newEmptyPiece)

        copy = pc.Piece.board.getPiece(newPosition[0], newPosition[1])
        copy.x = pieceToMove.x
        copy.y = pieceToMove.y
        pieceToMove.x = newPosition[0]
        pieceToMove.y = newPosition[1]
        pc.Piece.board.setPiece(pieceToMove)
        pc.Piece.board.setPiece(copy)
        #pc.Piece.board.save("lastState.csv")

        if (pieceToMove.color == "white" and newPosition[1] == 7
                and pieceToMove.name != "king"):
            self.playerToMove.pieces.remove(pieceToMove)
            newKing = pc.King()
            newKing.color = "white"
            newKing.x = newPosition[0]
            newKing.y = newPosition[1]
            self.playerToMove.pieces.append(newKing)
            self.newKing = newKing
            pc.Piece.board.setPiece(newKing)
        elif (pieceToMove.color == "black" and newPosition[1] == 0
              and pieceToMove.name != "king"):
            self.playerToMove.pieces.remove(pieceToMove)
            newKing = pc.King()
            newKing.color = "black"
            newKing.x = newPosition[0]
            newKing.y = newPosition[1]
            self.playerToMove.pieces.append(newKing)
            self.newKing = newKing
            pc.Piece.board.setPiece(newKing)
Example #9
0
    def __init__(self, master):

        self._turn = 1
        self.n = 8  # length checkers on board
        self.wking_loc = [0] * 2
        self.wking_loc[0] = 7
        self.wking_loc[1] = 4
        self.bking_loc = [0, 4]

        #       self.game_board = [[piece.EmptyPiece()]*8]*8                                WRONG, duplicates the 1D list 8 times (same lists)
        #       self.game_board = { (pp,qq):0 for pp in range(8) for qq in range(8) }       if were using a dictionary
        self.game_board = [[piece.EmptyPiece() for pp in range(8)]
                           for qq in range(8)]

        for s in range(0, 8):
            self.game_board[6][s] = piece.Pawn(defines.white_piece,
                                               defines.pawn)
            self.game_board[1][s] = piece.Pawn(defines.black_piece,
                                               defines.pawn)

        self.game_board[7][4] = piece.King(defines.white_piece, defines.king)
        self.game_board[0][4] = piece.King(defines.black_piece, defines.king)
        self.game_board[7][3] = piece.Queen(defines.white_piece, defines.queen)
        self.game_board[0][3] = piece.Queen(defines.black_piece, defines.queen)
        self.game_board[7][0] = piece.Rook(defines.white_piece, defines.rook)
        self.game_board[0][0] = piece.Rook(defines.black_piece, defines.rook)
        self.game_board[7][7] = piece.Rook(defines.white_piece, defines.rook)
        self.game_board[0][7] = piece.Rook(defines.black_piece, defines.rook)
        self.game_board[7][2] = piece.Bishop(defines.white_piece,
                                             defines.bishop)
        self.game_board[0][2] = piece.Bishop(defines.black_piece,
                                             defines.bishop)
        self.game_board[7][5] = piece.Bishop(defines.white_piece,
                                             defines.bishop)
        self.game_board[0][5] = piece.Bishop(defines.black_piece,
                                             defines.bishop)
        self.game_board[7][6] = piece.Knight(defines.white_piece,
                                             defines.knight)
        self.game_board[0][6] = piece.Knight(defines.black_piece,
                                             defines.knight)
        self.game_board[7][1] = piece.Knight(defines.white_piece,
                                             defines.knight)
        self.game_board[0][1] = piece.Knight(defines.black_piece,
                                             defines.knight)

        # Graphics
        self.master = master
        self.master.title('ChessPy')
        self.master.configure(background='#e1d8b9')
        self.master.minsize(400, 470)
        self.master.resizable(True, True)
        self.master.bind('<Configure>', lambda e: self.draw_board(
        ))  # call draw_board() in the event of new Hight and Width window size

        self.style = ttk.Style()
        self.style.configure('TFrame', background='#e1d8b9')
        self.style.configure('TButton', background='#e1d8b9')
        self.style.configure('TLabel', background='#e1d8b9')

        self.board_canvas = Canvas(
            self.master)  # used to draw shapes: line, oval,...
        self.board_canvas.pack()

        self.controls_frame = ttk.Frame(self.master)
        self.controls_frame.pack(side=TOP, pady=20)

        self.n_var = StringVar()
        self.n_var.set(self.n)
        #         Spinbox(self.controls_frame, from_ = 4, to = 99, width = 2,
        #                 font = 'Verdana 10 bold', textvariable = self.n_var).grid(row = 0, column = 1)

        self.from_row_var = StringVar()
        self.from_col_var = StringVar()
        self.to_row_var = StringVar()
        self.to_col_var = StringVar()
        #self.to_col_var.set('0')
        """ location entry widgets """
        ttk.Label(self.controls_frame,
                  text='Move From Row:',
                  font='Verdana 10 bold').grid(row=0,
                                               column=0,
                                               sticky=(W),
                                               padx=10)  # , sticky= (E)
        self.from_row_entry = ttk.Entry(
            self.controls_frame,
            width=10,  #textvariable = self.from_row_var,
            font='Verdana 10')  #, sticky = (W)
        self.from_row_entry.grid(row=0, column=1, sticky=(W))

        ttk.Label(self.controls_frame,
                  text='Move From Column:',
                  font='Verdana 10 bold').grid(row=1,
                                               column=0,
                                               sticky=(W),
                                               padx=10)
        self.from_col_entry = ttk.Entry(
            self.controls_frame,
            width=10,  #textvariable = self.from_col_var,
            font='Verdana 10')
        self.from_col_entry.grid(row=1, column=1, sticky=(W))

        ttk.Label(self.controls_frame,
                  text='Move To Row:',
                  font='Verdana 10 bold').grid(row=2,
                                               column=0,
                                               sticky=(W),
                                               padx=10)
        self.to_row_entry = ttk.Entry(
            self.controls_frame,
            width=10,  #textvariable = self.to_row_var,
            font='Verdana 10')
        self.to_row_entry.grid(row=2, column=1, sticky=(W))

        ttk.Label(self.controls_frame,
                  text='Move To Column:',
                  font='Verdana 10 bold').grid(row=3,
                                               column=0,
                                               sticky=(W),
                                               padx=10)
        self.to_col_entry = ttk.Entry(
            self.controls_frame,
            width=10,  #textvariable = self.to_col_var,
            font='Verdana 10')
        self.to_col_entry.grid(row=3, column=1, sticky=(W))

        #         self.from_row_entry.pack()
        #         self.from_col_entry.pack()
        #         self.to_row_entry.pack()
        #         self.to_col_entry.pack()
        #
        self.from_row_entry["textvariable"] = self.from_row_var
        self.from_col_entry["textvariable"] = self.from_col_var
        self.to_row_entry["textvariable"] = self.to_row_var
        self.to_col_entry["textvariable"] = self.to_col_var

        # and here we get a callback when the user hits return.
        #self.to_col_entry.bind('<Key-Return>',self.move_callback)
        #self.to_col_var.get()
        """ Move button """
        ttk.Button(self.controls_frame,
                   text='Enter Move',
                   command=self.move_callback).grid(row=4,
                                                    column=1,
                                                    columnspan=2,
                                                    sticky=(W),
                                                    padx=10,
                                                    pady=10)

        ttk.Label(self.controls_frame, text='to exit type q',
                  font='Verdana 8').grid(row=7, column=0, sticky=(W),
                                         pady=10)  # , sticky= (E)
        #         ttk.Label(self.controls_frame).grid(row = 0, column = 2, padx = 10) # spacer

        turn_color = "WHITE" if self._turn == 1 else "BLACK"
        ttk.Label(self.controls_frame,
                  text=turn_color + ' turn',
                  font='Verdana 8').grid(row=6, column=0, sticky=(W), pady=10)

        self.draw_board()
Example #10
0
playing = True
moves = []

piecesGroup = pygame.sprite.Group()
## Add Pawns
for i in range(0, 1):
	piecesGroup.add(piece.Pawn("white", [i, 6]),
					piece.Pawn("black", [i, 1]))

## Add black pieces
piecesGroup.add(#piece.Rook("black", [0, 0]),
				#piece.Knight("black", [1, 0]),
				#piece.Bishop("black", [2, 0]),
				#piece.Queen("black", [3, 0]), 
				piece.King("black", [4, 0]),
				#piece.Bishop("black", [5, 0]),
				#piece.Knight("black", [6, 0]),
				piece.Rook("black", [7, 0]))

## Add white pieces
piecesGroup.add(#piece.Rook("white", [0, 7]),
				#piece.Knight("white", [1, 7]),
				#piece.Bishop("white", [2, 7]),
				#piece.Queen("white", [3, 7]), 
				piece.King("white", [4, 7]),
				#piece.Bishop("white", [5, 7]),
				#piece.Knight("white", [6, 7]),
				piece.Rook("white", [7, 7]))

gameboard = board.Board(piecesGroup)
Example #11
0
import board
import piece
import copy

#these are the pieces that each player will initially start each game with
p1InitializedPieces = [piece.Rook("R2",0,0,False),piece.Knight("K2",0,1,False),piece.Bishop("B2",0,2,False),piece.Queen("Q1",0,3,False),\
    piece.King("KG",0,4,False),piece.Bishop("B1",0,5,False), piece.Knight("K1",0,6,False),piece.Rook("R1",0,7,False), \
    piece.Pawn("P8",1,0,False),piece.Pawn("P7",1,1,False),piece.Pawn("P6",1,2,False),piece.Pawn("P5",1,3,False),piece.Pawn("P4",1,4,False), \
    piece.Pawn("P3",1,5,False),piece.Pawn("P2",1,6,False),piece.Pawn("P1",1,7,False)]

p2InitializedPieces = [piece.Pawn("P1",6,0,False),piece.Pawn("P2",6,1,False),piece.Pawn("P3",6,2,False),piece.Pawn("P4",6,3,False),piece.Pawn("P5",6,4,False), \
    piece.Pawn("P6",6,5,False),piece.Pawn("P7",6,6,False),piece.Pawn("P8",6,7,False), \
    piece.Rook("R1",7,0,False),piece.Knight("K1",7,1,False),piece.Bishop("B1",7,2,False),piece.King("KG",7,3,False),\
    piece.Queen("Q1",7,4,False),piece.Bishop("B2",7,5,False), piece.Knight("K2",7,6,False),piece.Rook("R2",7,7,False)]


class Player:
    '''Player objects will have a list of Piece objects that are owned by the player
    '''
    def __init__(self, name, isPlayer1):  #constructor
        self.name = name
        self.isPlayer1 = isPlayer1
        playerId = name[0]
        if isPlayer1 == True:
            self.myPieces = p1InitializedPieces
        else:
            self.myPieces = p2InitializedPieces

        listLength = len(self.myPieces)
        counter = 0
        while counter != listLength:  #add a identifier(playerName[0]) to each piece
Example #12
0
 def create_pieces(self):
     ps = [
         p.Rook(
             (0, 7),
             color=True,
             value=5,
             image=load("../images/w_rook.png"),
         ),
         p.Rook(
             (7, 7),
             color=True,
             value=5,
             image=load("../images/w_rook.png"),
         ),
         p.Bishop(
             (2, 7),
             color=True,
             value=3,
             image=load("../images/w_bishop.png"),
         ),
         p.Bishop(
             (5, 7),
             color=True,
             value=3,
             image=load("../images/w_bishop.png"),
         ),
         p.Knight(
             (1, 7),
             color=True,
             value=3,
             image=load("../images/w_knight.png"),
         ),
         p.Knight(
             (6, 7),
             color=True,
             value=3,
             image=load("../images/w_knight.png"),
         ),
         p.Rook(
             (0, 0),
             color=False,
             value=-5,
             image=load("../images/b_rook.png"),
         ),
         p.Rook(
             (7, 0),
             color=False,
             value=-5,
             image=load("../images/b_rook.png"),
         ),
         p.Knight(
             (1, 0),
             color=False,
             value=-3,
             image=load("../images/b_knight.png"),
         ),
         p.Knight(
             (6, 0),
             color=False,
             value=-3,
             image=load("../images/b_knight.png"),
         ),
         p.Bishop(
             (2, 0),
             color=False,
             value=-3,
             image=load("../images/b_bishop.png"),
         ),
         p.Bishop(
             (5, 0),
             color=False,
             value=-3,
             image=load("../images/b_bishop.png"),
         ),
         p.King(
             (4, 7),
             color=True,
             value=1000,
             image=load("../images/w_king.png"),
         ),
         p.Queen(
             (3, 7),
             color=True,
             value=9,
             image=load("../images/w_queen.png"),
         ),
         p.King(
             (4, 0),
             color=False,
             value=-1000,
             image=load("../images/b_king.png"),
         ),
         p.Queen(
             (3, 0),
             color=False,
             value=-9,
             image=load("../images/b_queen.png"),
         ),
     ]
     for i in range(8):
         ps += [
             p.Pawn(
                 (i, 6),
                 color=True,
                 value=1,
                 image=pygame.image.load("../images/w_pawn.png"),
             ),
             p.Pawn(
                 (i, 1),
                 color=False,
                 value=-1,
                 image=pygame.image.load("../images/b_pawn.png"),
             ),
         ]
     return ps