本文整理汇总了Python中Board.test_victory方法的典型用法代码示例。如果您正苦于以下问题:Python Board.test_victory方法的具体用法?Python Board.test_victory怎么用?Python Board.test_victory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Board
的用法示例。
在下文中一共展示了Board.test_victory方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Main_game_display
# 需要导入模块: import Board [as 别名]
# 或者: from Board import test_victory [as 别名]
#.........这里部分代码省略.........
def define_pieces(self):
self.v = tkinter.IntVar()
self.v.set(16)
self.pieces = []
self.image_pieces = []
i = 0
while i < 16:
self.pieces.append(tkinter.Radiobutton(
self, variable=self.v,
indicatoron=0,
value=i))
self.pieces[i].grid(column=6+(i//8), row=(i % 8)+2)
imageToLoad = 'Piece' + str(i) + '.gif'
self.image_pieces.append(tkinter.PhotoImage(file=imageToLoad))
self.pieces[i].config(
image=self.image_pieces[i],
width="60", height="60")
self.pieces[i].grid(column=6+(i//8), row=(i % 8)+2)
i += 1
def put_piece(self, i):
if self.selection < 16:
self.chosenPiece = self.board.list_pieces[self.selection]
self.image_square[i] = self.image_pieces[self.selection]
self.button_square[i].configure(image=self.image_square[i],
state='disabled')
self.text_instruction.set("{}, now, please choose \
the next piece to play.".format(self.player_main))
self.button_selec.config(state='normal')
self.image_selec = self.image_empty
self.canvas_selec.create_image(30, 30, image=self.image_selec)
self.selection = 16
# update of the board
self.board.put_piece(i//4+1, i % 4+1, self.chosenPiece)
# victory test
self.victory()
def select(self):
self.selection = self.v.get()
if self.selection < 16:
# at this point, the main player changes
self.change_player()
self.text_instruction.set("{}, Please put the selected \
piece on the board.".format(self.player_main))
self.image_selec = self.image_pieces[self.selection]
self.canvas_selec.create_image(30, 30, image=self.image_selec)
self.button_selec.config(state='disabled')
self.pieces[self.selection].destroy()
self.v.set(16)
# AI MODE
# in case of AI mode chosen
if (self.mode == "ai" and self.player_main == "Computer"):
self.aiTurn()
def change_player(self):
"""
Change the main player
"""
if self.player_main is self.player1:
self.player_main = self.player2
else:
self.player_main = self.player1
def victory(self):
if self.board.test_victory():
self.text_instruction.set("CONGRATULATION {}, you \
won.".format(self.player_main))
self.button_selec.config(state='disabled')
for elt in self.board.piecesRemaining:
self.pieces[elt.get_piece_id()].config(state='disabled')
for (r, c) in self.board.free_square():
self.button_square[c-1+(r-1)*4].configure(state="disabled")
def aiTurn(self):
self.chosenPiece = self.board.list_pieces[self.selection]
# The AI evaluates possibilities for its next move
self.moveChoice = QTree(self.board, "square",
chosenPiece=self.chosenPiece)
self.moveChoice.add_level()
self.moveChoice.add_level()
self.moveChoice.add_level()
self.moveChoice.update_score()
self.bestChoice = self.moveChoice.leaf[0]
for leaf in self.moveChoice.leaf:
if leaf.score > self.bestChoice.score:
self.bestChoice = leaf
# bestChoice is the best move to play. The AI plays
self.put_piece(self.bestChoice.chosenSquare)
if not self.board.test_victory():
# bestPiece is the best situation for a piece selection
# bestPiece is not a piece but a Qtree !
self.bestPiece = self.bestChoice.leaf[0]
for leaf in self.bestChoice.leaf:
if leaf.score > self.bestPiece.score:
self.bestPiece = leaf
self.v.set(self.bestPiece.chosenPiece.get_piece_id())
self.select()
def quit(self):
self.destroy()