by January 1, 2000 0 comments

Core Wars is a programming game in which players write programs that fight to death in a virtual “ring”.

When I encourage the average newbie to take up this game, he usually declines, and quite naturally so. Most newbies wouldn’t consider optimizing assembly code as fun. For people who do become interested, there’s another factor that leads to the high starting threshold. It’s painfully difficult to formulate a comprehensive tutorial that starts from scratch and gets you up and playing the game without prior knowledge of some assembly language, programming experience, and what not. The aim of this series is to get you started with playing Core Wars, assuming that this article is your first contact with it and that you’re nowhere near being a hardcore programmer. Let’s begin by answering a few basic questions.

What is Core Wars
and how did it start?
Core Wars is a programming game in which programs battle against each other in the memory of a simulated computer. It was first played in Bell Labs in the 1960s on computers such as the PDP-1, amongst the likes of Dennis Ritchie and John Morris Sr. Core Wars was globally popularized in the mid 1980s, when A K Dewdney, now known as the father of the game, wrote a series of articles for the Scientific American, describing Core Wars and its possibilities. 

Why should I take it up?
Core Wars is a game of attitudes. Programming is no longer
the bland experience it used to be. Here, your code reflects everything
from your mood to your imaginativeness. Core Wars fanatics see their
warriors as real, living characters. “Dwarf” for example, is a tiny
warrior who sits in one place and throws bombs all over the core, wiping
out any one it hits. “Sucker” is a vampire who draws its adversaries
into a slave pit, makes them work until they run out of energy, and
finally kills them. There are some serious advantages of playing the
game too. As David Moore says in his paper “Thoughts on Core Wars”:

  • Programming in Redcode Assembly slashes the learning curve for all assembly languages exponentially.

  • Playing Core Wars implicitly builds up your logic, promotes problem solving, and blooms your programming skills.

  • Hardcore Core Wars enthusiasts often write supplementary C code to optimize their warriors.

  • Core Wars genetics: People have written genetic algorithms to evolve warriors. Core Wars is the ideal platform to start genetic programming.

  • Core Wars math: Core Wars can involve a lot of math. An “n” step bombing pattern in a core of size “c” models Euclid’s algorithm to find gcd
    (c,n). There are thousands of techniques you can extend your math to.

  • Hill dynamics: Core Wars provides many generalizations of Prisoners’ Dilemma.

Can I play Core Wars
on my PC?
There are abundant simulators available for Core Wars for DOS, Unix, and Windows. You can find links to these from the CWSI (Core Wars Society of India) Website–www.corewars.org. You can also play it at various Websites. If you’re an Indian, you can play Core Wars on the Standard Indian Hill at the 
CWSI Website. Otherwise, the International King of the Hill tournament at www. koth.org is open to anyone. You’ll find the necessary instructions at both places. All entries are free of cost, and there are no incentives for winning or for getting on any of the hills (a collection of the top 20 Core Wars warriors in a community).


How does it work?

The system couldn’t be simpler. The core is a chunk of continuous linear
memory, which is wrapped around its ends. That is, if the size of the
core is 8,000, then one can assume memory locations to be numbered from
0 to 7,999. The 8,000th location is the same as the 0th location; the
14,699th location same as the 6,699th location (14,699-8,000), and so
on. The Core is simply a circular memory array–circular, so that no
warrior can “get out” of the core. A warrior that tries going beyond
the “last” location in the core will emerge from the first. 

An incident with similar semantics resulted
in the genesis of the infamous Internet Worm, which caused widespread
mayhem in the US in the 1980s. Robert T Morris (who was incidentally
Morris Sr’s son), conceived it while playing Core Wars on the original
“Darwin” operating system. Today, Core Wars is played in controlled
simulated environments, which rules out any possibilities of warriors
getting out of the core.

In fact, to a warrior the “first” and “last”
locations in the core are not defined, simply because there are no absolute
addresses. All addresses are relative, which means that the address
“0” refers not to the first memory location, but the current
one. The address “1” refers to the next location and the address “—1”
to the previous one. In this way, a warrior has no way of determining
its absolute position in the core.
The basic unit of memory in the core is not a byte, as one might imagine, but an instruction. An instruction consists of three parts:

  • The op-code

  • The A-field

  • The B-field

The op-code is a function, and forms the crux of the instruction. It tells the Memory Array Redcode Simulator (MARS)–the software used to play Core Wars in your computer–what to do. The A-field and the B-field are parameters on which the op-code operates. The A-field is usually the source memory location and the B-field, the destination (as contrary to most other assembly languages, Redcode assembly follows this scheme).

For example, in the instruction “MOV 0,1”, “MOV” is the op-code, “0” is the A-field and “1” the B-field. We’ll discuss its function and semantics next time. However, note that the simple instruction “MOV 0,1” is a warrior in itself. It’s the fastest moving warrior in Core Wars and rapidly clones itself to flood the entire core, if it isn’t “blocked” by another warrior. Also, anyone who steps on its footsteps becomes a clone of it. That’s a lot of juice in one line of code.

Program execution is just as simple. Once MARS places a warrior in the core, it executes its instructions one by one–starting from the first instruction of the warrior, executing the current instruction, and moving to the next one unless a JMP or CMP instruction explicitly facilitates a jump to another location.

Core Wars has been active for the past 20 years and is unquestionably here to stay. If you’re game, you can pick it up gradually by following this series, or jumpstart and get going in a day, at
www.corewars.org or any one of the hundreds of Core Wars Websites. Either way, I assure you, you won’t regret it.

No Comments so far

Jump into a conversation

No Comments Yet!

You can be the one to start a conversation.

<