def __init__(self): self.board = ChessBoard() self.view = ChessView(self) self.view.showMsg("Red") self.view.draw_board(self.board) self.player_is_red = True self.ai = AI()
def __init__(self, anId, players): self.board = ChessBoard() self.whiteUserName = players[0] self.blackUserName = players[1] self.whoseTurn = players[0] self.columnLetters = ["a", "b", "c", "d", "e", "f", "g", "h"] super(ChessGame, self).__init__(anId, "ChessGame", players)
class ChessGame: def __init__(self): self.board = ChessBoard() self.view = ChessView(self) self.view.showMsg("Red") self.view.draw_board(self.board) self.player_is_red = True self.ai = AI() def start(self): self.view.start() def callback(self, event): rx, ry = Tools.real_coord(event.x), Tools.real_coord(event.y) if self.board.select(rx, ry, self.player_is_red): self.player_is_red = not self.player_is_red self.view.showMsg("Green") self.view.draw_board(self.board) if not self.player_is_red: # the round of AI list_step = self.ai.find_next_step(self.board, 2, sys.maxsize) self.board.select(list_step[1][0][0], list_step[1][0][1], self.player_is_red) self.board.select(list_step[1][0][0] + list_step[1][0][2], list_step[1][0][1] + list_step[1][0][3], self.player_is_red) self.player_is_red = not self.player_is_red self.view.showMsg("Red") self.view.draw_board(self.board)
class ChessSimulatorManager: def __init__(self): self.board = ChessBoard() self.whiteSimulatorStream = None self.blackSimulatorStream = None self.chessGraphics = ChessGraphicsManager() print("SimulatorManager loaded, no simulator streams locked") def tick(self): pass def run(self): while True: for event in pygame.event.get(): if(event.type == pygame.QUIT): sys.exit(0) elif(event.type == pygame.MOUSEBUTTONDOWN): self.toggleClickedPos(event.pos) else: pass self.chessGraphics.render(self.board) def toggleClickedPos(self, pos): position = ChessPosition(int(pos[0]/40), 7-int(pos[1]/40)) shouldSet = False if(self.chessGraphics.selectedPosition is None): self.chessGraphics.selectedPosition = position else: if(self.chessGraphics.selectedPosition.isEqualTo(position)): self.chessGraphics.selectedPosition = None else: piece = self.board.pieceAt(self.chessGraphics.selectedPosition) occupant = self.board.pieceAt(position) if(piece and occupant and occupant.color == piece.color): self.chessGraphics.selectedPosition = position elif(piece is not None and piece.color == self.board.activeColor): move = ChessMove(self.chessGraphics.selectedPosition, position, self.board) self.board.processMove(move) self.chessGraphics.selectedPosition = None else: self.chessGraphics.selectedPosition = None def lockSimulatorStream(self, simulatorStream, color): if(color == COLOR.WHITE): self.whiteSimulatorStream = simulatorStream print("White simulator stream locked") else: self.blackSimulatorStream = simulatorStream print("Black simulator stream locked") if(self.bothSimulatorStreamsLocked()): print("Both simulator streams are locked, SimulatorManager primed") def bothSimulatorStreamsLocked(self): if(self.whiteSimulatorStream and self.blackSimulatorStream): return True return False
def gen_possible_moves(board, black=True): """ Goes through every single move on the board, finds which ones are legal, then returns a list of move objects that are legal""" legal_moves = [] # Iterating through every possible move on the board for (sx, sy, ex, ey) in itertools.product(range(8), range(8), range(8), range(8)): if ChessBoard.legal_move(board, (sx, sy), (ex, ey), black): legal_moves.append( ChessBoard.move(board, (sx, sy), (ex, ey), black)) return legal_moves
def test2(): chessboard = ChessBoard() chessboard.init_board() #在10,8位置上放置黑棋 chessboard.set_chess((10, 8), 'x') #创建一个棋子对象 颜色为白棋 位置为4,7 chessman = ChessMan() chessman.set_pos((4, 7)) chessman.set_color('o') chessboard.set_chessman(chessman) chessboard.print_board()
def __init__(self): self.size = [self.SCREEN_WIDTH, self.SCREEN_HEIGHT] self.cb = ChessBoard() self.white_to_move = True self.destx = 0 self.desty = 0 self.x = 0 self.y = 0 self.last_move = None self.is_square_selected = None self.promote_to = Piece.QUEEN
def __init__(self,anId,players): self.board = ChessBoard() self.whiteUserName = players[0] self.blackUserName = players[1] self.whoseTurn = players[0] self.columnLetters = ["a","b","c","d","e","f","g","h"] super(ChessGame, self).__init__(anId,"ChessGame",players)
def legal_moves(self, chess_board, legal=True): boards = [] moves = [(1, 2), (2, 1), (2, -1), (1, -2), (-1, -2), (-2, -1), (-2, 1), (-1, 2)] for move in moves: new_pos = self.pos + np.array(move) if inside(new_pos) and not chess_board.is_p(new_pos, color=self.color): b = copy.deepcopy(chess_board.board) b[tuple(new_pos)] = b[tuple(self.pos)] b[tuple(new_pos)].pos = new_pos b[tuple(self.pos)] = None # It is a capture if chess_board.is_p(new_pos, color=ChessBoard.n(self.color)): move_type = "capture" # Just a regular old move else: move_type = "move" new_board = chess_board.make_move(b, new_pos, move_type, None) if legal: if new_board.is_legal(): boards.append(new_board) else: boards.append(new_board) return boards
def createBoard(self): dict = self.ui.comboBox_dict.currentIndex() numX = int(self.ui.lineEdit_numX.text()) numY = int(self.ui.lineEdit_numY.text()) squareSize = float(self.ui.lineEdit_squareSize.text()) dpi = int(self.ui.lineEdit_DPI.text()) imgSize = (float(self.ui.lineEdit_printX.text()), float(self.ui.lineEdit_printY.text())) if dict == 0: self.boardType = 0 self.calibBoard = ChessBoard.ChessBoard() self.board = self.calibBoard.create((numX, numY), squareSize, dpi, imgSize) # Create Board else: self.boardType = 1 self.calibBoard = CharucoBoard.CharucoBoard() self.board = self.calibBoard.create(numX, numY, dict - 1, squareSize, imgSize, dpi) #Create Board if self.board is None: ## splite Qt segment self.ui.label.setText("Create Failed,Please confire parameter!") return # showBoard image = QImage(self.board[:], self.board.shape[1], self.board.shape[0], self.board.shape[1], QImage.Format_Grayscale8) #ndarray -> QImage showBoard = QPixmap(image) #QImage -> Qpixmap if showBoard.width() > showBoard.height(): #resize Qpixmap showBoard = showBoard.scaledToWidth(self.ui.label.width()) else: showBoard = showBoard.scaledToHeight(self.ui.label.height()) self.ui.label.setPixmap(showBoard) #show
def testBoardSize(self): board = ChessBoard.ChessBoard() self.assertEqual(board.BOARD_WIDTH, 8) self.assertEqual(board.BOARD_HEIGHT, 8) for i in range(board.BOARD_WIDTH): for j in range (board.BOARD_HEIGHT): self.assertEqual(board.board[i][j], None)
def testAddPiece(self): board = ChessBoard.ChessBoard() pawn1 = pieces.Pawn(PieceColor.WHITE) pawn2 = pieces.Pawn(PieceColor.BLACK) rook1 = pieces.Rook(PieceColor.WHITE) rook2 = pieces.Rook(PieceColor.BLACK) bishop1 = pieces.Bishop(PieceColor.BLACK) bishop2 = pieces.Bishop(PieceColor.WHITE) knight1 = pieces.Knight(PieceColor.BLACK) knight2 = pieces.Knight(PieceColor.WHITE) queen1 = pieces.Queen(PieceColor.BLACK) queen2 = pieces.Queen(PieceColor.WHITE) king1 = pieces.King(PieceColor.BLACK) king2 = pieces.King(PieceColor.WHITE) self.assertTrue(board.addPiece('2a', pawn1)) self.assertTrue(board.addPiece('7a', pawn2)) self.assertTrue(board.addPiece('1a', rook1)) self.assertTrue(board.addPiece('8a', rook2)) self.assertTrue(board.addPiece('8b', knight1)) self.assertTrue(board.addPiece('1b', knight2)) self.assertTrue(board.addPiece('8c', bishop1)) self.assertTrue(board.addPiece('1c', bishop2)) self.assertTrue(board.addPiece('8d', queen1)) self.assertTrue(board.addPiece('1d', queen2)) self.assertTrue(board.addPiece('8e', king1)) self.assertTrue(board.addPiece('1e', king2)) #try to add piece at invalid coordinates self.assertFalse(board.addPiece('9e', king2)) self.assertFalse(board.addPiece('9a', king2)) #try to add piece at non empty cell self.assertFalse(board.addPiece('1d', queen2)) self.assertFalse(board.addPiece('1e', king2))
def best_move(board, depth, black=True): """ Scores all the possible moves for the computer make by calling recur_score_move() on each move""" moves = gen_possible_moves(board, black) # For viewing processing time print("Legal Moves: " + str(len(moves))) print("-" * len(moves)) for move in moves: print("#", end="", flush=True) # Creating a new board, where the move was executed new_board = ChessBoard.chessboard(board) # Executing and scoreing move` new_board.move_piece(move.start_coords, move.end_coords) move.score = score(board, move, black) # Recursively scoring next gen possible moves move.score -= recur_score_move( depth, new_board, black=not black, curr_depth=0) / (PRUNE ) # ** depth) print() # Creating new, blank move with default score to be compared to max_move max_move = moves[0] # Finding the highest scoring move for move in moves: if move.score > max_move.score: max_move = move return max_move
def __init__(self, parent, pieceWidth=48, pieceHeight=48): Tkinter.Frame.__init__(self, parent) self.parent = parent # left side self.chessBoard = ChessBoard.ChessBoard(self, pieceWidth, pieceHeight) self.chessBoard.draw() # right side self.reserveBoard = ReserveBoard.ReserveBoard(self, pieceWidth, pieceHeight) self.reserveBoard.draw() self.margin = 4 self.width = self.margin + self.chessBoard.width + self.reserveBoard.width + self.margin self.height = self.margin + self.chessBoard.height + self.margin #self.chessBoard.pack(side=Tkinter.LEFT) #self.reserveBoard.pack(side=Tkinter.LEFT) self.chessBoard.grid(row=0, column=0) self.reserveBoard.grid(row=0, column=1) #print self.chessBoard.grid_info() #print self.reserveBoard.grid_info() w = Tkinter.Label(self, text="row0_column2", bg="red", fg="white") w.grid(row=0, column=2) w = Tkinter.Label(self, text="row1_column2", bg="red", fg="white") w.grid(row=1, column=2) w = Tkinter.Label(self, text="row2_column2", bg="red", fg="white") w.grid(row=2, column=2)
def __init__(self, in_ai_count, in_ai_function, in_play_playout, in_delay, in_end_delay, batch_size, search_threads, processor, num_gpus, res_block_nums, human_color = "b"): self.human_color = human_color self.current_player = "w" self.players = {} self.players[self.human_color] = "human" ai_color = "w" if self.human_color == "b" else "b" self.players[ai_color] = "AI" ChessGame.board = ChessBoard(self.human_color == 'b') self.view = ChessView(self, board=ChessGame.board) self.view.showMsg("Loading Models...") #"Red" player_color self.view.draw_board(self.board) ChessGame.game_mode = in_ai_count self.ai_function = in_ai_function self.play_playout = in_play_playout self.delay = in_delay self.end_delay = in_end_delay self.win_rate = {} self.win_rate['w'] = 0.0 self.win_rate['b'] = 0.0 self.view.root.update() self.cchess_engine = cchess_main(playout=self.play_playout, in_batch_size=batch_size, exploration=False, in_search_threads=search_threads, processor=processor, num_gpus=num_gpus, res_block_nums=res_block_nums, human_color=human_color)
def init(data): data.mode = "beginning" data.y = data.height / 4 * 3.3 data.x1 = data.width * .098 data.x2 = data.width * .3629 data.x3 = data.width / 20 * 12.6 data.x4 = data.width / 19 * 17 data.r = data.width / 17 data.margin = int(data.width / 31) data.mainBoard = CB.Board(data.width, data.height) data.mainBoard.makeBoard() data.player = "White" data.timerFiredCount = 0 data.origRow = None data.origCol = None data.newRow = None data.newCol = None data.moved = False data.hover = None data.checkMate = None data.instructImage = "./MoveImages/MovePawn.png" data.music = "On" try: return data.other.ID except: data.me = Person(data.mainBoard) data.other = Person(data.mainBoard)
class ChessGame(Game): def __init__(self, anId, players): self.board = ChessBoard() self.whiteUserName = players[0] self.blackUserName = players[1] self.whoseTurn = players[0] self.columnLetters = ["a", "b", "c", "d", "e", "f", "g", "h"] super(ChessGame, self).__init__(anId, "ChessGame", players) def makeMove(self, fromRow, fromCol, toRow, toCol): fromCol = self.columnLetters.index(fromCol) toCol = self.columnLetters.index(toCol) errorMessage = self.board.makeMove(fromRow, fromCol, toRow, toCol) if (errorMessage == ""): self.changeTurn() return "" else: return errorMessage def changeTurn(self): if (self.whoseTurn == self.players[0]): self.whoseTurn = self.players[1] else: self.whoseTurn = self.players[0] super(ChessGame, self).changeTurn(self.whoseTurn) def getBoardAsList(self): return self.board.getAsList() def json(self): return { "chessGame": { "gameId": self.getId(), "board": self.board.json(), "players": self.players, "whoseTurn": self.whoseTurn } } def decode(self, json): self.board.decode(json["board"]) self.players = json["players"] self.whoseTurn = json["whoseTurn"] self.whiteUserName = self.players[0] self.blackUserName = self.players[1] super(ChessGame, self).decode(json["gameId"], self.players, self.whoseTurn)
class ChessGame(Game): def __init__(self,anId,players): self.board = ChessBoard() self.whiteUserName = players[0] self.blackUserName = players[1] self.whoseTurn = players[0] self.columnLetters = ["a","b","c","d","e","f","g","h"] super(ChessGame, self).__init__(anId,"ChessGame",players) def makeMove(self,fromRow,fromCol,toRow,toCol): fromCol = self.columnLetters.index(fromCol) toCol = self.columnLetters.index(toCol) errorMessage = self.board.makeMove(fromRow,fromCol, toRow, toCol) if (errorMessage == ""): self.changeTurn() return "" else: return errorMessage def changeTurn(self): if (self.whoseTurn == self.players[0]): self.whoseTurn = self.players[1] else: self.whoseTurn = self.players[0] super(ChessGame, self).changeTurn(self.whoseTurn) def getBoardAsList(self): return self.board.getAsList() def json(self): return { "chessGame": { "gameId" : self.getId(), "board" : self.board.json(), "players" : self.players, "whoseTurn" : self.whoseTurn } } def decode(self,json): self.board.decode(json["board"]) self.players = json["players"] self.whoseTurn = json["whoseTurn"] self.whiteUserName = self.players[0] self.blackUserName = self.players[1] super(ChessGame, self).decode(json["gameId"],self.players,self.whoseTurn)
def read_info_form_database(self, filename): # 从文件读取开局信息 with open(filename, "r", encoding='utf-8') as f: s = f.read().splitlines() del s[0] for i in range(len(s)): s[i] = s[i].split(' ') UI = ChessBoard.ChessBoard() UI.my_s(1, s)
def test3(self, ThreeThree1): UI = ChessBoard.ChessBoard() board = [[0 for n in range(15)] for i in range(15)] for i in range(len(ThreeThree1)): x = 7 - ThreeThree1[i][1] y = 7 + ThreeThree1[i][0] if ThreeThree1[i][2] == 1: board[x][y] = 1 UI.out_gobang_board(self.total, board)
def __init__(self, parent, pieceWidth=64, pieceHeight=64): Tkinter.Frame.__init__(self, parent) self.parent = parent self.boardMap = {} self.PgnParser = None self.stateIndex = 0 # widget self.chessBoard = ChessBoard.ChessBoard(self, pieceWidth, pieceHeight) self.chessBoard.setFEN(Common.initChessFEN) self.chessBoard.refreshCanvasFromState() # status thingies self.playerInfoW = Tkinter.Label(self, text="", bg="white", fg="black") self.playerTimeW = Tkinter.Label(self, text="", bg="green", fg="black") self.playerInfoB = Tkinter.Label(self, text="", bg="black", fg="white") self.playerTimeB = Tkinter.Label(self, text="", bg="green", fg="black") # buttons go into frame self.btnFrame = Tkinter.Frame(self) self.btnFlip = Tkinter.Button(self.btnFrame, text="FLIP", command=self.btnFlipCb) self.btnStart = Tkinter.Button(self.btnFrame, text="|<", command=self.btnStartCb) self.btnBackward = Tkinter.Button(self.btnFrame, text="<", command=self.btnBackwardCb) self.btnForward = Tkinter.Button(self.btnFrame, text=">", command=self.btnForwardCb) self.btnEnd = Tkinter.Button(self.btnFrame, text=">|", command=self.btnEndCb) self.playerInfoW.grid(row=0, column=1, sticky=Tkinter.E + Tkinter.W) self.playerTimeW.grid(row=0, column=0) self.playerInfoB.grid(row=0, column=2, sticky=Tkinter.E + Tkinter.W) self.playerTimeB.grid(row=0, column=3) self.chessBoard.grid(row=1, column=0, columnspan=4) self.playerInfoW.grid(row=2, column=1, sticky=Tkinter.E + Tkinter.W) self.playerTimeW.grid(row=2, column=0) self.playerInfoB.grid(row=2, column=2, sticky=Tkinter.E + Tkinter.W) self.playerTimeB.grid(row=2, column=3) self.btnFlip.pack(side=Tkinter.LEFT) self.btnStart.pack(side=Tkinter.LEFT) self.btnBackward.pack(side=Tkinter.LEFT) self.btnForward.pack(side=Tkinter.LEFT) self.btnEnd.pack(side=Tkinter.LEFT) self.btnFrame.grid(row=3, columnspan=4)
def main(): #创建棋盘类 chessboard = ChessBoard() #创建 chessman = ChessMan() #人的棋子 chesscomputer = ChessMan() #电脑的棋子 #创建Engine对象 engine = Engine(chessboard) #开始游戏 engine.play(chessboard, chessman, chesscomputer)
def test4(): chessboard = ChessBoard() chessboard.init_board() engine = Engine(chessboard) #创建chessMan对象 并写入棋子颜色 chessman = ChessMan() chessman.set_color('x') input = '13,b' engine.parse_uesr_input(input, chessman) #把该棋子对象放置到棋盘上 chessboard.set_chessman(chessman) #打印棋盘 chessboard.print_board()
def test3(): chessboard = ChessBoard() chessboard.init_board() #创建Engine对象 engine = Engine(chessboard) #创建chessMan对象 并写入棋子颜色 chessman = ChessMan() chessman.set_color('o') engine.computer_go(chessman) #方法中填入位置 #把该棋子对象放置到棋盘上 chessboard.set_chessman(chessman) #打印棋盘 chessboard.print_board()
def __init__(self, mode=1, dis=0, showMove=True, showSearch=False, showGUI=True, saveInfo=False): self.board = ChessBoard() self.Player_Side = False self.GameMode = mode self.distribution = dis self.ai_0 = AI() self.ai_1 = AI() self.ShowMoveInfo = showMove self.ShowSearchInfo = showSearch self.ShowGraphUI = showGUI self.SaveInfo = saveInfo self.view = ChessView(self)
def CPU_v_CPU(): while True: ChessBoard.draw_board(board, True) A_max_move = best_move(board, DEPTH, False) A_max_move.execute() print("<<<", end=" ") print("Move: " + str(A_max_move)) print(" Score: " + str(A_max_move.score)) B_max_move = best_move(board, DEPTH, True) B_max_move.execute() print("<<<", end=" ") print("Move: " + str(B_max_move)) print(" Score: " + str(B_max_move.score)) # Ascii bell tone print("\a")
def testGetCoordinates(self): board = ChessBoard.ChessBoard() for i in range(10): x = random.randint(0, board.BOARD_HEIGHT) y = random.randint(0, board.BOARD_WIDTH) buf = str(8 - x) + chr(ord('a') + y) (x1, y1) = board.getCoordinates(buf) self.assertEqual((x, y), (x1, y)) for i in range(10): x = random.randint(board.BOARD_HEIGHT + 2, 100) y = random.randint(board.BOARD_WIDTH + 1, 26) buf = str(x) + chr(ord('a') + y) (x1, y1) = board.getCoordinates(buf) self.assertEqual((x1, y1), (-1, -1))
def test1(self): UI = ChessBoard.ChessBoard() ThreeThree = copy.deepcopy(self.ThreeThree) for i in range(len(ThreeThree)): self.total = i + 1 # print(ThreeThree[i]) board = [[0 for n in range(15)] for i in range(15)] for j in range(len(ThreeThree[i])): x = 7 - ThreeThree[i][j][1] y = 7 + ThreeThree[i][j][0] if ThreeThree[i][j][2] == 1: board[x][y] = 1 UI.out_gobang_board(self.total, board) print()
def test2(self): UI = ChessBoard.ChessBoard() FourFour = copy.deepcopy(self.FourFour) for i in range(len(FourFour)): self.total = i + 1 # print(FourFour[i]) board = [[0 for n in range(15)] for k in range(15)] for j in range(len(FourFour[i])): x = 7 - FourFour[i][j][1] y = 7 + FourFour[i][j][0] if FourFour[i][j][2] == 1: board[x][y] = 1 UI.out_gobang_board(self.total, board) print()
class ChessGame: board = ChessBoard() player_is_red = True def __init__(self): self.view = ChessView(self) self.view.showMsg("Red") self.view.draw_board(self.board) def start(self): self.view.start() def callback(self, event): print event.x, event.y rx, ry = real_coord(event.x), real_coord(event.y) if self.board.select(rx, ry, self.player_is_red): self.player_is_red = not self.player_is_red self.view.showMsg("Red" if self.player_is_red else "Green") self.view.draw_board(self.board)
def test(self): UI = ChessBoard.ChessBoard() UI.out_gobang_board(self.total, self.board) for i in range(15): for j in range(15): if self.board[i][j] == 1: if self.charge_three_forbid(i, j): row = chr(ord("A") + i) col = chr(ord("A") + j) s = "" s += row + col print( "�ܲ��Ұ����������˵��װ��Ľ��ֵ㣡�����е��������ֵ�Ϊ (%s) ��" % (s)) if self.charge_four_forbid(i, j): row = chr(ord("A") + i) col = chr(ord("A") + j) s = "" s += row + col print( "�ܲ��Ұ����������˵��װ��Ľ��ֵ㣡�����е����Ľ��ֵ�Ϊ (%s) ��" % (s)) if self.charge_long_forbid(i, j): row = chr(ord("A") + i) col = chr(ord("A") + j) s = "" s += row + col print( "�ܲ��Ұ����������˵��װ��Ľ��ֵ㣡�����еij������ֵ�Ϊ (%s) ��" % (s)) player_input = input( "�����������ƶ���λ��:") # ������������������ x = ord(player_input[0].upper()) - ord("A") # ת������ y = ord(player_input[1].upper()) - ord("A") self.board[x][y] = 1 # ����Ϊ���� self.total += 1 self.test()
def recur_score_move(depth, board, black=True, curr_depth=0): """ Scores the board by recursing `depth` moves deep. Prunes tree based by only taking the best half of moves""" tot_score = 0 # Finding all the legal moves for the computer moves = gen_possible_moves(board, black) # Pruning, finding the best `number` of moves # Scoring for move in moves: move.score = score(board, move, black) # Sorting by score sorted_moves = sorted(moves, key=lambda x: x.score, reverse=True) moves = sorted_moves[0:PRUNE] if curr_depth < depth: # Runs if the maximum recursion depth is not reached # Scoring all the moves for move in moves: # Creating a new board, where the move was executed new_board = ChessBoard.chessboard(board) new_board.move_piece(move.start_coords, move.end_coords) # Scoring the move by adding all its own possible moves and subtracting the others. # Deals with averages tot_score -= recur_score_move( depth, new_board, black=not black, curr_depth=curr_depth + 1) / (PRUNE) # ** depth) # returning score to collapse tree if not root # print(curr_depth) # If computer's turn to move, curr_depth will be an odd number and score will be returned positive # if curr_depth%2: # os.system('cls') # ChessBoard.draw_board(board, True) return tot_score
def __init__(self, parent, pieceWidth=48, pieceHeight=48): Tkinter.Frame.__init__(self, parent) self.parent = parent # on piece capture, send to other side self.transferPieces = 1 # left side self.chessBoard = ChessBoard.ChessBoard(self, pieceWidth, pieceHeight) # right side self.holdingBoard = HoldingBoard.HoldingBoard(self, pieceWidth, pieceHeight) self.width = self.chessBoard.width + self.holdingBoard.width self.height = self.chessBoard.height self.chessBoard.grid(row=0, column=0, padx=2) self.holdingBoard.grid(row=0, column=1, pady=2) self.boardMap = {}
def test_castle_result(self): board = ChessBoard("boards/castling.cb") ks = ChessBoard("boards/castle-ks-result.cb") qs = ChessBoard("boards/castle-qs-result.cb") self.assertTrue(board.move(self.bks).move(self.wks).equals(ks)) self.assertTrue(board.move(self.bqs).move(self.wqs).equals(qs))
def test_castle_into_check(self): board = ChessBoard("boards/castle-into-check.cb") self.assertTrue(board.legalMove(self.bks)) self.assertTrue(board.legalMove(self.bqs)) self.assertFalse(board.legalMove(self.wks)) self.assertFalse(board.legalMove(self.wqs))
def test_castle_onto_piece(self): board = ChessBoard("boards/castle-onto-piece.cb") self.assertFalse(board.legalMove(self.bks)) self.assertFalse(board.legalMove(self.bqs)) self.assertFalse(board.legalMove(self.wks)) self.assertFalse(board.legalMove(self.wqs))
def test_castle_rook_path_blocked(self): board = ChessBoard("boards/castle-rook-path-blocked.cb") self.assertFalse(board.legalMove(self.bqs)) self.assertFalse(board.legalMove(self.wqs))
def __init__(self): self.board = ChessBoard() self.whiteSimulatorStream = None self.blackSimulatorStream = None self.chessGraphics = ChessGraphicsManager() print("SimulatorManager loaded, no simulator streams locked")