Core War is a 1984 programming game in which two or more fighting programs compete for control of a virtual computer.
The goal of this project was to create:
- A Champion (fighting program), written in assembly.
- An Assembler - asm, which compiles the champion assembly into bytecode.
- A Virtual Machine - corewar, the battle arena where champions fight to the death.
See the subject for more details.
Final Score 125/100
First clone this repo to your machine.
git clone https://github.com/dfinnis/Corewar.git; cd Corewar
Make the binaries asm and corewar.
make
Run the virtual machine with 2-4 assembled champions as argument. You'll find some assembled champions in champions/compiled/.
./corewar champions/the_best_player_around_the_whole_universe.cor champions/compiled/zork.cor
Our champion (the_best_player_around_the_whole_universe) beat Zork, great!
The game ends when cycle_to_die reaches 0, or when all processes are dead. The last to have been reported alive wins.
Some strategies:
- Aim to execute live last.
- fork to create more processes who work for you.
- Overwrite enemy bytecode, evicerating or enslaving them.
Champions battle to the death in the circular virtual memory arena.
- -v [speed (1-100)], plays the game start to end without -w or -dump.
- -cp, color process pointers according to which champion is parent.
- -w nbr_cycles, wait nbr_cycles before starting vizualizer.
- -dump nbr_cycles, dump virtual machine state nbr_cycles into game. In combination with -w a specific period of the game can be viewed.
We can view just the crucial moment in the game where our champion overwrites zork, after which zork calls live for our champion.
./corewar champions/the_best_player_around_the_whole_universe.cor champions/compiled/zork.cor -v -cp -w 2150 -dump 2400
Visualizer built with ft_printf.
- -a, don't print alive operations (as prescribed by the subject). Much cleaner output.
- -e, print cycle_count at end (how long the game is).
./corewar champions/the_best_player_around_the_whole_universe.cor champions/compiled/zork.cor -a -e
- -op, print operations excecuted & argument sizes.
- -arg, print values extracted from the coding byte.
Our champion (the_best_player_around_the_whole_universe) was written to beat zork.
Our champion calls alive, forks itself and overwrites zork's id number with our champions id number. Zombie zork now calls alive for our champion, zork is defeated.
Above is the .s assembly, below is the .cor assembled bytecode.
Run the assembler with one or more champion.s files as argument. The assembler assembles .s assembly to .cor bytecode, ready to be loaded into the VM. You'll find some champion.s files in champions/uncompiled/.
./asm champions/the_best_player_around_the_whole_universe.s
If the .s file is invalid, asm displays detailed error messages specifying line and column number in the assembly file.
- -o , specify destination folder (default same as sourcefile).
- -c, remove filesize limit.
Let's see a later stage of a game with 4 players.
./corewar champions/compiled/Car.cor champions/compiled/Misaka_Mikoto.cor champions/compiled/Kittystrophic.cor champions/compiled/Octobre_Rouge_V4.2.cor -v -cp -w 10000
@svaskeli & I created the Virtual Machine.
@erli & @pmasson created the Assembler.