Пример #1
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)
Пример #2
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]]
Пример #3
0
 def check_castled(self, piece, pos_start, pos_end):
     if isinstance(piece, p.King):
         king = piece
         if king.color is False:
             rook_value = -5
             rook_color = "b"
         else:
             rook_value = 5
             rook_color = "w"
         pos_diff = pos_start[0] - pos_end[0]
         # short castleing
         if pos_diff == -2:
             self.board[-1][king.rel_pos(1, 0)[1],
                            king.rel_pos(1, 0)[0]] = 0
             rook = p.Rook(
                 king.rel_pos(-1, 0),
                 color=king.color,
                 value=rook_value,
                 image=load("../images/{}_rook.png".format(rook_color)),
             )
             self.place_piece(rook)
         # long castleing
         elif pos_diff == 2:
             self.board[-1][king.rel_pos(-2, 0)[1],
                            king.rel_pos(-2, 0)[0]] = 0
             rook = p.Rook(
                 king.rel_pos(1, 0),
                 color=king.color,
                 value=rook_value,
                 image=load("../images/{}_rook.png".format(rook_color)),
             )
             self.place_piece(rook)
Пример #4
0
 def makeMove(self, initialX, initialY, posX, posY):
     posY = int(posY) - 1
     initialY = int(initialY) - 1
     #Get the piece in question and update its knowledge of its location, make the move. If there was a piece in the new spot, update the piece tracker.
     current_soldier = self.positions[initialX][initialY]
     current_soldier.posX = posX
     current_soldier.posY = posY
     old_soldier = self.positions[posX][posY]
     self.positions[posX][posY] = current_soldier
     self.positions[initialX][initialY] = ' '
     if type(old_soldier) != str:
         self.update_pieces()
     #Update logic for individual pieces with special cases
     if type(current_soldier) == piece.King or type(current_soldier) == piece.Rook:
         current_soldier.hasNotMovedYet = False
     if type(current_soldier) == piece.Pawn:
         if current_soldier.first_turn:
             current_soldier.first_turn = False
         #Handle promotion logic for pawns and update piece tracker to reflect this.
         if current_soldier.posY == self.white_pawn_goal and current_soldier.side == "White":
             picked = False
             while not picked:
                 promotion = input("Enter what kind of piece you want your pawn to be promoted to - your options are Q, Kn, R or B: ")
                 if promotion == "Kn":
                     self.positions[current_soldier.posX][current_soldier.posY] = piece.Knight('wKn', 'White', current_soldier.posX, current_soldier.posY)
                     picked = True
                 elif promotion == "Q":
                     self.positions[current_soldier.posX][current_soldier.posY] = piece.Queen('wQ', 'White', current_soldier.posX, current_soldier.posY)
                     picked = True
                 elif promotion == "R":
                     self.positions[current_soldier.posX][current_soldier.posY] = piece.Rook('wR', 'White', current_soldier.posX, current_soldier.posY)
                     picked = True
                 elif promotion == "B":
                     self.positions[current_soldier.posX][current_soldier.posY] = piece.Bishop('wB', 'White', current_soldier.posX, current_soldier.posY)
                     picked = True
                 else:
                     self.printer()
                     print("Issue with the piece name you're inputting")
             self.update_pieces()
         elif current_soldier.posY == self.black_pawn_goal and current_soldier.side == "Black":
             picked = False
             while not picked:
                 promotion = input("Enter what kind of piece you want your pawn to be promoted to - your options are Q, Kn, R or B: ")
                 if promotion == "Kn":
                     self.positions[current_soldier.posX][current_soldier.posY] = piece.Knight('bKn', 'Black', current_soldier.posX, current_soldier.posY)
                     picked = True
                 elif promotion == "Q":
                     self.positions[current_soldier.posX][current_soldier.posY] = piece.Queen('bQ', 'Black', current_soldier.posX, current_soldier.posY)
                     picked = True
                 elif promotion == "R":
                     self.positions[current_soldier.posX][current_soldier.posY] = piece.Rook('bR', 'Black', current_soldier.posX, current_soldier.posY)
                     picked = True
                 elif promotion == "B":
                     self.positions[current_soldier.posX][current_soldier.posY] = piece.Bishop('bB', 'Black', current_soldier.posX, current_soldier.posY)
                     picked = True
                 else:
                     print("Issue with the piece name you're inputting")
             self.update_pieces()
Пример #5
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
Пример #6
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]]
Пример #7
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))
Пример #8
0
    def promote(self, piec):
        posvec = piec.getpos()
        c = 0 if piec.ogcolor == color.red else 3
        if (posvec.z == c and posvec.d == c):
            picked = False
            while (not picked):
                scene.caption = 'Please choose a piece to upgrade your pawn to q/k/r/b'
                ev = scene.waitfor('keydown')
                if ev.event == 'keydown':
                    picked = True
                    if ev.key == 'q':
                        col = self.spots[posvec.d][posvec.z][posvec.y][
                            posvec.x].ogcolor
                        self.spots[posvec.d][posvec.z][posvec.y][
                            posvec.x].setvisible(False)
                        self.spots[posvec.d][posvec.z][posvec.y][
                            posvec.x] = None
                        self.addPiece(
                            posvec.x, posvec.y, posvec.z, posvec.d,
                            piece.Queen(vector(posvec.x, posvec.y, posvec.z),
                                        col, self.spots))
                    elif ev.key == 'k':
                        col = self.spots[posvec.d][posvec.z][posvec.y][
                            posvec.x].ogcolor
                        self.spots[posvec.d][posvec.z][posvec.y][
                            posvec.x].setvisible(False)
                        self.spots[posvec.d][posvec.z][posvec.y][
                            posvec.x] = None
                        self.addPiece(
                            posvec.x, posvec.y, posvec.z, posvec.d,
                            piece.Knight(vector(posvec.x, posvec.y, posvec.z),
                                         col, self.spots))
                    elif ev.key == 'b':
                        col = self.spots[posvec.d][posvec.z][posvec.y][
                            posvec.x].ogcolor
                        self.spots[posvec.d][posvec.z][posvec.y][
                            posvec.x].setvisible(False)
                        self.spots[posvec.d][posvec.z][posvec.y][
                            posvec.x] = None
                        self.addPiece(
                            posvec.x, posvec.y, posvec.z, posvec.d,
                            piece.Bishop(vector(posvec.x, posvec.y, posvec.z),
                                         col, self.spots))
                    elif ev.key == 'r':
                        col = self.spots[posvec.d][posvec.z][posvec.y][
                            posvec.x].ogcolor
                        self.spots[posvec.d][posvec.z][posvec.y][
                            posvec.x].setvisible(False)
                        self.spots[posvec.d][posvec.z][posvec.y][
                            posvec.x] = None
                        self.addPiece(
                            posvec.x, posvec.y, posvec.z, posvec.d,
                            piece.Rook(vector(posvec.x, posvec.y, posvec.z),
                                       col, self.spots))
                    else:
                        picked = False

        else:
            return False
Пример #9
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
Пример #10
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)
Пример #11
0
if __name__ == '__main__':

    chess = chessBoard.ChessBoard()

    parser = argparse.ArgumentParser(description=(
        "Find a list of all the potential board positions the given piece could advance to, \
                                                       with one move, from the given position, with the assumption there are no other pieces on the board"
    ))

    parser.add_argument('-piece',
                        metavar='piece',
                        type=str,
                        choices=['KNIGHT', 'ROOK', 'QUEEN'],
                        help="Only support KNIGHT|ROOK|QUEEN.")
    parser.add_argument( '-position', metavar = 'position', type = str, choices=chess.getCells(), \
                                                                       help = "position in the board that piece is on")
    res = parser.parse_args()

    (row, col), ok = chess.toIndex(res.position)

    if res.piece == "KNIGHT":
        p = piece.Knight(row, col, chess)
    elif res.piece == "QUEEN":
        p = piece.Queen(row, col, chess)
    else:
        p = piece.Rook(row, col, chess)

    s = ", ".join(p.possibleMoves())
    print(f'"{s}"')
Пример #12
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()
Пример #13
0
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)

currentPlayer = "white"
inCheck = False
Пример #14
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
Пример #15
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