本文整理汇总了Python中bot.Bot.update_state方法的典型用法代码示例。如果您正苦于以下问题:Python Bot.update_state方法的具体用法?Python Bot.update_state怎么用?Python Bot.update_state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bot.Bot
的用法示例。
在下文中一共展示了Bot.update_state方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_game
# 需要导入模块: from bot import Bot [as 别名]
# 或者: from bot.Bot import update_state [as 别名]
def init_game():
cards = [[pygame.image.load(path.join('cards', '{0:02d}'.format(value) + suit + ".gif"))
for value in range(1, 14)]
for suit in ['d', 'c', 'h', 's']]
backside = pygame.image.load(path.join('cards', 'back192.gif'))
bottom = pygame.image.load(path.join('cards', 'bottom01-n.gif'))
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill((0, 130, 0))
solitaire = Solitaire(background, cards, backside, bottom)
solitaire.draw()
bot = Bot()
screen.blit(background, (0, 0))
pygame.display.update()
while 1:
# event = pygame.event.wait()
# if event.type == pygame.KEYDOWN:
# if event.key == pygame.K_LEFT:
# solitaire.move_left()
# elif event.key == pygame.K_RIGHT:
# solitaire.move_right()
# elif event.key == pygame.K_UP:
# solitaire.move_up()
# elif event.key == pygame.K_DOWN:
# solitaire.move_down()
# elif event.key == pygame.K_SPACE:
# solitaire.select()
# background.fill((0, 130, 0))
# solitaire.draw()
# screen.blit(background, (0, 0))
# pygame.display.update()
event = pygame.event.get()
bot.update_state(solitaire.deck.rows, solitaire.cursor)
moves = bot.make_move()
for move in moves:
background.fill((0, 130, 0))
if move == 'r':
solitaire.move_right()
elif move == 'l':
solitaire.move_left()
elif move == 'u':
solitaire.move_up()
elif move == 'd':
solitaire.move_down()
elif move == 's':
solitaire.select()
solitaire.draw()
screen.blit(background, (0, 0))
pygame.display.update()
sleep(0.1)
示例2: __init__
# 需要导入模块: from bot import Bot [as 别名]
# 或者: from bot.Bot import update_state [as 别名]
class MotherRussia:
'''Mother russia functions as the program object'''
def __init__(self, debug_mode=False, timeout=10.0):
self.data_handler = DataHandler()
self.connector = SocketHandler(timeout)
self.debug = debug_mode
self.bot = Bot()
self.DEFAULT_TICKS = 2*(1000//50)
self.ticks = self.DEFAULT_TICKS
def __enter__(self):
return self
def __exit__(self, exec_type, value, traceback):
if isinstance(value, KeyboardInterrupt):
print('\r\rRecieved keyboard interrupt')
elif isinstance(value, SystemExit):
print('Recieved system exit signal')
elif isinstance(value, Exception):
print('Exception: ', value)
print('Attempting to clean up...')
clean_error = self.clean()
if isinstance(clean_error, Exception):
print('Could not clean up: ', clean_error)
else:
print('Done')
if not self.debug:
return True
def init(self):
socket_error = self.connector.connect()
if isinstance(socket_error, Exception):
raise socket_error
self.connector.send_data('NAME Putin')
def run(self):
while True:
raw_data = self.connector.poll_data()
if len(raw_data) == 0:
break
json_error = self.data_handler.parse_data(raw_data)
if isinstance(json_error, ValueError):
# The exception will contain the string 'Extra data' if the
# raw data it received was incomplete. Therefore, try to
# receive new raw data
if 'Extra data' in str(json_error):
continue
else:
# In most cases, this error will be 'Expecting value',
# because the block of raw data it received was empty
raise json_error
if self.data_handler.is_dead or self.data_handler.is_end_of_round:
self.ticks = self.DEFAULT_TICKS
start = time.perf_counter()
self.bot.update_state(self.data_handler)
self.bot.make_decisions(self.ticks)
elapsed_time = (time.perf_counter() - start)*1000
if elapsed_time > 45 and self.ticks > 0.5*(1000//50):
self.ticks -= 1
elif elapsed_time < 30 and self.ticks < 4*(1000//50):
self.ticks += 1
# print(elapsed_time, self.ticks)
while len(self.bot.commands) > 0:
command = self.bot.get_command()
self.connector.send_data(command)
self.clean()
def clean(self):
try:
if self.connector.sock is not None:
self.connector.close()
except Exception as e:
return e