Playing Core War - The Programming Game
So I'm trying to start playing Core War, which is a programming game where two or more programs written in a special assembly language battle against each other to kill the other program in the memory of a virtual computer. I decided to document how to start playing, after I had trouble just installing the simulator.
I found this website, where I downloaded the source code for the simulator, a.k.a MARS (Memory Array Redcode Simulator). The one that I used in this tutorial is called pmars (portable MARS).
It seems like there are download links for windows users, so that you don't have to compile anything like I did, but there also seems to be different simulators that have more features and are (maybe?) easier to use.
The following instructions worked on my mac, but I'm not so sure if they would work on Linux or Windows. If you manage to get it working on either of those, lmk and I'll try to add it.
Instructions for mac (& maybe? linux):
(BTW, whenever things are in quotes, please ignore them)
I downloaded pmars version 0.9.4 from here.
On macOS, I had to download XQuartz, for the UI of the simulator to start.
I used GCC to compile the program, so install homebrew, and run "brew install gcc make" inside your terminal to install both GCC & Make.
Once unzipped, I read the README file (might be helpful)
Open the file called Makefile within the src directory, and edit the line that starts with "CFLAGS" so that it becomes "CFLAGS = -O -DEXT94 -DXWINGRAPHX -DPERMUTATE -DRWLIMIT -I/usr/X11/include/"
Also change the line at the top from "CC = gcc" to "CC = gcc-12" only if on macOS
First try to compile by running "make" within the "src" directory. If it works, great! If not, try the following after running "make clean".
edit the file "sim.c" and find the line that contains "sighandler"
Change "sighandler(0);" to "sigaction(0);"
Try to run "make" again within the "src" directory
For me, that was how I compiled the program. This may or may not work on M1 and M2 macs, as I don't have access to one. Once compiled, you can move the file called pmars to an easily accesible directory (Ex. Create a directory called "bin" in your home folder and put it there). Make sure to put the "warriors" directory somewhere you could find it easily (such as your "Documents" folder)
To run a game (for mac), first open the XQuartz application.
Change directory to the folder where the program is stored and run:
"./pmars PATH_TO_FIRST_WARRIOR PATH_TO_SECOND_WARRIOR"
An example would be: "./pmars ~/Documents/warriors/aeka.red ~/Documents/warriors/rave.red"
A window should pop up containing the memory contents of the Virtual Machine!
Voila! Your very own MARS simulator!
Some resources for creating your own programs to battle:
A Core War Website
Strategy Guide
Wikipedia Article
Tutorial that I found that explains things really well
Hope this works, and Happy Programming! :D