本文整理汇总了Python中bot.Bot.move方法的典型用法代码示例。如果您正苦于以下问题:Python Bot.move方法的具体用法?Python Bot.move怎么用?Python Bot.move使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bot.Bot
的用法示例。
在下文中一共展示了Bot.move方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: controlConexion
# 需要导入模块: from bot import Bot [as 别名]
# 或者: from bot.Bot import move [as 别名]
def controlConexion(self):
response = None
while self.conectado:
print("turno")
server_message = self.socket_cliente.recv(511)
message = server_message.split(";")
print(message[0])
if message[0] == "EMPEZO":
bot = Bot(message[2][0])
bot.update_map(message[1])
elif message[0] == "TURNO":
print("turno: %s" % message[1])
bot.update_map(message[2])
msg = bot.move()
self.socket_cliente.send(msg)
elif message[0] == "PERDIO":
print("perdi :(")
示例2: xrange
# 需要导入模块: from bot import Bot [as 别名]
# 或者: from bot.Bot import move [as 别名]
print >>outf, "P2" # PGM with ascii values
print >>outf, width, height
print >>outf, 1024
for j in xrange(height):
# scan line
print "LINE",j
for i in xrange(width):
# record
time.sleep(0.1)
val = bot.get_analog_input()
#print val,calib(val), '@',relx, rely
print calib(val),
print >>outf, calib(val),
# move
bot.move(stepby,0)
relx += stepby
print >>outf
print
# retrace
for i in xrange(width):
bot.move(-stepby,0)
relx -= stepby
# move down
bot.move(0,-stepby)
rely -= stepby
# Move back up
bot.move(0,stepby*height)
示例3: __init__
# 需要导入模块: from bot import Bot [as 别名]
# 或者: from bot.Bot import move [as 别名]
#.........这里部分代码省略.........
self.states = []
# Restart game with brand new bot
self.bot = Bot()
# Default move is no move !
direction = "Stay"
# Create a requests session that will be used throughout the game
self.pprint('Connecting...')
self.session = requests.session()
if self.config.game_mode == 'arena':
self.pprint('Waiting for other players to join...')
try:
# Get the initial state
# May raise error if self.get_new_state() returns
# no data or inconsistent data (network problem)
self.state = self.get_new_game_state()
self.states.append(self.state)
self.pprint("Playing at: " + self.state['viewUrl'])
except (KeyError, TypeError) as e:
# We can not play a game without a state
self.pprint("Error: Please verify your settings.")
self.pprint("Settings:", self.config.__dict__)
self.running = False
return
for i in range(self.config.number_of_turns + 1):
if self.running:
# Choose a move
self.start_time = time.time()
while sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
line = sys.stdin.read(1)
if line.strip() == "q":
self.running = False
self.bot.running = False
break
if self.bot.running:
direction = self.bot.move(self.state)
if not self.is_game_over():
# Send the move and receive the updated game state
self.game_url = self.state['playUrl']
self.state = self.send_move(direction)
self.states.append(self.state)
# Clean up the session
self.session.close()
def get_new_game_state(self):
"""Get a JSON from the server containing the current state of the game"""
if self.config.game_mode == 'training':
# Don't pass the 'map' parameter if no map has been selected
if len(self.config.map_name) > 0:
params = {'key': self.config.key,
'turns': self.config.number_of_turns,
'map': self.config.map_name}
else:
params = {'key': self.config.key,
'turns': self.config.number_of_turns}
api_endpoint = '/api/training'
else:
params = {'key': self.config.key}
api_endpoint = '/api/arena'
# Wait for 10 minutes
try:
r = self.session.post(self.config.server_url + api_endpoint,
params,
timeout=10 * 60)
if r.status_code == 200:
return r.json()
else:
self.pprint("Error when creating the game:", str(r.status_code))
self.running = False
self.pprint(r.text)
except requests.ConnectionError as e:
self.pprint("Error when creating the game:", e)
self.running = False
def is_game_over(self):
"""Return True if game defined by state is over"""
try:
return self.state['game']['finished']
except (TypeError, KeyError):
return True
def send_move(self, direction):
"""Send a move to the server
Moves can be one of: 'Stay', 'North', 'South', 'East', 'West'"""
try:
response = self.session.post(self.game_url,
{'dir': direction},
timeout=TIMEOUT)
if response.status_code == 200:
return response.json()
else:
self.pprint("Error HTTP ", str(response.status_code), ": ",
response.text)
self.time_out += 1
self.running = False
return {'game': {'finished': True}}
except requests.exceptions.RequestException as e:
self.pprint("Error at client.move;", str(e))
self.running = False
return {'game': {'finished': True}}
示例4: Board
# 需要导入模块: from bot import Bot [as 别名]
# 或者: from bot.Bot import move [as 别名]
from agent import Agent
board = Board()
agent1 = Agent(board, 1, 0.1, 0.0, 0.5)
agent2 = Agent(board, 2, 0.8, 0.2, 0.9)
all_turns = []
for x in range(0, 1000):
turns = 0
finished = False
player1 = Bot(board, agent1)
player2 = Bot(board, agent2)
message = "Win!"
while not finished:
turns += 1
player1.move()
player2.move()
finished = board.finished()
if turns > 400:
finished = True
message = "Stalemate"
# print message
b, r, bk, rk = board.get_values()
# print("R: " + str(r) + " RK: " + str(rk) + " B: " + str(b) + " BK: " + str(bk))
all_turns.append(turns)
board = Board()
agent1.set_board(board)
agent2.set_board(board)
if x % 100 == 99:
print(sum(all_turns)/len(all_turns))
all_turns = []