當前位置: 首頁>>代碼示例>>Python>>正文


Python BoardState.make_initial_setup方法代碼示例

本文整理匯總了Python中game.game_module.BoardState.make_initial_setup方法的典型用法代碼示例。如果您正苦於以下問題:Python BoardState.make_initial_setup方法的具體用法?Python BoardState.make_initial_setup怎麽用?Python BoardState.make_initial_setup使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在game.game_module.BoardState的用法示例。


在下文中一共展示了BoardState.make_initial_setup方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_piece_path

# 需要導入模塊: from game.game_module import BoardState [as 別名]
# 或者: from game.game_module.BoardState import make_initial_setup [as 別名]
 def test_piece_path(self):
     board = BoardState()
     board.make_initial_setup()
     path1 = board[('a', 2)].path
     board = board.next(MoveParser().parse("a4", Color.WHITE))
     path2 = board[('a', 4)].path
     self.assertEqual([Square('a',2)], path1)
     self.assertEqual([Square('a',2), Square('a', 4)], path2)
開發者ID:ElenaHudyakova,項目名稱:ChessMaster,代碼行數:10,代碼來源:tests.py

示例2: test_serialize_initial_setup

# 需要導入模塊: from game.game_module import BoardState [as 別名]
# 或者: from game.game_module.BoardState import make_initial_setup [as 別名]
 def test_serialize_initial_setup(self):
     board = BoardState()
     board.make_initial_setup()
     blob = board.serialize()
     white_rows_blob = ((((((((((((((0*16+1)*16+2)*16+3)*16+4)*16+2)*16+1)*16+0)*16+5)*16+5)*16+5)*16+5)*16+5)*16+5)*16+5)*16+5
     black_rows_blob = (((((((((((((((5+8)*16+5+8)*16+5+8)*16+5+8)*16+5+8)*16+5+8)*16+5+8)*16+5+8)*16+0+8)*16+1+8)*16+2+8)*16+3+8)*16+4+8)*16+2+8)*16+1+8)*16+0+8
     two_empty_rows_blob = ((((((((((((((14*16+14)*16+14)*16+14)*16+14)*16+14)*16+14)*16+14)*16+14)*16+14)*16+14)*16+14)*16+14)*16+14)*16+14)*16+14
     self.assertEqual([white_rows_blob, two_empty_rows_blob, two_empty_rows_blob, black_rows_blob], blob)
開發者ID:ElenaHudyakova,項目名稱:ChessMaster,代碼行數:10,代碼來源:tests.py

示例3: _show_first_move

# 需要導入模塊: from game.game_module import BoardState [as 別名]
# 或者: from game.game_module.BoardState import make_initial_setup [as 別名]
 def _show_first_move(self):
     if not self.current_game is None:
         try:
             self.current_move_num = 0
             self.move_list.setCurrentRow(self.current_move_num)
             self.board.redraw(self.current_game.board_states[self.current_move_num])
         except Exception as err:
             print err
     else:
         board_state = BoardState()
         board_state.make_initial_setup()
         self.board.redraw(board_state)
開發者ID:ElenaHudyakova,項目名稱:ChessMaster,代碼行數:14,代碼來源:main.py

示例4: BoardScene

# 需要導入模塊: from game.game_module import BoardState [as 別名]
# 或者: from game.game_module.BoardState import make_initial_setup [as 別名]
class BoardScene(QtGui.QGraphicsScene):

    def __init__(self, board_state = None):
        if board_state is None:
            self.board_state = BoardState()
            self.board_state.make_initial_setup()
        else:
            self.board_state = board_state
        super(BoardScene, self).__init__()
        self.piece_images = []
        self.painted_squares = []
        self.path = []
        self.acceptDrag = False
        self.drag_num = 0
        self.initUI()

    def dragEnterEvent(self, event):
        x = event.scenePos().x()
        y = event.scenePos().y()
        self.dragging_piece = self.itemAt(event.scenePos())
        file = int(math.floor(x/40))
        rank = int(9 - math.floor(y/40))
        self.drag_from = Square(file, rank)
#        event.acceptProposedAction()


    def dragMoveEvent(self, event):
        event.acceptProposedAction()


    def dropEvent(self, event):
        if self.dragging_piece.__class__.__name__ != 'PieceItem':
            return
        x = event.scenePos().x()
        y = event.scenePos().y()
        file = int(math.floor(x/40))
        rank = int(9 - math.floor(y/40))
        try:
            try:
                self.drag_to = Square(file, rank)
            except InvalidSquareCoordException:
                self.removeItem(self.dragging_piece)
                self.board_state.pieces.remove(self.board_state[self.drag_from])
                return
            if self.board_state[self.drag_to] is None:
                if self.drag_num == 0:
                    self.board_state = copy.deepcopy(self.board_state)
                self.drag_num += 1
                self.board_state[self.drag_from].square = self.drag_to
                self.dragging_piece.setOffset(40*file, 400 - 40*rank - 40)
        except Exception as err:
            print err


    def _get_image_filename(self, piece):
        if piece is None:
            return
        filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..%simg' % os.sep)
        filename += os.sep
        if piece.type == PieceType.BISHOP:
            filename += 'bishop'
        if piece.type == PieceType.KING:
            filename += 'king'
        if piece.type == PieceType.KNIGHT:
            filename += 'knight'
        if piece.type == PieceType.PAWN:
            filename += 'pawn'
        if piece.type == PieceType.QUEEN:
            filename += 'queen'
        if piece.type == PieceType.ROOK:
            filename += 'rook'
        filename+= '_'
        if piece.color == Color.WHITE:
            filename += 'white'
        else:
            filename += 'black'
        filename += '.png'
        return filename


    def initUI(self):
        self.setSceneRect(0,0, 400, 400)
        font=QtGui.QFont()
        font.setPointSize(15)

        black_brush = QtGui.QBrush(QtGui.QColor(50, 125, 215), QtCore.Qt.SolidPattern)
        white_brush = QtGui.QBrush(QtGui.QColor(255, 240, 225), QtCore.Qt.SolidPattern)

        squares = list()
        for i in range(1,9):
            row = list()
            squares.append(row)

        for i in range(1,9):
            file=QtGui.QGraphicsTextItem(Square.digit_to_file(i))
            file.setPos(40*i + 13 , 370)
            file.setFont(font)
            self.addItem(file)

            file=QtGui.QGraphicsTextItem(Square.digit_to_file(i))
#.........這裏部分代碼省略.........
開發者ID:ElenaHudyakova,項目名稱:ChessMaster,代碼行數:103,代碼來源:main.py


注:本文中的game.game_module.BoardState.make_initial_setup方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。