Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

343 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Corewar

Epitech project — 2023 (1st year) Made by Louis Rollet, Guillaume Tran, Théodore Billotte and Marton Roux.

Corewar is a game in which several assembly programs, called champions, fight inside the shared memory of a virtual machine. Each champion is a process running its own bytecode; the last champion still able to signal that it is alive — by executing the live instruction — wins the round.

The project is split in two parts:

  • an assembler (asm) that compiles a champion written in the Corewar assembly language (.s) into executable bytecode (.cor);
  • the virtual machine (corewar) that loads the champions into a circular shared-memory arena and runs them concurrently until a winner emerges.

Building

A single make at the root of the repository builds everything (the asm and corewar binaries and the internal list library):

make        # build asm and corewar
make re     # rebuild from scratch
make clean  # remove object files
make fclean # remove object files and binaries

Usage

1. Assemble a champion

Compile a champion's source into a .cor file:

./asm champion.s     # produces champion.cor

2. Run the arena

Load one to four champions into the virtual machine:

./corewar champion.cor [champion2.cor ...]

Available flags:

Flag Description
-n <id> Set the number of the champion that follows.
-a <addr> Set the load address of the champion that follows.
-dump <n> Dump the memory in hexadecimal after n cycles, then stop.
-d Enable the live graphical visualizer (bonus, see below).
-h Display the help message.

Example:

./corewar -n 1 -a 100 champion.cor -dump 0B champion2.cor

A champion wins when it is the last one alive — i.e. the last process to have executed the live instruction. A champion loses once it has no running process left, or once its processes stop declaring themselves alive.

Bonus — Visualizer

Running the VM with the -d flag opens a graphical visualizer that shows the memory arena and the champions fighting over it in real time:

./corewar -d champion.cor champion.cor

Visualizer

Tests

Unit tests (Criterion) can be run with:

make tests_run

About

Corewar — a virtual machine and its assembler in C, where champion programs battle in shared memory. Epitech 1st-year team project.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages