本文整理汇总了Python中ai.AI.valid_move方法的典型用法代码示例。如果您正苦于以下问题:Python AI.valid_move方法的具体用法?Python AI.valid_move怎么用?Python AI.valid_move使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ai.AI
的用法示例。
在下文中一共展示了AI.valid_move方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from ai import AI [as 别名]
# 或者: from ai.AI import valid_move [as 别名]
class CLI:
def __init__(self):
self._game = AI()
def play(self):
outcome = Game.IN_PROGRESS
while outcome == Game.IN_PROGRESS:
self._draw_board()
move = None
while move is None:
move = self._get_move()
outcome = self._game.play(move)
self._clear()
self._announce_outcome(outcome)
def _announce_outcome(self, outcome):
if outcome == Game.X_WINS:
print('Congratulations! You won!')
if outcome == Game.O_WINS:
print('Sorry, you loose. Better luck next time')
else:
print('It\'a a tie')
def _get_move(self):
try:
position = int(input('Enter your move>'))
if self._game.valid_move(position):
return position
print("Wrong input!")
except ValueError:
print("Wrong input!")
return None
def _clear(self):
os.system('clear')
def _draw_board(self):
state = self._game.current_state()
symbols = {str(place): symbol for place, symbol in enumerate(state)}
print(self._fill_board(symbols))
def _fill_board(self, symbols):
new_board = []
for character in BOARD:
if character in symbols and symbols[character] != Game.EMPTY:
new_board.append(symbols[character])
else:
new_board.append(character)
return "".join(new_board)