Corewar
A virtual machine in C where small programs fight inside a shared memory, with my own warrior and a 3D viewer in the bonus.
- Period
- Apr 2025 – May 2025
- Role
- The virtual machine and a champion program
- Team
- 2 people
- Status
- archived
Stack and tags
Demo
Transcript (final screen)
demo:corewar$ ls *.cor lucien.cor quentin.cor demo:corewar$ ./corewar lucien.cor quentin.cor | tail -4 The player 2(Quentin) is alive. The player 2(Quentin) is alive. The player 2(Quentin) is alive. The player 2(Quentin) has won. demo:corewar$ ./corewar -dump 400 lucien.cor quentin.cor | grep -v alive | head -6 | cut -c1-80 00000000 02 90 00 00 00 41 01 02 90 00 00 00 00 02 00 00 00 41 00 02 0 -------- 00000c00 0b 68 01 00 1f 00 01 0c 00 18 02 90 00 00 00 4c 01 02 90 00 0 00000c30 00 00 00 41 08 03 70 08 00 64 04 54 06 07 07 0b 54 07 07 01 0 The player 2(Quentin) has won. demo:corewar$
Corewar is a programming game from the 1980s. Small programs, the champions, are loaded into the same circular block of memory and run in turns by a virtual machine. They can rewrite memory, including each other’s, and copy themselves. The last one still proving it is alive wins.
How it works
Champions are written in a tiny assembly language and compiled to bytes; the virtual machine reads those bytes and runs them, all sixteen instructions of them. Memory wraps around like a ring, so running off the end starts again at the beginning. A dump option stops a match at any moment and prints the whole memory, so a run can be compared byte by byte with the reference. I also wrote a champion of my own, ChampLucien, and the team added a 3D viewer to watch the fight.
What I took from it
- With a virtual machine, tiny details (byte order, wrap-around, a jump off by one) decide whether anything works, so comparing dumps earned its keep.
- Building the machine taught me to read machine code the way a processor does.
Built with
- Quentin Taranne-Payet@Quentin-taranneNo bio yet.GitHub