An open API service indexing awesome lists of open source software.

https://github.com/dwayne/herbert-python

A Python implementation of the Herbert game from the Imagine Cup algorithm contest.
https://github.com/dwayne/herbert-python

game herbert imaginecup programming-puzzles python

Last synced: 10 months ago
JSON representation

A Python implementation of the Herbert game from the Imagine Cup algorithm contest.

Awesome Lists containing this project

README

          

Herbert
=======

Herbert is a game I first saw in the `Imagine Cup 2008 Algorithm Invitational `_.

The game requires you to solve a series of levels by writing small programs to
control a robot named Herbert. The simpler and more elegant your solution, the
more points you get.

It challenges your ability to see patterns and create algorithms to produce
those patterns.

Here's my clone of Herbert.

.. image:: https://raw.githubusercontent.com/dwayne/herbert-python/master/data/images/herbert.png

Enjoy!

Installation
------------

To install, simply use pip (or `pipenv`_):

.. code-block:: bash

$ pip install herbert

Usage
-----

To run :code:`herbert` you need a **level** to solve and a **program**, that you
write, that attempts to solve the level.

Suppose the level is stored in :code:`level.txt` and that you wrote and saved
your solution in :code:`sol.h`. Then, you'd run :code:`herbert` as follows:

.. code-block:: bash

$ herbert level.txt sol.h

It will open a `curses `_
based text user interface that allows you to run your program against the level
to determine if it solves the level and how many points your solution is worth.

**N.B.** The `data/example `_
directory contains an example level along with 3 attempted solutions to the
level. You can use it to help you understand how the game works.

**An overview of the game**

A level consists of empty spaces (:code:`.`), walls (:code:`*`), white
(:code:`w`) and gray (:code:`g`) buttons, and a robot (:code:`u` means the robot
is facing upwards, :code:`r` means the robot is facing towards the right,
:code:`d` means the robot is facing downwards, or :code:`l` means the robot is
facing towards the left).

**N.B.** You can find an example level `here `__.

On each level there are some white buttons. To solve a level you must press all
the white buttons. Your goal then is to program Herbert, in a language called
"h", to press all the white buttons while avoiding obstacles such as walls and
gray buttons (walls block Herbert's path and gray buttons reset any previously
pressed white buttons to their unpressed state).

You are only allotted a certain number of "bytes" (a unit of program size) per
level. Your program must use no more than this number of bytes.

Points are awarded for each white button pressed, a bonus is awarded for solving
the level, and extra points are awarded for solutions that use less than the
allotted maximum number of bytes.

**The "h" language**

It is a simple language that contains statements, procedures with zero or more
parameters and recursion. Check out the tutorial `here `__
to get a better understanding of the language.

You can find examples of the language in use `here `__,
`here `__
and `here `__.

**Challenge**

Try to solve the following levels (see `data/levels `_):

- `Level 1 `_
- `Level 2 `_
- `Level 3 `_
- `Level 4 `_
- `Level 5 `_

Development
-----------

Recommended tools:

- `pyenv `_
- `pipenv`_

Clone the repository and install the dependencies:

.. code-block:: bash

$ git clone git@github.com:dwayne/herbert-python.git
$ cd herbert-python
$ pipenv shell
$ pipenv install --dev

You're now all set to begin development.

Testing
-------

Tests are written using the built-in unit testing framework, `unittest `_.

Run all tests.

.. code-block:: bash

$ python -m unittest

Run a specific test module.

.. code-block:: bash

$ python -m unittest tests.test_interpreter

Run a specific test case.

.. code-block:: bash

$ python -m unittest tests.test_interpreter.ExamplesTestCase.test_example10

Resources
---------

- `Herbert Programming Challenge `_ by `Wild Noodle `_
- `Herbert Online Judge `_
- `uHerbert `_

.. _pipenv: https://github.com/pypa/pipenv