适合python东北的伟大精灵游戏-客户机和服务器
pyne-xmas-elves的Python项目详细描述
年度圣诞精灵游戏服务器和客户端
Python东北12月为您带来圣诞精灵挑战赛。你的任务, 如果您选择接受它,就是收集最多的
运行游戏
指南的这一部分将指导您设置游戏,以便您 可以开始尝试高分了!
安装
确保安装了python—如果有windows,请查看 Beginner’s Guide of the Xmas Elves document。
一旦准备好,就可以运行客户端代码:
pyvenv venv . venv/bin/activate pip install pyne-xmas-elves
构建您的机器人
创建游戏文件,名为game.py:
frompyne_xmas_elves.clientimportBaseGameclassGame(BaseGame):"""Your main Game Class. """PLAYER_NAME='Tom Cooper'defturn(self,elves_available):"""Take a single turn. The elves_available argument will tell you how many elves you can use as a guide. """send_to_woods=elves_available//2send_to_forest=(elves_available-send_to_woods)//2send_to_mountains=elves_available-send_to_forestreturn(send_to_woods,send_to_forest,send_to_mountains)
助手属性
转弯时,您可以访问self上的以下属性:
- amount_raised-募集资金总额
- current_turn-当前匝数
- last_turn-最后一圈的号码是多少
- previous_weather-上次探险的天气
运行游戏
创建机器人后,您可以运行游戏:
elves game
运行服务器
安装依赖项
服务器是自包含的,有一个sqlite数据库,所以只需安装 要求:
pip install -r requirements.txt
运行
我们使用的是django频道,因此运行服务器非常简单:
python server/manage.py runserver
API
为了与服务器会话交互,我们使用一个简单的rest api来发送新的数据 进入服务器。完整的api文档可以通过运行服务器和 导航到/docs/。
开始新会话
若要启动新会话,请使用name变量发送POST请求 表单编码为https://<host>/sessions/:
curl https://example.com/sessions/ -X POST -d player_name="Scott"
您将得到一个简单的json对象,该对象带有一个sessionurl 反过来。
转弯
若要进行轮换,请对会话的day端点发出POST请求。
说明和规则
有关规则和 最新的提示和技巧。