Niki the Robot Online Remake

By Stefan Nikolaj on April 19, 2025. Tags: programming.

Introduction

Screenshot of page


Niki the Robot (Niki der Roboter) is an Ancient German (1990s) educational programming language and game. In the lost tradition of Turtle Graphics and BASIC, it aimed to allow younger people to learn basic programming principles by writing code that does stuff on screen, as opposed to rewriting Fibonacci or Bubble Sort. Unfortunately, given the age, it’s written in (probably) Turbo Pascal and looks like it. About a year ago, I mentioned to my computer science professor that I was interested in rewriting it, but I never got around to doing it, until now. My main point of interest was to learn more about parsing code and as an exercise in making custom programming/markup languages.

The point of Niki the Robot is that you have a grid that you can edit and a robot character that can be placed anywhere. The game allows you to draw walls and create balls. Niki can move in any direction and do a few checks, like if there’s a ball or a wall nearby. Based on those simple rules, you can create your own games – you can build a maze, apply algorithms, practice coding – anything you want! Niki the Robot is controlled by writing code for it in a simplified version of Pascal with no variable declarations. Pascal, in my opinion, is a great language for this due to the fact that it’s both similar to modern languages like Python, while also being visually and logically similar to pseudocode, which makes it great for beginners. The lack of clutter and complex syntax makes it easy to focus on just the learning.

I initially tried to follow the amazing youtuber Bisqwit’s programming language tutorial with Bison and similar many years ago, but I just couldn’t get the toolchain to work reliably. I just never vibed with GNU tools. For this project, I made the choice to go with Peggy, a fully-JavaScript parser generator. This does the hard part of parsing a programming language by turning messy code into an easily traversable and readable Abstract Syntax Tree (AST). The AST is easier to interpret because it subdivides the language into tokens with a very specific and explicit meaning and structure. Peggy applies the rules defined in a grammar file, which get invoked sequentially and make sense of more and more of the language. Like a human doing a calculation, compound statements get reduced to individual, connected branches. Recursively, the interpreter handles each statement in just one large switch statement, which makes everything much easier. The interpreter then runs the code on the playfield. In this case, since there’s no compilation, this is running Pascal as an interpreted language, which is quite fun.

About the app

The fact that it’s written in JavaScript allowed me to put it in an HTML page and run it as a normal webpage – no app needed. My goal is to allow everyone to run it, regardless of their operating system or proficiency with handling ancient Windows apps that come with instructions on loading levels from floppy disks. We are two generations removed from floppy disks – most kids these days don’t even play singleplayer video games to know what saving a game is, so they would never even know that the save icon was actually based on what floppy disks looked like. 

The HTML/CSS/JavaScript is fairly normal, no black magic here. The simple colors and simple layout make it similar to the original, but with simply more features and many quality-of-life improvements. Now you can save and load both the code and the playfield from the main page. You can load a few examples to see a rough idea of what you can and should do. Those examples have comments too! Any errors in the Pascal code will result in a somewhat legible error output and explanation in the bottom left of the screen. 

The app is free to use forever, and the source code is open forever. If anyone has any feature requests, just request them! I’m open to any requests for collaboration or some kind of working relationship too.

How to run it

I haven’t gotten around to setting it up on my server, but you can find the GitHub repository with the entire source code here: snikolaj/niki_the_robot: A JavaScript remake of the Niki the Robot educational game and programming language

To run the app, you need to serve it with a server. If you have Python installed, a very simple way of doing this is to just run this command in the main folder: py -m http.server

Eventually, you’ll be able to run Niki the Robot in your browser without downloading anything!

Table of contents: