机器人游戏的游戏引擎
rgkit的Python项目详细描述
作为包安装
pip
安装工具包的最简单方法是 pip。从终点站, 运行:
pip install rgkit
或者如果您想要开发版本:
pip install git+https://github.com/RobotGame/rgkit.git
注意:这将在系统范围内安装rgkit。建议使用virtualenv来管理开发环境。
virtualenv
使用virtualenv安装需要以下步骤:
mkdir my_robot cd my_robot virtualenv env source env/bin/activate pip install rgkit
setup.py
也可以直接从源文件夹手动安装。做一个 git存储库的本地副本或下载源文件。那么, 使用终端,从 源代码:
python setup.py install
注意:这将在系统范围内安装rgkit。建议使用virtualenv来管理开发环境。
运行游戏
安装包后,脚本可以通过命令执行 line(如果您使用的是virtualenv,请记住激活环境)。 提供了两个入口点:rgrun和rgmap。这个 run的一般用法是:
usage: rgrun [-h] [-m MAP] [-c COUNT] [-A] [-q] [-H | -T | -C] [--game-seed GAME_SEED] [--match-seeds [MATCH_SEEDS [MATCH_SEEDS ...]]] [-r] player1 player2 Robot game execution script. positional arguments: player1 File containing first robot class definition. player2 File containing second robot class definition. optional arguments: -h, --help show this help message and exit -m MAP, --map MAP User-specified map file. -c COUNT, --count COUNT Game count, default: 1, multithreading if >1 -A, --animate Enable animations in rendering. -q, --quiet Quiet execution. -q : suppresses bot stdout -qq: suppresses bot stdout and stderr -qqq: supresses all rgkit and bot output -H, --headless Disable rendering game output. -T, --play-in-thread Separate GUI thread from robot move calculations. -C, --curses Display game in command line using curses. --game-seed GAME_SEED Appended with game countfor per-match seeds. --match-seeds [MATCH_SEEDS [MATCH_SEEDS ...]] Used for random seed of the first matches in order. -r, --random Bots spawn randomly instead of symmetrically.
因此,从包含您的_robot.py的目录中,您可以运行一个游戏 针对默认robot并使用以下命令抑制gui输出 命令:
rgrun -H your_robot.py defaultrobots.py
利用源代码开发
rgkit打包为一个模块,但是可以只签出 存储库和导入/运行源脚本。
./rgkit |--- rgkit | |--- __init__.py | |--- game.py | |--- run.py | |--- ... | |--- your_robot.py |--- setup.py ... /path/your_other_robot.py
运行游戏
要以这种方式配置源代码运行游戏,请使用终端 并从内部rgkit文件夹(即 与run.py目录相同:
python run.py your_robot.py /path/your_other_robot.py
为自己的机器人编码
一旦安装,您只需要rg模块来开发 拥有机器人。包可以像任何其他模块一样导入:
import rg class Robot: def act(self): return ['guard']