thunderer/logeek

Lego Mindstorms NXT-like robot programming engine in PHP

v0.2.0 2018-07-09 09:38 UTC

This package is auto-updated.

Last update: 2024-10-15 00:16:18 UTC


README

Build Status SensioLabsInsight License Latest Stable Version Dependency Status Scrutinizer Code Quality Code Coverage Code Climate

Introduction

Logeek is a PHP engine for learning basic programming by simulating movement of element through a board. It's concepts are similar to LEGO Mindstorms or Android and iPhone games like Robot School.

Requirements

Only PHP 5.3 (namespaces).

Installation

This library is available on Packagist under alias thunderer/logeek.

Usage

// 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'));

Program syntax is a simple Python-like programming language with significant white-space (indentation of 2 spaces). Number as the first token in line means repeating that line that number of times. Currently implemented actions are as follows:

  • Basic:

    • rotate left|right
    • move length|variable
    • pick up|down
    • open
  • Loops:

    • for iterations
    • while variable is|not value
  • Conditions:

    • if variable is|not value
  • Structure:

    • function name
  • Sensors:

    • sensor-type variable
    • sensor-distance variable
    • sensor-proximity variable

Sample simulations are implemented in tests/LogeekTest.php, it's easy to look, change and experiment with them.

License

See LICENSE file in the root of this repository.