Sunday, 20 September 2009

A History of Programming Games 1961-1989

In a programming game players write a program to complete a specific task, usually to wipe out all opponents. The contest takes place between either programs in the memory of a virtual computer or robots in an arena.

Darwin


In August 1961, Douglas McIlroy, Robert Morris and Victor Vyssotsky invented Darwin and the programming game genre. Programs written using IBM 7090 machine code competed to destroy all opponents and be the most prolific replicator. An Umpire provided three functions to probe memory for an opponent, to claim memory or kill an opponent.

RobotWar


RobotWar was written in the 1970s by Silas Warner for the PLATO computer system and published commercially for the Apple II by MUSE Software in 1981. Programs written in a proprietary high level language control robots which battle to eliminate all opponents in a virtual arena. In the early 1980s a society was formed and an annual tournament organised by Computer Gaming World.

Color Robot Battle


The Image Producers released Color Robot Battle in 1981 for the TRS-80 Color Computer. The game was played by writing programs in a simple hybrid of BASIC and Logo to control a battle robot. Programs faced each other in a one-on-one battle with the last robot standing being declared winner.

Core War


Alexander Dewdney described Core War in the May 1984 issue of Scientific American, introducing programming games to a wide audience for the first time. Core War became popular overnight. A society was formed, a newsletter published and regular tournaments held. Core War is played between assembly languages programs in the memory of a virtual computer. Each program attempts to eradicate all opponents. Core War can be played by email at KOTH.org or KOTH@SAL.

DROID


Inspired by RobotWar, DROID was developed at Reichhold Chemicals as a teaching aid in December 1984. Programs to control robots are written in the D-code assembly language and attempt to exterminate all adversaries in the virtual arena. DROID can be played by Telnet on the Empire HPe3000 server.

CROBOTS


Tom Poindexter published CROBOTS as shareware in December 1985 after being inspired by RobotWar. A subset of C is used to control battle robots. As usual, the aim of the game is to destroy all opponents in a virtual arena. A king of the hill tournament is organised by Maurizio Camangi.

P-Robots


In 1988 David Malmberg released P-Robots, a robot battle game based on a subset of the Pascal programming language and inspired by CROBOTS. Later versions introduced a variety of optional extras for robots, teams and obstacles.

OMEGA


OMEGA is a programming game written by Stuart Marks and published by Origin Systems in 1989. The object of the game is to program a tank to defeat a series of increasingly more powerful enemies. Each opponent defeated unlocks a higher security clearance and increased budget.

Unfortunately there's very little information about some of these games online. Do you remember playing any of the above? Which is your favourite programming game and why?

Thursday, 10 September 2009

#songsincode - Lyrics for Programmers

#songsincode#songsincode are small pseudo-programs which display a song title or part of the lyrics. The more refined examples use conditional code and control stuctures to define the song.

The tag was first used on twitter a couple of weeks ago. After a sudden burst of popularity, #songsincode has slowed to about 20 tweets a day. Here's an example by testydonkey:

if(Door.Color == System.Color.Red)
{ Door.Color = System.Color.Black; }

This is Paint it Black by the Rolling Stones, “I see a red door and I want it painted black”.

Here's the top 25 countdown of the very finest #songsincode. Can you identify all 25? Is your favourite missing? Let me know :-)

anurse:
var s = new Submarine(Color.Yellow);
s.Residents.Add(Us); for(int i=0;i<2;i++)
{Assert.IsTrue(s.Color == Color.Yellow);}

darrennisbett:
h=new hotel(); h.name="california";
h.guest.addEvent("checkout");
h.guest.removeEvent("leave")

royvanrijn:
if(grass=="green" && girls == "pretty")
{ takeMe(paradiseCity); }

injenierobarsa:
for (int i = 1; i <= 99; i++)
{ redBalloons[i].goBy() }

3d0:
if(my.sexyness>shirt.sexyness) pain();

phikachu:
me.color = 0x0000FF;
me.text = “Da Ba Dee Da Ba Di”;

Borisson:
($horse_name == false ? $location = desert : ' ');

plaxdan:
self.vehicle = new CombineHarvester();
you.setKey(vehicle.getKey());

cargoweasel:
SubwayWalls.write(words_of_the_prophets());

Leadhyena:
I.send("...---...",world);
I.send("...---...",world);
while(!(someone.receive(bottle)&&
bottle.contains(message)){I.hope()}

antallan:
substring("the tiger",6,1)

pitsk:
void shootPeople() { shootSherif; return;
shootDeputy; }

sbruchmann:
if ($angelsDeserveToDie) { iCry(); }

royvanrijn:
while( !me.like(mondays) ) { tellWhy(me); }

Levistica:
cuts.firstElement().deepness = max;

uberTof:
final--;

plaxdan:
while (thing != that) { doForLove(thing);

numptygeek:
jumpWithDirection(left); stepWithDirection(right);

CarstenHagemann:
$jealous_sky[$sun] = $you->tell()
if ($we->walk($fields_of_gold));

numptygeek:
if(somethingStrange==true && location ==
neighborhood){ ghostbusters();
printf("I ain't afraid of no ghost");}

draconum:
//roxanne.putOnLight('#ff0000');
commented out, was not necessary

brozow:
video$ kill -9 `ps -ef | grep radio*`

rennyhernandez:
stuff={'red door','a line of cars', 'my heart'}
stuff.each do |it| it.setColor('#000000') end

codepo8:
.clowns{float:left;}.jokers{float:right};
#me_you{position:fixed;margin:0 auto;width:100%}

royvanrijn:
for(Leaf leaf:leafs)
{ leaf.setColor(new Color(139,69,19)); }
sky.setColor(Color.GRAY);

#moviesincode, #tvincode, #booksincode!


#songsincode has inspired three new tags. Can you see #moviesincode, #tvincode or #booksincode catching on? :-)

sijmen:
TypeError: Result of expression this.spoon'
[undefined] is not an object

rhizomecowboy:
trace(isNAN(prisoner));

nail7:
var i = count(MonteChristo);

#songsincode, lyrics for programmers

Saturday, 29 August 2009

My Two Greatest Programming Sins

My programming sins are too numerous to count, but there are two which keep coming back to haunt me over and over:
  • version control - while developing a program I create multiple versions. Development may split into multiple paths or be backtracked. Without proper version control, confusion is inevitable.
  • illegible code - I make frequent tweaks and changes, use irrelevant names for labels and functions and fail to comment code. It's unlikely I'll understand the program if I return to it a few weeks later.
Earlier this week I posted an example of ugly code. By examining the program, the magic numbers or output for sample input, three readers identified the code as an implementation of parallel bit counting. Here's how the bit counter ought to have been implemented:
: (COUNTBITS) ( u1 u2 u3 -- u4 )
( u1 = partial count )
( u2 = power )
( u3 = mask )
( u4 = new partial count )
ROT 2DUP AND >R ROT / AND R> +
;

: COUNTBITS ( u1 -- u2 ) ( parallel count )
( u2 = number of 1 bits in u1 )
2   %101010101010101 (COUNTBITS)
4   %011001100110011 (COUNTBITS)
16  %000011100000111 (COUNTBITS)
256 %000000000001111 (COUNTBITS)
;
To increase code legibility, the following changes have been made:
  • function name now represents the word's behaviour
  • word factored into two simpler words
  • documented the word's stack activity
  • represented the bit masks in binary
It's also worth considering what countbits will be used for (any suggestions?). Do we really need a fast bit twiddling algorithm? A simple iterated count or sparse ones algorithm will probably suffice:
: COUNTBITS ( u1 -- u2 )( iterated count )
( u2 = number of 1 bits in u1 )
0 SWAP
BEGIN
2 /MOD >R + R>
?DUP 0=
UNTIL
;

: COUNTBITS ( u1 -- u2 ) ( sparse ones )
( u2 = number of 1 bits in u1 )
0 SWAP
BEGIN
?DUP
WHILE
DUP 1- AND >R 1+ R>
REPEAT
;

Now I've identified a couple of faults with my coding technique, I'm hoping to correct my shortcomings while tackling my next programming project. What is your greatest coding sin and how do you plan to deal with it?

Tuesday, 25 August 2009

Impenetrable Code

However elegant a programming language, some fool will always find a way to write ugly code.

Here's a word I recently implemented in Forth:
: C
>R
256 15 16 1799
4 13107 2 21845
R>
4 0 DO
TUCK OVER AND -ROT
INVERT AND ROT / +
LOOP
;
Although I didn't set out to intentionally create something hideous, I'm appalled by how difficult to understand the code is. How can I make the word easier to comprehend and can you remind me what it's supposed to do?

Saturday, 25 July 2009

Perverse Code: Deviant Forth

The Forth programming language has a set of functions (or words) called primitives. These are traditionally written in the language of the host machine to keep the system as simple and efficient as possible. Typically the primitives required no more than about five machine instructions each to implement.

Deviant Forth explores the possibility of using Forth to implement some of the primitives. Warning, prolonged exposure to this code may cause permanent damage to your eyes!

As a exercise, let's implement NIP in Forth:

: NIP SWAP DROP ;

Standard stuff so far. Now lets try to implement SWAP and DROP!

: DROP DUP - + ;
: SWAP OVER >R >R DROP R> R> ;

Things are beginning to look ugly. On most systems DROP can be implemented in one machine instruction and SWAP in four. It's also possible to implement DUP, + and OVER in Forth:

: DUP >R R@ R> ;
: + >R DUP DUP - R> - - ;
: OVER >R DUP DUP R@ - DUP >R - R> R> + ;

I'm no Forth purist, but I feel repelled by the abomination I've programmed. Despite this, it's interesting to discover so many Forth words can be implemented with just >R, R>, R@ and -, however unnatural it might be.

As an afront to the very nature of Forth I challenge you to implement ROT using only >R, R>, R@ and -. If you can in less than 50 words I'd love to see your solution, however unpleasant :-)

Thursday, 9 July 2009

RobotWar and the Army of Clones

Back in 1981 Silas Warner created a game for MUSE Software which would go on to spawn an entire army of clones. Silas is probably better know as the author of the legendary Castle Wolfenstein. However it was RobotWar which went on to inspire a whole new genre.

screenshot: RobotWar, the battlefield of the futureSilas developed RobotWar for the PLATO computer system and later ported it to the Apple II for release by MUSE. The game is set at a time in the distant future when war has been declared hazardous to human health. Wars still rage, but the combatants are robots programmed to battle to the death.

RobotWar is played by writing the control program for one of these battle robots. The program controls the movement, radar and gun of the robot. Here's one of the example robots:

;     ROBOT  'SCANNER'
; SEND RADAR PULSE AND FIRE IF AN
; ENEMY IS SPOTTED

SCAN
AIM + 7 TO AIM

CHECK
AIM TO RADAR
IF RADAR > 0 GOTO SCAN
0 - RADAR TO SHOT
GOTO CHECK

Scanner is a simple stationary warrior. The first instruction (at scan) turns the gun 7° clockwise. The next instruction (at check) lines up the radar with the gun. The radar returns a positive number if it detects nothing, otherwise it returns minus the distance to the opponent.

The next line jumps back to scan if the radar returns positive. Otherwise a shell is fired by the penultimate instruction and the next line jumps back to check.

RobotWar earned a strong following in the early 1980's. Computer Gaming World organised annual tournaments and a group of enthusiasts formed the Postal RobotWar Club of America.

RobotWar has inspired a huge number of clones, I'll just mention a select few here:

  • CROBOTS by Tom Poindexter (1985) uses a subset of C
  • P-Robots by David Malmberg (1988) uses a Pascal subset
  • AT-Robots by Ed T Toten (1992) uses assembly language
  • Robocode by Mathew Nelson (2001) uses Java

Robocode is currently the most active. More information is available on the RoboWiki.

Please let me know if you think I've missed an important robot programming game or one of historical note. Also I'd love to hear from you if you have any memories of the above.

Thursday, 2 July 2009

Five Computers I Longed to Possess in the 1980s

Back in the 1980's I owned a couple of computers, a Commodore 16 and a Spectrum +2. However, this didn't stop me wanting to own a whole range of other machines.
  1. Jupiter Ace: I loved this from the moment I read about it. A Z80 based micro with a built in Forth interpreter, what more could I desire? Only about 9000 machines were manufactured and I've been waiting patiently ever since for one to come up on eBay.
  2. Sam Coupé: a Sinclair Spectrum clone with 256K memory, a 6MHz Z80, optional internal disk drives and a 25MHz Z80 processor upgrade. Somewhere in the region of 12000 units were sold. A few years ago I picked up one of these at a car boot sale for a fiver! ;-)
  3. NeXT Computer: from the moment I saw screenshots and read about this workstation built around Motorola's 68030 I knew I had to have one. After seeing the hefty price tag I knew I never would. Even now these sell for a small fortune on eBay.
  4. Dragon 64: the Dragon's 6809 processor looked amazing compared to the 6502 used in most computers of the time. It boasted two stacks, plenty of registers and on chip multiplication. Whenever I wrote code for the 6502 I'd secretly hope to write for the 6809 one day.
  5. KITT: a sentient, artificially intelligent computer built by Knight Industries and installed into a Pontiac Firebird Trans Am. Unfortunately my diecast model came without William Daniels' voice and the cool red lights. If KITT is ever on eBay I'll likely sell my house to buy it!
Let me know if you think I've missed off any cool machines :-)