def set_pieces(self): self.board[1][4] = Queen("Queen","Black",1,4,"[ \u265B ]") self.board[8][4] = Queen("Queen","White",8,4,"[ \u2655 ]") for i in range(1,9): self.board[2][i] = Pawn("Pawn","Black",2,i,"[ \u265F ]") self.board[7][i] = Pawn("Pawn","White",7,i,"[ \u2659 ]")
def __init__(self, mateInOne=False, castleBoard=False, pessant=False, promotion=False): self.pieces = [] self.history = [] self.points = 0 self.player = WHITE self.move_count = 0 self.checkmate = False if not mateInOne and not castleBoard and not pessant and not promotion: self.pieces.extend( [ Rook(self, BLACK, C(0, 7)), Knight(self, BLACK, C(1, 7)), Bishop(self, BLACK, C(2, 7)), Queen(self, BLACK, C(3, 7)), King(self, BLACK, C(4, 7)), Bishop(self, BLACK, C(5, 7)), Knight(self, BLACK, C(6, 7)), Rook(self, BLACK, C(7, 7)), ] ) for x in range(8): self.pieces.append(Pawn(self, BLACK, C(x, 6))) for x in range(8): self.pieces.append(Pawn(self, WHITE, C(x, 1))) self.pieces.extend( [ Rook(self, WHITE, C(0, 0)), Knight(self, WHITE, C(1, 0)), Bishop(self, WHITE, C(2, 0)), Queen(self, WHITE, C(3, 0)), King(self, WHITE, C(4, 0)), Bishop(self, WHITE, C(5, 0)), Knight(self, WHITE, C(6, 0)), Rook(self, WHITE, C(7, 0)), ] ) elif promotion: pawnToPromote = Pawn(self, WHITE, C(1, 6)) pawnToPromote.movesMade = 1 kingWhite = King(self, WHITE, C(4, 0)) kingBlack = King(self, BLACK, C(3, 2)) self.pieces.extend([pawnToPromote, kingWhite, kingBlack]) elif pessant: pawn = Pawn(self, WHITE, C(1, 4)) pawn2 = Pawn(self, BLACK, C(2, 6)) kingWhite = King(self, WHITE, C(4, 0)) kingBlack = King(self, BLACK, C(3, 2)) self.pieces.extend([pawn, pawn2, kingWhite, kingBlack]) self.history = [] self.player = BLACK self.points = 0 self.move_count = 0 self.checkmate = False firstMove = Move(pawn2, C(2, 4)) self.make_move(firstMove) self.player = WHITE return
def move(self, startLoc, endLoc, game1=True): """Attempts to make move. inputs: startLoc and endLoc are tuples with coordinates x,y A startLoc can be a piece if a piece is being dropped outputs: True if move made, else False""" try: if game1: gamePlaying = self.game1 gameNotPlaying = self.game2 else: gamePlaying = self.game2 gameNotPlaying = self.game1 capturedPiece = gamePlaying.makeAndValidateMove(startLoc,endLoc) if capturedPiece: # if it was a promoted pawn, make it back into a pawn if capturedPiece.promotedPawn: capturedPiece = Pawn() # captured pieces are counted as having moved already if isinstance(capturedPiece, MovedPiece): capturedPiece.move() capturedPiece.move() # give the captured piece to the the partner of the capturer gameNotPlaying.addPiece(capturedPiece) # since no errors were thrown, we were able to make a move return True except AssertionError: return False
def setBoard(self): for row in range(8): self.board.append([]) self.board[row] = [None] * 8 # element 0, 0 of the board is A1 on the chess board and # element 8,8 of the board is H8 on the chess board self.board[0][0] = Spot(Rook("Rook", True), 0, 0) self.board[0][1] = Spot(Knight("Knight", True), 0, 1) self.board[0][2] = Spot(Bishop("Bishop", True), 0, 2) self.board[0][3] = Spot(Queen("Queen", True), 0, 3) self.board[0][4] = Spot(King("King", True), 0, 4) self.board[0][5] = Spot(Bishop("Bishop", True), 0, 5) self.board[0][6] = Spot(Knight("Knight", True), 0, 6) self.board[0][7] = Spot(Rook("Rook", True), 0, 7) for i in range(8): self.board[1][i] = Spot(Pawn("Pawn", True), 1, i) self.board[6][i] = Spot(Pawn("Pawn", False), 6, i) for emptyI in range(2, 6): for j in range(8): self.board[emptyI][j] = 0 self.board[7][0] = Spot(Rook("Rook", False), 7, 0) self.board[7][1] = Spot(Knight("Knight", False), 7, 1) self.board[7][2] = Spot(Bishop("Bishop", False), 7, 2) self.board[7][3] = Spot(Queen("Queen", False), 7, 3) self.board[7][4] = Spot(King("King", False), 7, 4) self.board[7][5] = Spot(Bishop("Bishop", False), 7, 5) self.board[7][6] = Spot(Knight("Knight", False), 7, 6) self.board[7][7] = Spot(Rook("Rook", False), 7, 7)
def initialize(self): self.board = [ [None] * 5, [None] * 5, [None] * 5, [None] * 5, [None] * 5 ] self.board[0][0] = Rook(1) self.board[0][1] = Bishop(1) self.board[0][2] = SilverGen(1) self.board[0][3] = GoldGen(1) self.board[0][4] = Emperor(1) self.board[1][4] = Pawn(1) self.board[4][4] = Rook(2) self.board[4][3] = Bishop(2) self.board[4][2] = SilverGen(2) self.board[4][1] = GoldGen(2) self.board[4][0] = Emperor(2) self.board[3][0] = Pawn(2) # self.print_board() self.dead_pieces = {} self.dead_pieces[1] = [] self.dead_pieces[2] = [] self.winner = None self.player_turn = 1
def move(self, startLoc, endLoc, game1=True): """Attempts to make move. inputs: startLoc and endLoc are tuples with coordinates x,y A startLoc can be a piece if a piece is being dropped outputs: True if move made, else False""" try: if game1: gamePlaying = self.game1 gameNotPlaying = self.game2 else: gamePlaying = self.game2 gameNotPlaying = self.game1 capturedPiece = gamePlaying.makeAndValidateMove(startLoc, endLoc) if capturedPiece: # if it was a promoted pawn, make it back into a pawn if capturedPiece.promotedPawn: capturedPiece = Pawn() # captured pieces are counted as having moved already if isinstance(capturedPiece, MovedPiece): capturedPiece.move() capturedPiece.move() # give the captured piece to the the partner of the capturer gameNotPlaying.addPiece(capturedPiece) # since no errors were thrown, we were able to make a move return True except AssertionError: return False
def __init__(self): # The initialising function of the 'Board' class. Assigns all of the # attributes their starting values before creating all of the pieces # needed for the game. self.pieces = [] self.history = [] self.points = 0 self.currentSide = WHITE self.movesMade = 0 for x in range(8): self.pieces.append(Pawn(self, BLACK, C(x, 6))) self.pieces.append(Pawn(self, WHITE, C(x, 1))) self.pieces.extend([ Rook(self, WHITE, C(0, 0)), Knight(self, WHITE, C(1, 0)), Bishop(self, WHITE, C(2, 0)), King(self, WHITE, C(3, 0)), Queen(self, WHITE, C(4, 0)), Bishop(self, WHITE, C(5, 0)), Knight(self, WHITE, C(6, 0)), Rook(self, WHITE, C(7, 0)), Rook(self, BLACK, C(0, 7)), Knight(self, BLACK, C(1, 7)), Bishop(self, BLACK, C(2, 7)), King(self, BLACK, C(3, 7)), Queen(self, BLACK, C(4, 7)), Bishop(self, BLACK, C(5, 7)), Knight(self, BLACK, C(6, 7)), Rook(self, BLACK, C(7, 7)) ])
def getAllPossibleMoves(self, board, i, j): color = self.name[0] name = self.name[1:] if name == 'rook': from Rook import Rook piece = Rook(name, False) elif name == 'knight': from Knight import Knight piece = Knight(name, False) elif name == 'king': from King import King piece = King(name, False) elif name == 'queen': from Queen import Queen piece = Queen(name, False) elif name == 'bishop': from Bishop import Bishop piece = Bishop(name, False) elif name == 'pawn': from Pawn import Pawn piece = Pawn(name, False) else: return [] piece_moves = piece.getPossibleMoves(board, color, i, j) return piece_moves
def __add_pieces(self): for x in range(8): self.board.add_piece(Pawn(is_white=True, x=x, y=1), x, 1) self.board.add_piece(Pawn(is_white=False, x=x, y=6), x, 6) for x in [0, 7]: self.board.add_piece(Rook(is_white=True, x=x, y=0), x, 0) self.board.add_piece(Rook(is_white=False, x=x, y=7), x, 7) for x in [1, 6]: self.board.add_piece(Knight(is_white=True, x=x, y=0), x, 0) self.board.add_piece(Knight(is_white=False, x=x, y=7), x, 7) for x in [2, 5]: self.board.add_piece(Bishop(is_white=True, x=x, y=0), x, 0) self.board.add_piece(Bishop(is_white=False, x=x, y=7), x, 7) self.board.add_piece(Queen(is_white=True, x=3, y=0), 3, 0) self.board.add_piece(Queen(is_white=False, x=3, y=7), 3, 7) self.board.add_piece(King(is_white=True, x=4, y=0), 4, 0) self.board.add_piece(King(is_white=False, x=4, y=7), 4, 7)
def __init__(self, window, gameMode): super().__init__() self.window = window self.round = "red" self.board = Board() self.choosenPawn = Pawn(69, 420, (21,3,7)) self.listOfMoves = [] self.gameMode = gameMode
def __init__(self, mateInOne=False, castleBoard=False, pessant=False, promotion=False): self.pieces = [] self.history = [] self.points = 0 self.currentSide = WHITE self.movesMade = 0 self.checkmate = False if not mateInOne and not castleBoard and not pessant and not promotion: self.pieces.extend([ Rook(self, BLACK, C(0, 7)), Knight(self, BLACK, C(1, 7)), Bishop(self, BLACK, C(2, 7)), Queen(self, BLACK, C(3, 7)), King(self, BLACK, C(4, 7)), Bishop(self, BLACK, C(5, 7)), Knight(self, BLACK, C(6, 7)), Rook(self, BLACK, C(7, 7)) ]) for x in range(8): self.pieces.append(Pawn(self, BLACK, C(x, 6))) for x in range(8): self.pieces.append(Pawn(self, WHITE, C(x, 1))) self.pieces.extend([ Rook(self, WHITE, C(0, 0)), Knight(self, WHITE, C(1, 0)), Bishop(self, WHITE, C(2, 0)), Queen(self, WHITE, C(3, 0)), King(self, WHITE, C(4, 0)), Bishop(self, WHITE, C(5, 0)), Knight(self, WHITE, C(6, 0)), Rook(self, WHITE, C(7, 0)) ]) elif promotion: pawnToPromote = Pawn(self, WHITE, C(1, 6)) pawnToPromote.movesMade = 1 kingWhite = King(self, WHITE, C(4, 0)) kingBlack = King(self, BLACK, C(3, 2)) self.pieces.extend([pawnToPromote, kingWhite, kingBlack]) elif pessant: pawn = Pawn(self, WHITE, C(1, 4)) pawn2 = Pawn(self, BLACK, C(2, 6)) kingWhite = King(self, WHITE, C(4, 0)) kingBlack = King(self, BLACK, C(3, 2)) self.pieces.extend([pawn, pawn2, kingWhite, kingBlack]) self.history = [] self.currentSide = BLACK self.points = 0 self.movesMade = 0 self.checkmate = False firstMove = Move(pawn2, C(2, 4)) self.makeMove(firstMove) self.currentSide = WHITE return
def initializeBoard(): # Make everything none first for y in range(SCL): tempBoard.append([]) for x in range(SCL): tempBoard[y].append(None) # Add all the rooks tempBoard[0][0] = Rook(0, 0, 'black', 0, False) tempBoard[0][7] = Rook(0, 7, 'black', 0, False) tempBoard[7][0] = Rook(7, 0, 'white', 0, False) tempBoard[7][7] = Rook(7, 7, 'white', 0, False) # Add all the knights tempBoard[0][1] = Knight(0, 1, 'black', 0, False) tempBoard[0][6] = Knight(0, 6, 'black', 0, False) tempBoard[7][1] = Knight(7, 1, 'white', 0, False) tempBoard[7][6] = Knight(7, 6, 'white', 0, False) # Add all the bishops tempBoard[0][2] = Bishop(0, 2, 'black', 0, False) tempBoard[0][5] = Bishop(0, 5, 'black', 0, False) tempBoard[7][2] = Bishop(7, 2, 'white', 0, False) tempBoard[7][5] = Bishop(7, 5, 'white', 0, False) # Add the Queens tempBoard[0][3] = Queen(0, 3, 'black', 0, False) tempBoard[7][3] = Queen(7, 3, 'white', 0, False) # Add the Kings tempBoard[0][4] = King(0, 4, 'black', 0, False, screen) tempBoard[7][4] = King(7, 4, 'white', 0, False, screen) # Add in all the pawns for x in range(SCL): tempBoard[1][x] = Pawn(1, x, 'black', 0, False, screen) for x in range(SCL): tempBoard[6][x] = Pawn(6, x, 'white', 0, False, screen) # Add it in as the first state of the board entireGameStates.append(makeCopy(tempBoard))
def createWhite(self): for n in range(8): self.board[6][n] = Pawn("white", 6, n) for n in [0, 7]: self.board[7][n] = Rook("white", 7, n) for n in [1, 6]: self.board[7][n] = Knight("white", 7, n) for n in [2, 5]: self.board[7][n] = Bishop("white", 7, n) self.board[7][3] = Queen("white", 7, 3) self.board[7][4] = King("white", 7, 4)
def createBlack(self): for n in range(8): self.board[1][n] = Pawn("black", 1, n) for n in [0, 7]: self.board[0][n] = Rook("black", 0, n) for n in [1, 6]: self.board[0][n] = Knight("black", 0, n) for n in [2, 5]: self.board[0][n] = Bishop("black", 0, n) self.board[0][3] = Queen("black", 0, 3) self.board[0][4] = King("black", 0, 4)
def reset_board(self): print("New game is starting.") self.turn = 0 self.end_game = 0 self.board = np.empty((8, 8), dtype=object) for i in range(8): self.board[1][i] = Pawn(0, i, 1) # populate with White Pawns self.board[6][i] = Pawn(1, i, 6) # populate with Black Pawns # Rooks self.board[0][0] = Rook(0, 0, 0) # first White Rook self.board[0][7] = Rook(0, 7, 0) # second White Rook self.board[7][0] = Rook(1, 0, 7) # first Black Rook self.board[7][7] = Rook(1, 7, 7) # second Black Rook # Knights self.board[0][1] = Knight(0, 1, 0) # first White Knight self.board[0][6] = Knight(0, 6, 0) # second White Knight self.board[7][1] = Knight(1, 1, 7) # first Black Knight self.board[7][6] = Knight(1, 6, 7) # second Black Knight # Bishops self.board[0][2] = Bishop(0, 2, 0) # first White Bishop self.board[0][5] = Bishop(0, 5, 0) # second White Bishop self.board[7][2] = Bishop(1, 2, 7) # first Black Bishop self.board[7][5] = Bishop(1, 5, 7) # second Black Bishop # Queens self.board[0][3] = Queen(0, 3, 0) # White Queen self.board[7][3] = Queen(1, 3, 7) # Black Queen # Kings self.board[0][4] = King(0, 4, 0) # White King self.board[7][4] = King(1, 4, 7) # Black King # Booleans to indicate if a king is in check self.white_check = 0 self.black_check = 0
def __init__(self): self.color = WHITE self.field = [[Rook(WHITE), Knight(WHITE), Bishop(WHITE), Queen(WHITE), King(WHITE), Bishop(WHITE), Knight(WHITE), Rook(WHITE)], [Pawn(WHITE)] * 8, [None] * 8, [None] * 8, [None] * 8, [None] * 8, [Pawn(BLACK)] * 8, [Rook(BLACK), Knight(BLACK), Bishop(BLACK), Queen(BLACK), King(BLACK), Bishop(BLACK), Knight(BLACK), Rook(BLACK)]] # self.field = [[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], # [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]] self.kings_coords = {BLACK: (7, 4), WHITE: (0, 4)} # координаты королей нужны для
def __init__(self): self.columns = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] self.rows = ['1', '2', '3', '4', '5', '6', '7', '8'] for i in range(1, 9): index = str(i) for j in range (0, 8): if i == 2 : self.board[self.columns[j]+index] = Pawn(self.columns[j], index, "white") elif i == 7: self.board[self.columns[j]+index] = Pawn(self.columns[j], index, "black") elif i > 2 and i < 7: self.board[self.columns[j]+index] = Piece(self.columns[j], index, "blank", " ") #Initialize white pieces self.board['a1'] = Rook('a', '1', "white") self.board['b1'] = Knight('b', '1', "white") self.board['c1'] = Bishop('c', '1', "white") self.board['d1'] = King('d', '1', "white") self.board['e1'] = Queen('e', '1', "white") self.board['f1'] = Bishop('f', '1', "white") self.board['g1'] = Knight('g', '1', "white") self.board['h1'] = Rook('h', '1', "white") #Initialize black pieces self.board['a8'] = Rook('a', '8', "black") self.board['b8'] = Knight('b', '8', "black") self.board['c8'] = Bishop('c', '8', "black") self.board['d8'] = King('d', '8', "black") self.board['e8'] = Queen('e', '8', "black") self.board['f8'] = Bishop('f', '8', "black") self.board['g8'] = Knight('g', '8', "black") self.board['h8'] = Rook('h', '8', "black") #Initialize backup kings for check calculations self.whiteKing = King('d', '1', "white") self.blackKing = King('d', '8', "black")
def init(): game_board = [] # Generate all the rows in the board for i in range(0, 8): game_board.append([]) # Add all the black pieces game_board[0].append(Rook(False, (0, 0))) game_board[0].append(Knight(False, (0, 1))) game_board[0].append(Bishop(False, (0, 2))) game_board[0].append(Queen(False, (0, 3))) game_board[0].append(King(False, (0, 4))) game_board[0].append(Bishop(False, (0, 5))) game_board[0].append(Knight(False, (0, 6))) game_board[0].append(Rook(False, (0, 7))) for i in range(8): game_board[1].append(Pawn(False, (1, i))) # Add the empty spaces for i in range(2, 6): for j in range(8): game_board[i].append(None) # Add all the white pieces for i in range(8): game_board[6].append(Pawn(True, (6, i))) game_board[7].append(Rook(True, (7, 0))) game_board[7].append(Knight(True, (7, 1))) game_board[7].append(Bishop(True, (7, 2))) game_board[7].append(Queen(True, (7, 3))) game_board[7].append(King(True, (7, 4))) game_board[7].append(Bishop(True, (7, 5))) game_board[7].append(Knight(True, (7, 6))) game_board[7].append(Rook(True, (7, 7))) return game_board
def __init__(self, s0, seed): self.m_initialState = s0 self.m_seedRS = seed # m_generator = new Random(m_seedRS); self.m_cost = 0.0 random.seed(seed) if s0.m_agent == Utils.wPawn: self.m_piece = Pawn(0) elif s0.m_agent == Utils.bPawn: self.m_piece = Pawn(1) elif s0.m_agent == Utils.wRook: self.m_piece = Rook(0) elif s0.m_agent == Utils.bRook: self.m_piece = Rook(1) elif s0.m_agent == Utils.wKing: self.m_piece = King(0) elif s0.m_agent == Utils.bKing: self.m_piece = King(1) elif s0.m_agent == Utils.wQueen: self.m_piece = Queen(0) elif s0.m_agent == Utils.bQueen: self.m_piece = Queen(1) elif s0.m_agent == Utils.wBishop: self.m_piece = Bishop(0) elif s0.m_agent == Utils.bBishop: self.m_piece = Bishop(1) elif s0.m_agent == Utils.wKnight: self.m_piece = Knight(0) elif s0.m_agent == Utils.bKnight: self.m_piece = Knight(1) else: # define the rest of pieces print("Chess piece not implemented") sys.exit()
def generateRandomPawn(self, pawnType, pawnCount): """ generate new Pawn with random position based on type of pawn and number of pawn with the type new pawn defined and included into listOfPawn chessBoard adjust to new pawn """ for i in range(pawnCount): while True: x = randint(0, 7) y = randint(0, 7) if (self.chessBoard[y][x] == '.'): break newPawn = Pawn(pawnType, x, y) self.listOfPawn.append(newPawn) self.chessBoard[y][x] = pawnType
def set_pieces(self, board): """ Pairing this Color's pieces on Board. :param board: Board. Board with which pieces will be paired with. :return: None. """ self.my_pawns = [Pawn(i, self.y + self.direction, board) for i in range(8)] self.my_bishops = [Bishop(2, self.y, board), Bishop(5, self.y, board)] self.my_knights = [Knight(1, self.y, board), Knight(6, self.y, board)] self.my_rooks = [Rook(0, self.y, board), Rook(7, self.y, board)] self.my_queens = [Queen(4, self.y, board)] self.my_king = King(3, self.y, board) self.set_starting_pieces() for piece in self.starting_pieces: piece.my_board = board piece.my_color = self piece.img = './ChessArt/'+self.color[0].upper()+piece.name+'.png' board.add_pieces(self.starting_pieces)
def isValidRule(self, board, turn): if self.coded == 'outside': return False x1 = self.coded[0] y1 = self.coded[1] x2 = self.coded[2] y2 = self.coded[3] x1 = x1.upper() x2 = x2.upper() x1 = ord(x1) y1 = int(y1) x2 = ord(x2) y2 = int(y2) x1 = x1 - 65 y1 = 8 - y1 x2 = x2 - 65 y2 = 8 - y2 x1, y1 = y1, x1 x2, y2 = y2, x2 this_piece = board.getPieceObject(x1, y1) piece_name = this_piece.name if (turn is 'BLACK' and piece_name[0] is 'W') or (turn is 'WHITE' and piece_name[0] is 'B'): print('Not your turn') return False if piece_name == 'Wknight' or piece_name == 'Bknight': piece = Knight(piece_name, False) elif piece_name == 'Brook' or piece_name == 'Wrook': piece = Rook(piece_name, False) elif piece_name == 'Wking' or piece_name == 'Bking': piece = King(piece_name, False) elif piece_name == 'Wqueen' or piece_name == 'Bqueen': piece = Queen(piece_name, False) elif piece_name == 'Wbishop' or piece_name == 'Bbishop': piece = Bishop(piece_name, False) elif piece_name == 'Wpawn' or piece_name == 'Bpawn': piece = Pawn(piece_name, False) else: print('No piece selected') return False # print(piece_name) if piece.isValid(board, x1, y1, x2, y2): return True return False
def create_piece(self, piece, square, color): if piece == "Pawn": return Pawn(square, color, self.board) elif piece == "Rook": return Rook(square, color, self.board) elif piece == "Bishop": return Bishop(square, color, self.board) elif piece == "Knight": return Knight(square, color, self.board) elif piece == "Queen": return Queen(square, color, self.board) elif piece == "King": king = King(square, color, self.board) if self.board.game.player1.get_current_color() == color: self.board.game.player1.king = king else: self.board.game.player2.king = king return king else: return None
def __init__(self): def is_in_middle_square(x, y): return ((x == 3) and (y == 3)) or ((x == 4) and (y == 4)) or ((x == 4) and (y == 3)) or ((x == 3) and (y == 4)) # True == White # False == Black def middle_square_color(x, y): return ((x == 3) and (y == 3)) or ((x == 4) and (y == 4)) board = [] for i in range(8): new_line = [] board.append(new_line) for j in range(8): if not is_in_middle_square(i, j): new_line.append('_') else: new_line.append(Pawn(middle_square_color(i, j), i, j)) self.board = board
def __init__(self): self.board = [ 'rnbqkbnr', 'pppppppp', '........', '........', '........', '........', 'PPPPPPPP', 'RNBQKBNR' ] self.move = 'w' # whose move is it? self.castling = 'KQkq' # who can castle self.en_passant = '-' # which square is en passant available on self.halfMove = 0 # number of half moves since last capture or pawn move self.fullMove = 1 # move number # Create piece objects self.board[0] = [ Rook('a8', 'b'), Knight('b8', 'b'), Bishop('c8', 'b'), Queen('d8', 'b'), King('e8', 'b'), Bishop('f8', 'b'), Knight('g8', 'b'), Rook('h8', 'b') ] self.board[1] = [ Pawn('a7', 'b'), Pawn('b7', 'b'), Pawn('c7', 'b'), Pawn('d7', 'b'), Pawn('e7', 'b'), Pawn('f7', 'b'), Pawn('g7', 'b'), Pawn('h7', 'b') ] self.board[7] = [ Rook('a1', 'w'), Knight('b1', 'w'), Bishop('c1', 'w'), Queen('d1', 'w'), King('e1', 'w'), Bishop('f1', 'w'), Knight('g1', 'w'), Rook('h1', 'w') ] self.board[6] = [ Pawn('a2', 'w'), Pawn('b2', 'w'), Pawn('c2', 'w'), Pawn('d2', 'w'), Pawn('e2', 'w'), Pawn('f2', 'w'), Pawn('g2', 'w'), Pawn('h2', 'w') ]
class Game: def __init__(self, num_players): self.num_players = num_players self.num_walls = 20 self.player1 = None self.player2 = None self.player3 = None self.player4 = None self.board = None def startgame(self): game_over = False self.board = BoardGame() if self.num_players == 4: self.player1 = Pawn((4, 8), self.board, 'up', self.num_walls / self.num_players) self.player2 = Pawn((4, 0), self.board, 'down', self.num_walls / self.num_players) self.player3 = Pawn((8, 4), self.board, 'right', self.num_walls / self.num_players) self.player4 = Pawn((0, 4), self.board, 'left', self.num_walls / self.num_players) while not game_over: self.player1.movement() self.player2.movement() self.player3.movement() self.player4.movement() self.player1 = Pawn((4, 8), self.board, 'up', self.num_walls / self.num_players) self.player2 = Pawn((4, 0), self.board, 'down', self.num_walls / self.num_players) while not game_over: self.player2.movement() self.player1.movement()
def startgame(self): game_over = False self.board = BoardGame() if self.num_players == 4: self.player1 = Pawn((4, 8), self.board, 'up', self.num_walls / self.num_players) self.player2 = Pawn((4, 0), self.board, 'down', self.num_walls / self.num_players) self.player3 = Pawn((8, 4), self.board, 'right', self.num_walls / self.num_players) self.player4 = Pawn((0, 4), self.board, 'left', self.num_walls / self.num_players) while not game_over: self.player1.movement() self.player2.movement() self.player3.movement() self.player4.movement() self.player1 = Pawn((4, 8), self.board, 'up', self.num_walls / self.num_players) self.player2 = Pawn((4, 0), self.board, 'down', self.num_walls / self.num_players) while not game_over: self.player2.movement() self.player1.movement()
def __init__(self, mateInOne=False, castleBoard=True, pessant=False, promotion=False, testing= 0): self.pieces = [] self.whiteCaptured = [] self.blackCaptured = [] self.history = [] self.points = 0 self.currentSide = WHITE self.movesMade = 0 self.checkmate = False #testing 1: normal board if not mateInOne and not pessant and not promotion and testing < 2: self.pieces.extend([Rook(self, BLACK, C(0, 7), 0), Knight(self, BLACK, C(1, 7), 0), Bishop(self, BLACK, C(2, 7), 0), Queen(self, BLACK, C(3, 7), 0), King(self, BLACK, C(4, 7), 0), Bishop(self, BLACK, C(5, 7), 1), Knight(self, BLACK, C(6, 7), 1), Rook(self, BLACK, C(7, 7), 1)]) for x in range(8): self.pieces.append(Pawn(self, BLACK, C(x, 6), x)) for x in range(8): self.pieces.append(Pawn(self, WHITE, C(x, 1), x)) self.pieces.extend([Rook(self, WHITE, C(0, 0), 0), Knight(self, WHITE, C(1, 0), 0), Bishop(self, WHITE, C(2, 0), 0), Queen(self, WHITE, C(3, 0), 0), King(self, WHITE, C(4, 0), 0), Bishop(self, WHITE, C(5, 0), 1), Knight(self, WHITE, C(6, 0), 1), Rook(self, WHITE, C(7, 0), 1)]) elif promotion: pawnToPromote = Pawn(self, WHITE, C(1, 6), 8) pawnToPromote.movesMade = 1 kingWhite = King(self, WHITE, C(4, 0), 2) kingBlack = King(self, BLACK, C(3, 2), 2) self.pieces.extend([pawnToPromote, kingWhite, kingBlack]) elif pessant: pawn = Pawn(self, WHITE, C(1, 4), 8) pawn2 = Pawn(self, BLACK, C(2, 6), 8) kingWhite = King(self, WHITE, C(4, 0), 2) kingBlack = King(self, BLACK, C(3, 2), 2) self.pieces.extend([pawn, pawn2, kingWhite, kingBlack]) self.history = [] self.currentSide = BLACK self.points = 0 self.movesMade = 0 self.checkmate = False firstMove = Move(pawn2, C(2, 4)) self.makeMove(firstMove) self.currentSide = WHITE return #white pawn being able to capture 1 piece elif testing == 2: self.pieces.extend([Bishop(self, BLACK, C(5, 3), 0)]) self.pieces.extend([Pawn(self, WHITE, C(6, 2), 0)]) #testing for pawn being able to capture 2 pieces elif testing ==3: self.pieces.extend([Bishop(self, BLACK, C(4, 3), 0)]) self.pieces.extend([Knight(self, BLACK, C(2, 3), 0)]) self.pieces.extend([Pawn(self, WHITE, C(3, 2), 0)]) #testing taking a piece that can be captured by 2 pieces elif testing ==4: self.pieces.extend([Bishop(self, WHITE, C(3, 1), 0)]) self.pieces.extend([Knight(self, BLACK, C(2, 2), 0)]) self.pieces.extend([Queen(self, WHITE, C(5, 2), 0)]) #black queen capturing 1 piece elif testing ==5: self.pieces.extend([Rook(self, WHITE, C(3, 4), 0)]) self.pieces.extend([Knight(self, WHITE, C(7, 5), 0)]) self.pieces.extend([Queen(self, BLACK, C(4, 5), 0)]) #black castle queen side with scattered pieces elif testing ==6: self.pieces.extend([Rook(self, BLACK, C(0, 7), 0)]) self.pieces.extend([King(self, BLACK, C(4, 7), 0)]) self.pieces.extend([Pawn(self, WHITE, C(2, 3), 0)]) self.pieces.extend([Pawn(self, WHITE, C(3, 2), 0)]) self.pieces.extend([Pawn(self, WHITE, C(4, 3), 0)]) self.pieces.extend([Pawn(self, WHITE, C(5, 2), 0)]) self.pieces.extend([Pawn(self, WHITE, C(6, 3), 0)]) self.pieces.extend([Rook(self, WHITE, C(0, 3), 0)]) elif testing ==7: self.pieces.extend([Rook(self, BLACK, C(7, 7), 0)]) self.pieces.extend([King(self, BLACK, C(4, 7), 0)]) self.pieces.extend([Pawn(self, WHITE, C(2, 3), 0)]) self.pieces.extend([Pawn(self, WHITE, C(3, 2), 0)]) self.pieces.extend([Pawn(self, WHITE, C(4, 3), 0)]) self.pieces.extend([Pawn(self, WHITE, C(5, 2), 0)]) self.pieces.extend([Pawn(self, WHITE, C(6, 3), 0)]) self.pieces.extend([Rook(self, WHITE, C(0, 3), 0)]) elif testing ==8: self.pieces.extend([Rook(self, BLACK, C(0, 0), 0)]) self.pieces.extend([King(self, BLACK, C(4, 0), 0)]) self.pieces.extend([Pawn(self, WHITE, C(2, 3), 0)]) self.pieces.extend([Pawn(self, WHITE, C(3, 2), 0)]) self.pieces.extend([Pawn(self, WHITE, C(4, 3), 0)]) self.pieces.extend([Pawn(self, WHITE, C(5, 2), 0)]) self.pieces.extend([Pawn(self, WHITE, C(6, 3), 0)]) self.pieces.extend([Rook(self, WHITE, C(0, 3), 0)]) elif testing ==9: self.pieces.extend([Rook(self, BLACK, C(7, 0), 0)]) self.pieces.extend([King(self, BLACK, C(4, 0), 0)]) self.pieces.extend([Pawn(self, WHITE, C(2, 3), 0)]) self.pieces.extend([Pawn(self, WHITE, C(3, 2), 0)]) self.pieces.extend([Pawn(self, WHITE, C(4, 3), 0)]) self.pieces.extend([Pawn(self, WHITE, C(5, 2), 0)]) self.pieces.extend([Pawn(self, WHITE, C(6, 3), 0)]) self.pieces.extend([Rook(self, WHITE, C(0, 3), 0)]) elif testing ==10: self.pieces.extend([Pawn(self, BLACK, C(6, 6), 0)]) self.pieces.extend([Pawn(self, WHITE, C(5, 4), 0)]) # need to move the pawn so that the en passant is a legal move elif testing == 11: self.pieces.extend([Knight(self, WHITE, C(4, 4), 0)]) self.pieces.extend([Queen(self, BLACK, C(7, 1), 0)]) elif testing == 12: self.pieces.extend([Rook(self, BLACK, C(0, 7), 0), Knight(self, BLACK, C(1, 7), 0), Bishop(self, BLACK, C(2, 7), 0), Queen(self, BLACK, C(3, 7), 0), King(self, BLACK, C(4, 7), 0), Bishop(self, BLACK, C(5, 7), 1), Knight(self, BLACK, C(6, 7), 1), Rook(self, BLACK, C(7, 7), 1)]) for x in range(8): self.pieces.append(Pawn(self, BLACK, C(x, 6), x)) for x in range(8): self.pieces.append(Pawn(self, WHITE, C(x, 1), x)) self.pieces.extend([Rook(self, WHITE, C(0, 0), 0), Knight(self, WHITE, C(1, 0), 0), Bishop(self, WHITE, C(2, 0), 0), Queen(self, WHITE, C(3, 0), 0), King(self, WHITE, C(4, 0), 0), Bishop(self, WHITE, C(5, 0), 1), Knight(self, WHITE, C(6, 0), 1), Rook(self, WHITE, C(7, 0), 1)]) elif testing == 13: self.pieces.extend([Rook(self, BLACK, C(0, 4), 0), Knight(self, BLACK, C(1, 7), 0), Bishop(self, BLACK, C(1, 2), 0), Queen(self, BLACK, C(3, 7), 0), King(self, BLACK, C(4, 7), 0), Bishop(self, BLACK, C(5, 7), 1), Knight(self, BLACK, C(6, 4), 1), Rook(self, BLACK, C(7, 7), 1)]) for x in range(8): self.pieces.append(Pawn(self, BLACK, C(x, 6), x)) for x in range(7): self.pieces.append(Pawn(self, WHITE, C(x, 1), x)) self.pieces.extend([Pawn(self, WHITE, C(6, 2), 7), Rook(self, WHITE, C(0, 2), 0), Knight(self, WHITE, C(3, 3), 0), Bishop(self, WHITE, C(2, 0), 0), Queen(self, WHITE, C(3, 0), 0), King(self, WHITE, C(4, 0), 0), Bishop(self, WHITE, C(5, 0), 1), Knight(self, WHITE, C(6, 0), 1), Rook(self, WHITE, C(1, 5), 1)])
def __createPawn(self, coordinateX, coordinateY): pawn = Pawn(coordinateX, coordinateY, self.__color) return pawn
def createPawnToList(self, cordinateX, cordinateY): self.list.append( Pawn(cordinateX, cordinateY, self.getRadius(), (self.getColor()), self.getWindow()))
def add_pawns(self): row = 1 for color in range(-1, 2, 2): for area in range(8): self.board[row][area].checker = Pawn(color, (row, area)) row = 6
def setUpBoard(self): #set up white self.white = [ Pawn(0, 1, True), Pawn(1, 1, True), Pawn(2, 1, True), Pawn(3, 1, True), Pawn(4, 1, True), Pawn(5, 1, True), Pawn(6, 1, True), Pawn(7, 1, True), Knight(1, 0, True), Knight(6, 0, True), Bishop(2, 0, True), Bishop(5, 0, True), Rook(0, 0, True), Rook(7, 0, True), King(4, 0, True), Queen(3, 0, True) ] #set up Black self.black = [ Pawn(0, 6, False), Pawn(1, 6, False), Pawn(2, 6, False), Pawn(3, 6, False), Pawn(4, 6, False), Pawn(5, 6, False), Pawn(6, 6, False), Pawn(7, 6, False), Knight(1, 7, False), Knight(6, 7, False), Bishop(2, 7, False), Bishop(5, 7, False), Rook(0, 7, False), Rook(7, 7, False), King(4, 7, False), Queen(3, 7, False) ] #set up board for obj in self.white: # print(obj.x, obj.y) self.board[obj.x][obj.y] = obj for obj in self.black: self.board[obj.x][obj.y] = obj
def add(self, color, x, y): if not self.board[x][y] == '_': return False else: self.board[x][y] = Pawn(color, x, y) return True