本文整理汇总了Python中bot.Bot.act方法的典型用法代码示例。如果您正苦于以下问题:Python Bot.act方法的具体用法?Python Bot.act怎么用?Python Bot.act使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bot.Bot
的用法示例。
在下文中一共展示了Bot.act方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_test
# 需要导入模块: from bot import Bot [as 别名]
# 或者: from bot.Bot import act [as 别名]
def run_test():
board = Board()
bot1 = Bot(1, board)
bot2 = Bot(2, board)
while not board.get_winner():
print board
if not board.can_be_played():
break
bot1.act()
print board
if not board.can_be_played():
break
bot2.act()
print board
bot1.update_strategy()
bot2.update_strategy()
print "bot %d wins" % board.get_winner()
示例2: App
# 需要导入模块: from bot import Bot [as 别名]
# 或者: from bot.Bot import act [as 别名]
class App(gtk.Window):
def __init__(self):
super(App, self).__init__()
self.set_title('Tic-Tac-Toe')
self.connect('destroy', gtk.main_quit)
self.set_position(gtk.WIN_POS_CENTER)
self.set_default_size(250,250)
self.show()
self.init_widgets()
self.game_count = 0
self.start_new_game()
def init_widgets(self):
vbox = gtk.VBox()
self.add(vbox)
self.button_position = {}
self.buttons = {}
for i in xrange(3):
hbox = gtk.HBox()
vbox.add(hbox)
for j in xrange(3):
button = gtk.Button()
self.button_position[button] = (i,j)
hbox.add(button)
button.connect('clicked', self.game_button_clicked)
button.show()
self.buttons[i, j] = button
hbox.show()
hbox = gtk.HBox()
restart_button = gtk.Button('restart')
restart_button.connect('clicked', self.start_new_game)
restart_button.show()
hbox.add(restart_button)
self.score_label= gtk.Label('0 - 0')
self.score_label.show()
hbox.add(self.score_label)
vbox.add(hbox)
hbox.show()
vbox.show()
def draw_board_state(self):
for i in xrange(3):
for j in xrange(3):
button = self.buttons[i,j]
if self.board.board[i][j] == 0:
label = ' '
elif self.board.board[i][j] == 1:
label = 'X'
else:
label = '0'
button.set_label(label)
def start_new_game(self, widget=None):
for button in self.button_position:
button.set_label(' ')
self.board = Board()
if self.game_count % 2 == 0:
self.bot = Bot(1, self.board)
self.bot.act()
self.draw_board_state()
self.player_color = 2
else:
self.bot = Bot(2, self.board)
self.player_color = 1
self.game_count += 1
def game_button_clicked(self, button):
position = self.button_position[button]
if position not in self.board.get_possible_actions():
return
self.board.move(self.player_color, self.button_position[button])
self.draw_board_state()
if not self.board.can_be_played():
return
self.bot.act()
self.draw_board_state()
if not self.board.get_winner() != 0:
return