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


Python Problem.get_setup方法代碼示例

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


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

示例1: BoardController

# 需要導入模塊: from Problem import Problem [as 別名]
# 或者: from Problem.Problem import get_setup [as 別名]
class BoardController(object):
    def __init__(self):
        self._v_message = None
        self._model = None
        self._to_board = lambda x, y: (x, y)
        self._from_board = lambda x, y: (x, y)
        self._fix_color = lambda c: c
        self._board_widget = None
        self._directory = None
        self._collection = None
        self._problem = None

    def register_message_var(self, v):
        self._v_message = v

    def register_board_widget(self, widget):
        self._board_widget = widget

    def get_stones(self):
        stones = self._model.get_stones()
        def stone_to_board((nx, ny, s)):
            nxb, nyb = self._to_board(nx, ny)
            c = self._fix_color(s)
            return (nxb, nyb, c)
        return map(stone_to_board, stones)

    def get_ko(self):
        ko = self._model.get_ko()
        if ko:
            return self._to_board(*ko)
        else:
            return None

    def allowed(self, nxb, nyb):
        nx, ny = self._from_board(nxb, nyb)
        return self._model.allowed(nx, ny)

    def add(self, nxb, nyb):
        assert(self._v_message)
        nx, ny = self._from_board(nxb, nyb)
        self._model.do_move(nx, ny)
        self._board_widget.update_board()
        if not self._problem.is_over():
            reply = self._problem.get_reply(nx, ny)
            # TODO
            if self._problem.is_over():
                if self._problem.is_wrong():
                    self._v_message.set("Wrong")
                else:
                    self._v_message.set("Right")
            else:
                self._v_message.set('')
            if reply is None:
                return
            self._model.do_move(*reply)
            self._board_widget.update_board()

    def to_move(self):
        return self._fix_color(self._model.to_move())

    def last_move(self):
        lm = self._model.last_move()
        if lm:
            lmx, lmy = lm
            return self._to_board(lmx, lmy)
        else:
            return None

    def open_collection(self, directory):
        # FIXME
        self._directory = directory
        self._collection = [f for f in listdir(directory)
                if isfile(join(directory, f))]

    def next_problem(self):
        assert(self._v_message)
        # FIXME
        l = len(self._collection)
        r = randint(0, l - 1)
        f = open(join(self._directory, self._collection[r]))
        self._problem = Problem(f.read())
        transform = Transform()
        self._to_board = transform.to_board
        self._from_board = transform.from_board
        self._fix_color = transform.fix_color
        self._model = BoardModel()
        if self.to_move() == Color.B:
            self._v_message.set('Black to move')
        else:
            self._v_message.set('White to move')
        self._model.setup_position(self._problem.get_setup())
        self._board_widget.update_board()
開發者ID:avysk,項目名稱:Peanuts,代碼行數:94,代碼來源:BoardController.py


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