Battleofai API的包装。
battleofai的Python项目详细描述
人工智能之战-python库
面向对象的easy2使用解决方案与https://battleofai.net/的API交互
基本特征的简要概述
轻松配置客户端。
frombattleofaiimportClientclient=Client(credentials=('username','password'))# if you want to export your configclient.config.from_python_file('config.py')# or use jsonclient.config.from_json_file('config.json')
自动玩游戏。
frombattleofaiimportClient,Coreclient=Client()# specify credentials@client.callback()defturn(board,symbol):forx_pos,columnsinenumerate(board):fory_pos,fieldinenumerate(columns):iffield=='#':# if position is freereturnx_pos,y_pos# set my stoneclient.play(Core)
手动玩游戏。
frombattleofaiimportClient,Core,GameStateimporttimeclient=Client()# specify credentialsdefturn(board,symbol):forx_pos,columnsinenumerate(board):fory_pos,fieldinenumerate(columns):iffield=='#':# if position is freereturnx_pos,y_pos# set my stonegame=Core.create_game()client.login()my_match=Core(callback=turn)my_match.join_game(client,game)# then eithermy_match.play()# or even something like thisplaying=Truewhileplaying:game.update()ifnotgame.state==GameState.STARTED:breakifmy_match.is_active:resp=my_match.make_turn()ifresp.status_code==200and'false'inresp.text:playing=Falsetime.sleep(5)
管理游戏。
frombattleofaiimportGame,GameState,Coremy_game=Game.get(game_id=100)print(my_game.players)open_games=Game.list(game_state=GameState.WAITING)new_game=Game.create(Core.__game_name__)