Site logo, www.grelf.net
 

The Forest - orienteering simulation

The program described here demonstrates a technique for generating vast terrain by an algorithm rather than storing it in memory or having to download it as a huge amount of data.

A major aim of The Forest, from its earliest version some 35 years ago, has been to help people interpret the contour information in maps. That enables orienteers to navigate without just following roads or streams, it helps hill walkers to avoid getting lost, and more generally it helps anyone reading a map to get the most out of it.

This program also includes some non-trivial games or diversions for those who are not orienteers.

The version available here is written in JavaScript for an HTML5 page and occupies only about 100 kilobytes, so it downloads and runs almost instantly. Nevertheless it has more than 1,000 sq km of forest to explore.

Try it: The Forest

New alternative URL, easier to remember: myforest.uk

I first used the method in the early 1980s in a program for the Sinclair ZX Spectrum, a machine having only 48 kilobytes of useable memory. That program simulated the sport of orienteering quite successfully despite the severe limitations of the technology. More details can found in the history page which includes a link to an archive for obtaining the old program and running it on a Spectrum emulator.

I am keen for other programmers to learn about the technique and perhaps take it further, so the source code of the new program is easily viewed.

The Forest demonstrates that JavaScript engines in browsers are now very fast. So client-side JavaScript in an HTML5 page can be an effective platform for games, avoiding large data downloads. It has many advantages: it is available on a very wide range of devices without needing any adaptation for each and does not require to be accessed through any application program ("app") store.

 The Forest reincarnated

There are three views of the terrain available in The Forest:

This text is from www.grelf.net

Although there are buttons for switching between these views there are also keyboard alternatives indicated on the buttons.

 Map and 3D plot

The map has 4 states, selectable through a button:

This text is from www.grelf.net

All show north lines 300m apart.

Printed orienteering maps declare their scale and contour interval but we cannot do that here. The scale depends on the size of your display screen. However, 1 pixel on the map represents 1 metre on the ground and the initial map is 800 pixels wide and 600 high. The north lines indicate the scale because they are 300m apart. The vertical scale in the scene display is rather arbitrary, so it is not possible to say what the contour interval is either. Just assume it is the usual 5m.

The map can be rotated clockwise in steps of 90°. North lines on the map have black arrows so that when the map has been rotated the direction of north is clear. Some orienteers find it easier to relate the map to the ground if it is oriented roughly to the direction they are facing.

The aim of the 3D plot is to help people interpret contour lines on the map. It may take several seconds to draw the plot - rather longer than the scene or map views.

 The scene view

The scene view indicates what the observer would see from an eye level 1.5m above the ground. The view indicates whether the ground ahead slopes up or down, according to the contours on the map. The type of terrain ahead is indicated by graphics. One of the advances here is that real photographic images can be used rather than simple drawn graphics. The ground is drawn in true perspective out to a certain distance ahead (the visible range). Initially this range is set to 30m but you can select greater ranges. You will soon find that if the range is too great it will take an appreciable time to draw the scene (depending on the speed of the processor in your computer). For moving through the forest it is desirable to keep the scene drawing time to less than a tenth of a second (100ms) The drawing time is shown in a status line below the display.

The arrow keys are active in the scene and they act as follows.

NB:

  1. The arrow keys may scroll/pan the window in some browsers or on small screens, so letter key alternatives are allowed: initials of Right, Left, Up , Down (upper or lower case).
  2. On touch screens it is possible to tap near the edges of the scene or map instead of using arrow keys. On a PC a mouse click just inside an edge of the image will also work.

Note that the observer's current position (x, y) and bearing (degrees clockwise from due North) are shown in the status line at the bottom of the view. A compass is also shown at the bottom centre of the scene view.

Shallow lakes may be crossable but if the depth becomes greater than a couple of metres you will be told you are out of your depth and you will be turned around to swim back to the shore. So venturing into lakes can be very time-consuming.

Why do level things such as lakes appear to slope down at the edges of the scene? Because we are viewing a circular disc patch of ground from a small eye-level distance above it. The effect becomes less as the visible range is increased.

 Roles

The observer mentioned above may have one of several roles:

 The easy short course

 At the finish

When an orienteer completes a course the full control card and a table analysing the route are shown:

 

How can the orienteer complete a leg of the course by travelling less than the crow-fly distance? Easily because it is only necessary to be within 5m of a control for it to be punched. By approaching and leaving controls in the right direction it is possible to cover up to 10m less than the actual distance between controls. This is not just a feature of this simulation: it now happens in the real sport because electronic devices are used for automatic punching when within 5m of a control.

Try it: The Forest

 Additional keys

Some keys have effects which are not represented by buttons or other controls on the web page. They only work unshifted (lower case). They are perhaps experimental and may or may not develop into something more.

 Two windows

On a PC (but not on a tablet or phone) you may well have room on the screen for part of the map alongside the scene on the ground. This can be achieved by having two browser windows open, each with a copy of the program running in it:

 

 Explorers: a game for you

Now available (version 18.5.15 onwards)

Explorers can see things in the forest which orienteers cannot. Some of these things will suggest a target to aim for (more achievable than in my 1980s Explorer version of this program: see Pixelatron).

You will inevitably want to copy and save images of some of the things you see but this program does not provide any such facility. Instead you will need to use a screen copying program in whichever system you are running, such as the Snipping Tool in Windows.

Hint: there is a short-cut, described in this page, for something which may at first seem very lengthy in your task.

 It's raining

Something else which explorers can now experience (but orienteers will not want to be bothered with) is changing weather. Rain causes the levels of lakes to rise and when it stops and the sun comes out, the levels fall back. A message appears briefly when lake levels are back to normal.

This illustrates that the terrain can change. Earthquakes would change the topography more drastically and that could easily be effected but it has not been done.

 Further information

There are some pages about my orienteering maps of real forests here. Follow the links there to read more about the original ZX Spectrum simulation of orienteering.

In particular there is a page about why The Forest is designed the way it is, which I wrote in the mid-1980s. It still has some relevance, especially about why I do not attempt to use maps of real forests (a scarce resource in the UK).

I started developing the new HTML5/JavaScript version in 2014 but it was heading more towards my second Spectrum program, Explorer (published by Electric Dreams in the mid-1980s). It included the possibility of falling down mineshafts and navigating underground. It also included a teleportation feature whereby typing a string of characters would take you to a new position on the map, seemingly at random but the same string would always go to the same place. Having got those features to work I rather lost interest in that development and shelved it.

My interest began again in February 2018 with an email out of the blue from Graham Scott of NATO (Newcastle and Tyneside Orienteers). He and I had been members of Tyneside Orienteers (as it was then) more than 30 years ago. I decided to complete the program as a purely orienteering project. Try it: The Forest

 Programming

The original versions of The Forest and Explorer were written in Z80 assembler, in order to fit into the very limited amount of memory available and to run at a reasonable speed (much faster than interpreted BASIC). The new version at www.grelf.net/forest is written in JavaScript, a much more easily comprehended language, running within an HTML5 page and doing the graphics within <canvas> elements. If you right-click and "view source" on that page you can see the file names for the JavaScript files and therefore view them also in your browser, to see how it works. If you are not familiar with JavaScript, particularly its object-oriented aspects, you may wish to peruse my introductory programming course.

Note again that the program runs entirely in your browser. After downloading the program and images the server has no further involvement. The browser does all of the hard work of course, and that is a very much larger program. I am amazed by how much detail it is now possible to show in real time by writing some JavaScript and running it in a standard browser.

The contours and terrain types repeat after 33km (32768m to be precise; older programmers will recognise that number instantly) but the point features do not repeat like that.

I am documenting aspects of the software design here.

Programming challenge

If you are already a JavaScript programmer you will be able to explore my code. Then you might like to try this:

Find the (x, y) coordinates of the highest point on the map (in the first block of the 32km repeating terrain, starting at 0, 0). Is this point unique (are there any other points at the same height)? Do the same for the deepest points in the lakes. Please email me with the answers, at gr[at]grelf{dot}net - I will be interested to see whether anyone does this. It doesn't take much code.

 Remaining work

June 2018: I plan to keep adding better graphics and more features, such as alternative games for those explorers who complete the first quest. I am open to ideas for further enhancements.

Next page