thunderer / logeek
PHP版本的乐高Mindstorms NXT机器人编程引擎
v0.2.0
2018-07-09 09:38 UTC
Requires
- php: ^7.0
Requires (Dev)
- phpunit/phpunit: ^6.0|^7.0
This package is auto-updated.
Last update: 2024-09-15 00:13:22 UTC
README
简介
Logeek是一个PHP引擎,通过模拟元素在板上的移动来学习基本编程。其概念与乐高Mindstorms或Android和iPhone游戏Robot School相似。
需求
仅支持PHP 5.3(命名空间)。
安装
此库在Packagist上以别名thunderer/logeek
提供。
使用方法
// first create Board object with desired dimensions $board = new Thunder\Logeek\Board(5, 5); // then add field types and actions allowed on this board $board->addFieldTypes(array('ground' => '.')); $board->addActions(array(new MoveAction())); // load board using field aliases $board->loadFromString('...'); // add actors and exits $board->addExit('exit', 2, 0); $board->addActor('robot', 0, 0, 'right'); // add program for your actor, function "main" will be run $compiler = new Compiler(); $functions = $compiler->compile($board, ' function main move 2 '); // run the simulation (print board size before and after) echo $board->renderBoard(); $board->runActor('robot'); echo $board->renderBoard(); // check if everything is correct assert(true === $board->isActorAtExit('robot', 'exit'));
程序语法是一种简单的Python-like编程语言,具有显著的空白(缩进为2个空格)。行首的数字表示重复该行指定次数。目前实现的操作如下:
-
基本操作
- 向左|向右旋转
- 移动长度|变量
- 拾起|放下
- 打开
-
循环
- for迭代次数
- while变量是|不是值
-
条件
- if变量是|不是值
-
结构
- 函数名
-
传感器
- 传感器类型变量
- 传感器距离变量
- 传感器接近变量
示例模拟实现于tests/LogeekTest.php
,查看、修改和实验它们很容易。
许可证
请参阅此存储库根目录下的LICENSE文件。