How thomas-migneret/corewar works
This repository implements the Corewar virtual machine: command-line champion selection and .cor loading lead into a shared-memory, cycle-based simulation, which executes champion instructions, removes inactive processes, and reports the winner. The README also describes an assembler, but no assembler sources are present in the supplied tree; it is therefore not represented as an implemented subsystem. VM internals are partly unsampled, so documented VM relationships are cited to the README rather than inferred from filenames.
Main entry points: main.c Corewar entry · run_cycle.c Cycle scheduler · init_vm.c VM initialization · run_vm.c Simulation loop
Components 20
Inputs and loading
- CLI options
src/parcing/recup_arg.c - Champion loader
src/parcing/open_file.c - Opcode and format definitions
include/op.h
VM runtime
- Corewar entry
src/main.c - VM initialization
src/vm/init_vm.c - Champion placement
src/vm/load_champions.c - Circular arena
src/vm/memory.c - Process state
src/vm/init_processes.c - Cycle scheduler
src/vm/run_cycle.c - Simulation loop
src/vm/run_vm.c
Instruction execution
- Opcode decoding
src/vm/decode.c - Argument validation
src/vm/decode_validation.c - Instruction dispatcher
src/vm/execute_instruction.c - Instruction implementations
src/vm
Game outcomes
- Live tracking
src/vm/instruction_live.c - Process death checks
src/vm/death_checks.c - Winner announcement
src/vm/winner.c - Arena dump
src/vm/dump_arena.c
Other components
- Game launcher
- Game operator
Connections 23
- Game launcher → Corewar entry: starts game
src/main.c - Corewar entry → CLI options: parses options
src/main.c - Corewar entry → Champion loader: loads files
src/main.c - Corewar entry → VM initialization: initializes VM
src/main.c - Corewar entry → Simulation loop: runs simulation
src/main.c - CLI options → Champion loader: selects champions
- Champion loader → Opcode and format definitions: reads binary layout
src/parcing/open_file.c - VM initialization → Champion placement: places champions
- Champion placement → Circular arena: loads code
- VM initialization → Process state: creates processes
- Simulation loop → Cycle scheduler: advances cycles
- Cycle scheduler → Opcode decoding: decodes instructions
- Opcode decoding → Opcode and format definitions: uses opcode table
src/vm/decode.c - Opcode decoding → Argument validation: validates arguments
- Cycle scheduler → Instruction dispatcher: executes instruction
- Instruction dispatcher → Instruction implementations: dispatches opcode
src/vm/execute_instruction.c - Instruction implementations → Circular arena: reads and writes
- Instruction implementations → Live tracking: runs live opcode
- Cycle scheduler → Process death checks: checks survival
- Process death checks → Process state: removes inactive
- Simulation loop → Winner announcement: reports winner
- Game operator → Arena dump: requests dump
- Arena dump → Circular arena: prints arena state