本文整理汇总了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()