本文整理汇总了Python中engine.Engine.someone_winning方法的典型用法代码示例。如果您正苦于以下问题:Python Engine.someone_winning方法的具体用法?Python Engine.someone_winning怎么用?Python Engine.someone_winning使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类engine.Engine
的用法示例。
在下文中一共展示了Engine.someone_winning方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from engine import Engine [as 别名]
# 或者: from engine.Engine import someone_winning [as 别名]
#.........这里部分代码省略.........
self.board = dict()
back = Frame(self.window)
back.pack(fill=BOTH, expand=1)
for row in range(8):
frame = Frame(back)
frame.pack(fill=BOTH, expand=1)
for column in range(8):
button = Button(frame,
state=DISABLED,
command=lambda position=(row, column): self.play(position))
button["bg"] = "gray"
button.pack(side=LEFT, fill=BOTH, expand=1)
self.board.update({(row, column): button})
def create_options(self):
pass_turn = Button(self.window, text="Pass", command=self.pass_turn)
pass_turn.pack(side=RIGHT)
self.status = Label(self.window)
self.update_status("Welcome to MonOthello!")
self.status.pack(side=LEFT)
def create_game(self):
message="Are you sure you want to restart?"
if self.game and \
not tkMessageBox.askyesno(title="New", message=message):
return
self.game = Engine()
self.update_board()
message = "Let's play! Now it's the %s's turn." % (self.game.turn.name,)
self.update_status(message)
def toggle_show_valid_positions(self):
self.show_valid_positions = not self.show_valid_positions
if self.game:
self.update_board()
def pass_turn(self):
if not self.game:
return
self.game.change_turn()
self.update_board()
message = "%s's turn." % (self.game.turn.name,)
self.update_status(message)
def show_credits(self):
message = "MonOthello\nv.: 1.0"
tkMessageBox.showinfo(title="About", message=message)
def bye(self):
if tkMessageBox.askyesno(title="Quit", message="Really quit?"):
quit()
def play(self, position):
"""Move a piece to the given position."""
if not self.game:
return
if not self.game.move(position, True):
message = "Wrong move. %s's turn." % (self.game.turn.name,)
self.update_status(message)
else:
self.update_board()
if self.game.check_end():
message = "End of game. "
if self.game.someone_winning():
message += self.game.who_is_winning() + " won!"
else:
message += "Tie."
tkMessageBox.showinfo(title="End of game", message=message)
self.game = False
else:
message = "%s's turn." % (self.game.turn.name,)
self.update_status(message)
def update_board(self):
for row in range(8):
for column in range(8):
position = self.board[(row, column)]
current_cell = self.game.board[(row, column)]
position["bg"] = current_cell.color
position["state"] = DISABLED
if isinstance(current_cell, EmptyPiece):
position["state"] = NORMAL
if self.show_valid_positions:
valid_positions = self.game.find_valid_positions()
for position in valid_positions:
self.board[position]["bg"] = "green"
self.update_score()
def update_score(self):
self.score["text"] = "Black: %s | White: %s" % \
(self.game.black_score,
self.game.white_score)
def update_status(self, message):
self.status["text"] = message