def main(): # 初始化棋盘 chessboard = ChessBoard() chessboard.initBoard() # 初始化引擎类 engine = Engine(chessboard) engine.play()
def set_up(): global cb, sq # load the map and set up the chessboard cb = ChessBoard("maps/sample.map") # the size of a square in px # TODO add config sq = 80 # define colors red = (255, 0, 0) black = (0, 0, 0) global cb_color, surface global launcher_up, launcher_down, launcher_left, launcher_right, \ block, farmer, keymaker global clock cb_color = [red, black] surface = pygame.display.set_mode([sq * x for x in cb.size()]) # load icons here launcher_up = pygame.image.load(icons['launcher-up']) launcher_down = pygame.image.load(icons['launcher-down']) launcher_left = pygame.image.load(icons['launcher-left']) launcher_right = pygame.image.load(icons['launcher-right']) block = pygame.image.load(icons['block']) farmer = pygame.image.load(icons['farmer']) keymaker = pygame.image.load(icons['keymaker']) clock = pygame.time.Clock()
def it_can_remove_a_piece(self): board = ChessBoard() field = board.get_field(4, 6) type(field.piece) |should| be(Pawn) white_pawn = board.get_piece(4, 6) field.piece |should| be(None) type(white_pawn) |should| be(Pawn)
def testSkipCells(self): board = ChessBoard() analyzeRow("r6r", 1, board) row = board.getRank(1) self.assertEqual(str(row[0]), "ra1") self.assertEqual(str(row[7]), "rh1")
def __init__(self): """Instantiate object.""" self.chessboard = ChessBoard() self.player_white = ChessPlayer('white') self.player_black = ChessPlayer('black') self.setup_board() self.current_player = self.player_white self.moves = 0 self.move_number = 1
def testCenterAllMovesBlockedDiff(self): board = ChessBoard() board.addPieceToBoard("Bishop", 4, 4, "White") board.addPieceToBoard("Pawn", 3, 3, "Black") board.addPieceToBoard("Pawn", 5, 5, "Black") board.addPieceToBoard("Pawn", 3, 5, "Black") board.addPieceToBoard("Pawn", 5, 3, "Black") moves = board.getSquare(4, 4).getMoveset(board.getRanks()) self.assertEqual(4, len(moves))
def initUI(self): self.button1 = QPushButton("音乐", self) self.button1.clicked.connect(self.button1click) self.clicknum = 1 self.button2 = QPushButton("战况", self) self.button2.clicked.connect(self.button2click) self.button2.move(80, 530) self.button1.move(0, 530) self.win = 0 self.fail = 0 self.step_num = 0 self.chessboard = ChessBoard() # 棋盘类 palette1 = QPalette() # 设置棋盘背景 palette1.setBrush(self.backgroundRole(), QtGui.QBrush(QtGui.QPixmap('img/chessboard.jpg'))) self.setPalette(palette1) # self.setStyleSheet("board-image:url(img/chessboard.jpg)") # 不知道这为什么不行 self.setCursor(Qt.PointingHandCursor) # 鼠标变成手指形状 self.sound_piece = QSound("sound/move.wav") # 加载落子音效 self.sound_win = QSound("sound/win.wav") # 加载胜利音效 self.sound_defeated = QSound("sound/defeated.wav") # 加载失败音效 self.resize(WIDTH, HEIGHT) # 固定大小 540*540 self.setMinimumSize(QtCore.QSize(WIDTH, HEIGHT)) self.setMaximumSize(QtCore.QSize(WIDTH, HEIGHT)) self.setWindowTitle("五子棋") # 窗口名称 self.setWindowIcon(QIcon('img/black.png')) # 窗口图标 # self.lb1 = QLabel(' ', self) # self.lb1.move(20, 10) self.black = QPixmap('img/black.png') self.white = QPixmap('img/white.png') self.piece_now = BLACK # 黑棋先行 self.my_turn = True # 玩家先行 self.step = 0 # 步数 self.x, self.y = 1000, 1000 self.mouse_point = LaBel(self) # 将鼠标图片改为棋子 self.mouse_point.setScaledContents(True) # self.mouse_point.setPixmap(self.black) # 加载黑棋 self.mouse_point.setGeometry(270, 270, PIECE, PIECE) self.pieces = [LaBel(self) for i in range(225)] # 新建棋子标签,准备在棋盘上绘制棋子 for piece in self.pieces: piece.setVisible(True) # 图片可视 piece.setScaledContents(True) # 图片大小根据标签大小可变 self.mouse_point.raise_() # 鼠标始终在最上层 self.ai_down = True # AI已下棋,主要是为了加锁,当值是False的时候说明AI正在思考,这时候玩家鼠标点击失效,要忽略掉 mousePressEvent self.setMouseTracking(True) self.show()
def its_fields_have_colors(self): board = ChessBoard() corner0 = board.get_field(0, 0) corner0.color |should| equal_to("white") corner1 = board.get_field(0, 7) corner1.color |should| equal_to("black") corner2 = board.get_field(7, 0) corner2.color |should| equal_to("black") corner3 = board.get_field(7, 7) corner3.color |should| equal_to("white")
def testSumFourPiecesBlackCanCastle(self): board = ChessBoard() board.addPieceToBoard("Pawn", 5, 2, "Black") board.addPieceToBoard("Pawn", 4, 2, "Black") board.addPieceToBoard("Pawn", 6, 2, "Black") board.addPieceToBoard("King", 4, 1, "Black") board.blackCanCastle() self.assertEqual(board.calculateAllMoves(1), 6)
def testOppositeNothing(self): board = ChessBoard() board.addPieceToBoard("Pawn", 5, 2, "Black") board.addPieceToBoard("Pawn", 4, 2, "Black") board.addPieceToBoard("Pawn", 6, 2, "Black") board.addPieceToBoard("King", 5, 1, "Black") board.blackCanCastle() self.assertEqual(board.calculateAllMoves(0), 0)
def testSumFourPiecesWhiteCanCastle(self): board = ChessBoard() board.addPieceToBoard("Pawn", 5, 2, "White") board.addPieceToBoard("Pawn", 4, 2, "White") board.addPieceToBoard("Pawn", 6, 2, "White") board.addPieceToBoard("King", 5, 1, "White") board.whiteCanCastle() self.assertEqual(board.calculateAllMoves(0), 9)
def test_get_path(self): self.b = ChessBoard() # check path for a white bishop (C1) -> (E3), blocked by own pawn self.assertFalse(self.b._check_path([7, 2], [-1, 1], [5, 4])) # move black pawn and later white pawn as well as check path for same knight self.b.move('d2', 'd4') self.assertTrue(self.b._check_path([7, 2], [-1, 1], [5, 4])) # check path for white pawn (C3) -> (C5), no obstacles self.assertTrue(self.b._check_path([6, 2], [-1, 0], [4, 2]))
def testAnalyzeEmptyRow(self): board = ChessBoard() analyzeRow("8", 1, board) row = board.getRank(1) self.assertEqual(row[0], 0) self.assertEqual(row[1], 0) self.assertEqual(row[2], 0) self.assertEqual(row[3], 0) self.assertEqual(row[4], 0) self.assertEqual(row[5], 0) self.assertEqual(row[6], 0) self.assertEqual(row[7], 0)
def it_can_put_a_piece(self): board = ChessBoard() origin_field = board.get_field(2, 6) target_field = board.get_field(2, 4) board.turn |should| equal_to("white") type(origin_field.piece) |should| be(Pawn) target_field.piece |should| be(None) white_pawn = board.get_piece(2, 6) board.put_piece(white_pawn, 2, 4) board.turn |should| equal_to("black") origin_field.piece |should| be(None) type(target_field.piece) |should| be(Pawn)
def it_has_pieces(self): board = ChessBoard() corner0 = board.get_field(0, 0) type(corner0.piece) |should| be(Rook) corner0.piece.color |should| equal_to("black") field = board.get_field(2, 1) print field.piece type(field.piece) |should| be(Pawn) field.piece.color |should| equal_to("black") field = board.get_field(2, 6) type(field.piece) |should| be(Pawn) field.piece.color |should| equal_to("white")
def testBlackFirstRow(self): board = ChessBoard() analyzeRow("rnbqkbnr", 1, board) row = board.getRank(1) self.assertEqual(str(row[0]), "ra1") self.assertEqual(str(row[1]), "nb1") self.assertEqual(str(row[2]), "bc1") self.assertEqual(str(row[3]), "qd1") self.assertEqual(str(row[4]), "ke1") self.assertEqual(str(row[5]), "bf1") self.assertEqual(str(row[6]), "ng1") self.assertEqual(str(row[7]), "rh1")
def test5(): # 初始化棋盘 chessboard = ChessBoard() chessboard.initBoard() # 初始化棋子类 chessman = ChessMan() chessman.Color = 'o' # 初始化引擎类 engine = Engine(chessboard) while 1: # 获取用户下棋位置 userInput = input("请输入用户下棋位置:") engine.userGo(chessman, userInput) # 放置用户下棋位置 chessboard.setChessMan(chessman) # 打印棋盘 RET = engine.isWonMan(chessman) chessboard.printBoard() if RET: print('win') break
def initUI(self): self.chessboard = ChessBoard() # 棋盘类 self.chess_manual = [] self.Going = False palette1 = QPalette() # 设置棋盘背景 pix = QtGui.QPixmap('board_' + str(N_LINE) + '.jpg') pix = pix.scaled(WIDTH, HEIGHT) palette1.setBrush(self.backgroundRole(), QtGui.QBrush(pix)) self.setPalette(palette1) # self.setStyleSheet("board-image:url(img/chessboard.jpg)")# 不知道这为什么不行 self.setCursor(Qt.PointingHandCursor) # 鼠标变成手指形状 #self.sound_piece = QSound("sound/luozi.wav")# 加载落子音效 # self.sound_win = QSound("sound/win.wav")# 加载胜利音效 # self.sound_defeated = QSound("sound/defeated.wav")# 加载失败音效 self.resize(WIDTH, HEIGHT) # 固定大小 540*540 self.setMinimumSize(QtCore.QSize(WIDTH, HEIGHT)) self.setMaximumSize(QtCore.QSize(WIDTH, HEIGHT)) self.setWindowTitle("GoBang") # 窗口名称 # self.setWindowIcon(QIcon('img/black.png'))# 窗口图标 # self.lb1 = QLabel(' ', self) # self.lb1.move(20, 10) self.black = QPixmap('black.png') self.white = QPixmap('white.png') self.is_black_do = True # 黑棋回合先行 self.step = 0 # 步数 self.x, self.y = 1000, 1000 self.mouse_point = LaBel(self) # 将鼠标图片改为棋子 self.mouse_point.setScaledContents(True) self.mouse_point.setPixmap(self.black) #加载黑棋 self.mouse_point.setGeometry(270, 270, PIECE, PIECE) self.pieces = [LaBel(self) for i in range(225)] # 新建棋子标签,准备在棋盘上绘制棋子 for piece in self.pieces: piece.setVisible(True) # 图片可视 piece.setScaledContents(True) #图片大小根据标签大小可变 self.mouse_point.raise_() # 鼠标始终在最上层 #self.ai_down = True# AI已下棋,主要是为了加锁,当值是False的时候说明AI正在思考,这时候玩家鼠标点击失效,要忽略掉 mousePressEvent self.setMouseTracking(True) self.show() self.display_it()
def make_move(): if request.method == 'POST': try: move_data = request.get_json() board = ChessBoard(move_data) new_move = board.makeMove() for key in new_move: src = key dest = new_move[key] source = board.convertCoord(src[0]) + str(src[1]) destination = board.convertCoord(dest[0]) + str(dest[1]) return jsonify(sourceID=source, destID=destination) except Exception as err: print((err))
def initUI(self): self.chessboard = ChessBoard() # 棋盘类 palette1 = QPalette() # 设置棋盘背景 palette1.setBrush(self.backgroundRole(), QtGui.QBrush(QtGui.QPixmap('img/1.jpg'))) self.setPalette(palette1) # self.setStyleSheet("board-image:url(img/chessboard.jpg)") # 不知道这为什么不行 self.setCursor(Qt.PointingHandCursor) # 鼠标变成手指形状 self.resize(WIDTH, HEIGHT) # 固定大小 540*540 self.setMinimumSize(QtCore.QSize(WIDTH, HEIGHT)) self.setMaximumSize(QtCore.QSize(WIDTH, HEIGHT)) self.setWindowTitle("黑白棋") # 窗口名称 self.setWindowIcon(QIcon('img/black.png')) # 窗口图标 # self.lb1 = QLabel(' ', self) # self.lb1.move(20, 10) self.black = QPixmap('img/black.png') self.white = QPixmap('img/white.png') self.piece_now = BLACK # 黑棋先行 self.my_turn = True # 玩家先行 self.step = 0 # 步数 self.x, self.y = 1000, 1000 self.mouse_point = LaBel(self) # 将鼠标图片改为棋子 self.mouse_point.setScaledContents(True) self.mouse_point.setPixmap(self.black) # 加载黑棋 self.mouse_point.setGeometry(270, 270, PIECE, PIECE) self.pieces = [LaBel(self) for i in range(4096)] # 新建棋子标签,准备在棋盘上绘制棋子 for piece in self.pieces: piece.setVisible(True) # 图片可视 piece.setScaledContents(True) # 图片大小根据标签大小可变 self.mouse_point.raise_() # 鼠标始终在最上层 self.ai_down = True # AI已下棋,主要是为了加锁,当值是False的时候说明AI正在思考,这时候玩家鼠标点击失效,要忽略掉 mousePressEvent self.draw(3, 3) self.draw(3, 4) self.draw(4, 4) self.draw(4, 3) self.setMouseTracking(True) self.show()
def __init__(self, root): self.root = root #Knapparnas-container self.menu = Frame(self.root) self.menu.pack() #Ny-omgång knappen self.newGameButton = Button(self.menu, height=1, width=20, text="Ny spelomgång") self.newGameButton.bind("<Button-1>", self.newGame) self.newGameButton.pack(side=LEFT) #highscore-knappen self.highscoreButton = Button(self.menu, height=1, width=20, text="Toggla Highscores") self.highscoreButton.bind("<Button-1>", self.toggleHighscore) self.highscoreButton.pack(side=LEFT) #Highscore-vyn self.highscoreView = Highscore(self.root, "highscores.txt") self.highscoreBool = False #Spel-vyn self.gameView = ChessBoard(self, self.root) self.gameView.container.pack()
def initBoard(fileLocation): """This method reads a .fen file and returns a board representing its state Args: Complete or partial filepath to .fen file Returns: Board representing contents of file, or None if an error during analysis """ board = ChessBoard() try: infile = open(fileLocation, "r") except FileNotFoundError: print("File", fileLocation, "could not be found, please check your input") return data = infile.read().split('/') if (len(data) != 8): print("Input file", fileLocation, "did not contain enough ranks, please check your input") return counter = 8 for row in data: try: analyzeRow(row, counter, board) except ValueError: print("A bad value was in row", counter) return counter -= 1 infile.close() return board
def __init__(self): self.board = ChessBoard() self.display = Display(self) self.player1 = PolicyPlayer(1, 2, self) self.player2 = PolicyPlayer(2, 1, self) super(PolicyPKPolicyGame, self).__init__(self.board, self.display, self.player1, self.player2)
def __init__(self): self.board = ChessBoard() self.display = TkinterDisplay(self) self.player1 = TkinterHumanPlayer(1, 2, self) self.player2 = PolicyPlayer(2, 1, self) super(HumanPKPolicyGame, self).__init__(self.board, self.display, self.player1, self.player2)
def newGame(self, event): if self.highscoreBool: self.highscoreView.container.pack_forget() self.highscoreBool = not self.highscoreBool self.gameView.container.pack_forget() self.gameView.container.destroy() self.gameView = ChessBoard(self, self.root) #Ny instans av ChessBoard. self.gameView.container.pack()
def custom_game(): # 策略玩家自我对弈的动态效果 board = ChessBoard() game = Game(board, None, None, None) game.display = TkinterDisplay(game) game.player1 = PolicyPlayer(1, 2, game) game.player2 = PolicyPlayer(2, 1, game) game.player = game.player1 game.mainloop()
def make_human_move(self, move): try: if move == None: raise Exception if not self.move_validator.is_move_valid( self.chessboard.chess_board, move[0], move[1], ChessBoard.WHITE_PAWN): raise Exception ChessBoard.move_piece(self.chessboard.chess_board, move[0], move[1]) self.game_state = GameState.PLAYING except: self.game_state = GameState.WRONG_MOVE
class TestCaseChessBoardMove(unittest.TestCase): def setUp(self) -> None: self.b = ChessBoard() def test_MoveNothingToMove(self): with self.assertRaises(CBNothingToMoveE): self.b.move('a3', 'a4') self.assertEqual(self.b.moves, 0) def test_MoveSameColorNoMove(self): with self.assertRaises(CBSameColorE): self.b.move('a2', 'b2') def test_MoveEmptyDestination(self): self.assertTrue(self.b.move('a2', 'a4')) def tearDown(self) -> None: del self.b
def new(self): self.turn = ESide.White self.currentPiece = None self.gameReview = [None, None, None ] #keeps track of the moves played during the game self.bgDraw() self.grid = self.getAndDrawGrid( ) #The key to transit between coords and the screen self.chessboard = ChessBoard() self.run()
def initUI(self): self.chessboard = ChessBoard() # 棋盘类 palette1 = QPalette() # 设置棋盘背景 palette1.setBrush(self.backgroundRole(), QtGui.QBrush(QtGui.QPixmap('img/chessboard.jpg'))) self.setPalette(palette1) self.setCursor(Qt.PointingHandCursor) # 鼠标变成手指形状 self.sound_piece = QSound("sound/move.wav") # 加载落子音效 self.sound_win = QSound("sound/win.wav") # 加载胜利音效 self.sound_defeated = QSound("sound/defeated.wav") # 加载失败音效 self.resize(WIDTH, HEIGHT) # 固定大小 540*540 self.setMinimumSize(QtCore.QSize(WIDTH, HEIGHT)) self.setMaximumSize(QtCore.QSize(WIDTH, HEIGHT)) self.setWindowTitle("五子棋") # 窗口名称 self.setWindowIcon(QIcon('img/black.png')) # 窗口图标 self.black = QPixmap('img/black.png') self.white = QPixmap('img/white.png') self.piece_now = BLACK # 黑棋先行 self.my_turn = True # 玩家先行 self.step = 0 # 步数 self.x, self.y = 1000, 1000 self.mouse_point = LaBel(self) # 将鼠标图片改为棋子 self.mouse_point.setScaledContents(True) self.mouse_point.setPixmap(self.black) # 加载黑棋 self.mouse_point.setGeometry(270, 270, PIECE, PIECE) self.pieces = [LaBel(self) for i in range(225)] # 新建棋子标签,准备在棋盘上绘制棋子 for piece in self.pieces: piece.setVisible(True) # 图片可视 piece.setScaledContents(True) # 图片大小根据标签大小可变 self.mouse_point.raise_() # 鼠标始终在棋盘背景的上方 self.ai_down = True # 当ai在执行任务的时候玩家不能使用鼠标 self.setMouseTracking(True) self.show()
def test_coordinate_to_index(self): self.assertEqual([7, 0], ChessBoard._coord_to_index('a1')) self.assertEqual([6, 0], ChessBoard._coord_to_index('a2')) self.assertEqual([7, 0], ChessBoard._coord_to_index('a1')) self.assertEqual([7, 0], ChessBoard._coord_to_index('A1')) self.assertEqual([0, 7], ChessBoard._coord_to_index('h8')) with self.assertRaises(NameError): ChessBoard._coord_to_index('g9')
def _simulate_play(self, state): board = ChessBoard(self.game.board.width, self.game.board.height, self.game.board.n_in_row, state) game = Game(board, None, None, None) display = Display(game) player1 = PolicyPlayer(self.other_index, self.index, game) player2 = PolicyPlayer(self.index, self.other_index, game) game.display = display game.player = game.player1 = player1 game.player2 = player2 game.mainloop() return display.win_player is not None and display.win_player.index == self.index
def testCenterAllMoves(self): board = ChessBoard() board.addPieceToBoard("Queen", 4, 4, "White") moves = board.getSquare(4, 4).getMoveset(board.getRanks()) self.assertEqual(27, len(moves)) self.assertIn((4, 3), moves) #1 self.assertIn((4, 2), moves) #2 self.assertIn((4, 1), moves) #3 self.assertIn((4, 5), moves) #4 self.assertIn((4, 6), moves) #5 self.assertIn((4, 7), moves) #6 self.assertIn((4, 8), moves) #7 self.assertIn((5, 4), moves) #8 self.assertIn((6, 4), moves) #9 self.assertIn((7, 4), moves) #10 self.assertIn((8, 4), moves) #11 self.assertIn((3, 4), moves) #12 self.assertIn((2, 4), moves) #13 self.assertIn((1, 4), moves) #14 self.assertIn((3, 3), moves) #15 self.assertIn((2, 2), moves) #16 self.assertIn((1, 1), moves) #17 self.assertIn((5, 5), moves) #18 self.assertIn((6, 6), moves) #19 self.assertIn((7, 7), moves) #20 self.assertIn((8, 8), moves) #21 self.assertIn((5, 3), moves) #22 self.assertIn((6, 2), moves) #23 self.assertIn((7, 1), moves) #24 self.assertIn((3, 5), moves) #25 self.assertIn((2, 6), moves) #26 self.assertIn((1, 7), moves) #27
def testPawnUnblockedFirstSquareBlack(self): board = ChessBoard() board.addPieceToBoard("Pawn", 4, 7, "Black") moves = board.getSquare(4, 7).getMoveset(board.getRanks()) self.assertEqual(2, len(moves)) self.assertIn((4, 6), moves) self.assertIn((4, 5), moves)
def testPawnBlockedDiffColor(self): board = ChessBoard() board.addPieceToBoard("Pawn", 4, 4, "White") board.addPieceToBoard("Pawn", 4, 5, "Black") moves = board.getSquare(4, 4).getMoveset(board.getRanks()) self.assertEqual(0, len(moves)) self.assertNotIn((4, 5), moves)
def it_only_remove_pieces_of_turn_player(self): board = ChessBoard() field1 = board.get_field(4, 1) type(field1.piece) |should| be(Pawn) board.get_piece(4, 1) |should| be(None) type(field1.piece) |should| be(Pawn) field2 = board.get_field(4, 6) type(field2.piece) |should| be(Pawn) white_pawn = board.get_piece(4, 6) field2.piece |should| be(None) type(white_pawn) |should| be(Pawn)
def it_should_return_all_white_pieces(self): board = ChessBoard() len(board.get_pieces_from_equal_turn()) |should| equal_to(16) for piece in board.get_pieces_from_equal_turn(): piece.color |should| equal_to('white')
class ChessGame(object): def __init__(self): self.chessboard = ChessBoard() def start(self, computerstarts = True): if computerstarts: print 'Computer is white. Take this move, bitch!' computer_color = 'white' else: print 'Computer is black. Please, make your move, punk!' computer_color = 'black' if computer_color == 'white': self.chessboard.draw() print 'Initial zobrist: ' + str(self.chessboard.zobrist_number) #print 'Resulting score: ' + str(self.chessboard.evaluate(WHITE)) #print 'Hash key: ' + str(self.chessboard._hash_code) depth_white = 4 depth_black = 5 n = 1 playing_color = WHITE while 1: if playing_color == WHITE: depth = depth_white else: depth = depth_black t0 = time.time() # abscore, principal_variation = negamax.alphabeta(self.chessboard, depth, -INF, INF, playing_color) t1 = time.time() # print 'alphabeta: ' + str(t1 - t0) + ' ' + str(abscore) # print [each.zobrist_number for each in principal_variation] # abmemscore, principal_variation = negamax.alphabetamemory(self.chessboard, depth, -INF, INF, playing_color) t2 = time.time() # print 'alphabetamem: ' + str(t2 - t1) + ' ' + str(abmemscore) # print [each.zobrist_number for each in principal_variation] # idscore, principal_variation = negamax.iterativedeepeningalphabeta(self.chessboard, depth, playing_color) t3 = time.time() # print 'iterdeep: ' + str(t3 - t2) + ' ' + str(idscore) # print [each.zobrist_number for each in principal_variation] idmemscore, principal_variation = negamax.iterativedeepeningalphabetamemory(self.chessboard, depth, playing_color) t4 = time.time() # print 'iterdeepmem: ' + str(t4 - t3) + ' ' + str(idmemscore) # print [each.zobrist_number for each in principal_variation] # mtdfscore, principal_variation = negamax.mtdf(self.chessboard, depth, playing_color) t5 = time.time() # print 'mtdf: ' + str(t5 - t4) + ' ' + str(mtdfscore) # print [each.zobrist_number for each in principal_variation] # idmtdfscore, principal_variation = negamax.iterativedeepeningmtdf(self.chessboard, depth, playing_color) t6 = time.time() # print 'idmtdf: ' + str(t6 - t5) + ' ' + str(idmtdfscore) # print [each.zobrist_number for each in principal_variation] if len(principal_variation) == 1: if playing_color == WHITE: print 'BLACK WON' else: print 'WHITE WON' break print '' if playing_color == WHITE: print 'WHITE MOVED, n = ' + str(n) else: print 'BLACK MOVED, n = ' + str(n) n += 1 self.chessboard = principal_variation[1] self.chessboard.draw() print 'Resulting score: ' + str(self.chessboard.evaluate()) print 'New zobrist number: ' + str(self.chessboard.zobrist_number) flagline = 'En passant flags: ' for f in range(8): flagline += str(self.chessboard.en_passant_flag(f)) flagline += ' Castling flags (wq, wk, bq, bk): ' if self.chessboard.castling_queen_side_flag(WHITE): flagline += '1' else: flagline += '0' if self.chessboard.castling_king_side_flag(WHITE): flagline += '1' else: flagline += '0' if self.chessboard.castling_queen_side_flag(BLACK): flagline += '1' else: flagline += '0' if self.chessboard.castling_king_side_flag(BLACK): flagline += '1' else: flagline += '0' print flagline print '' if playing_color == WHITE: playing_color = BLACK else: playing_color = WHITE
def it_not_should_is_in_checkmate_in_initial_position(self): board = ChessBoard() board.check_is_in_checkmate() |should| equal_to(False)
def __init__(self): self.chessboard = ChessBoard()
def it_should_return_all_black_pieces(self): board = ChessBoard() len(board.get_pieces_from_other_turn()) |should| equal_to(16) for piece in board.get_pieces_from_other_turn(): piece.color |should| equal_to('black')
def it_knows_all_possibilities_from_white_pieces(self): board = ChessBoard() board.get_all_possibilities_from_equal_turn() |should| equal_to(set([(0,4),(1,4),(2,4),(3,4),(4,4),(5,4),(6,4),(7,4),(0,5),(1,5),(2,5),(3,5),(4,5),(5,5),(6,5),(7,5)])) board.get_all_possibilities_from_equal_turn() |should_not| include((0,2))
def it_knows_all_possibilities_from_black_pieces(self): board = ChessBoard() board.get_all_possibilities_from_other_turn() |should| equal_to(set([(0,2),(1,2),(2,2),(3,2),(4,2),(5,2),(6,2),(7,2),(0,3),(1,3),(2,3),(3,3),(4,3),(5,3),(6,3),(7,3)])) board.get_all_possibilities_from_other_turn() |should_not| include((0,4))
def it_should_is_in_checkmate(self): board = ChessBoard() board.board[3][5].piece = Horse('black', 3, 5) board.check_is_in_checkmate() |should| equal_to(True)