Corewar

Full Version: super beginner
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
... as in I started reading on corewar yesterday

Information is pretty scarce. Plenty of endless definitions of redcode programming followed by examples but not much on how things work.

So I'm not quite following how Imp works (ref: above status of super beginner)

I follow Dwarf completely. The last executed line redirects the execution pointer to the beginning.

But Imp doesn't have anything like that. It is a one line program that just ends.

When Imp's one line has been executed, why does the MARS then execute the code located one location after the end of the program? Imp made a copy of itself there but I don't see why the MARS thinks it now needs to go there and execute it.

The one liner of "JMP 0" is obvious in it's manipulation of the execution pointer.

But Imp doesn't give any sort of instruction to the execution pointer; it just copies a the contents of one memory location to another and that's it.

Unless I can see why the MARS is compelled to move the execution pointer to a space immediately following a program's end (with no request/direction from the program itself to do this) I think I'm missing something fundamental about what happens during battle.

I couldn't find anything here:

https://users.obs.carnegiescience.edu/birk/COREWAR/DOCS/guide2red.txt

... which is not to say the answer isn't indeed there... I just couldn't see it Smile

Any insights appreciated! Warning: attempting to help me will almost assuredly lead to more questions.
Hi, stillsmallvoice, I noticed your post while perusing this forum, and after observing that it had received no reply, I decided to create an account and hopefully resolve some of your questions. I must confess, I am not immensely familiar with Corewar myself, and haven't yet written any particularly successful programs, but I've been reading on it for a few months, and consider myself adequately familiarized with the basics.

It seems as though the main confusion you possessed regarded the behavior of the instruction pointer. You understand that that the JMP command in Dwarf moves the instruction pointer back to Dwarf's first instruction, resulting in it looping through its instructions ad infinitum, but were unclear when it came to Imp, where no instruction pointer actions were explicitly set out.

First, it's important to understand that the instruction pointer acts not on the code itself, but on the instructions the code is compiled into. It's not that the instruction pointer traverses the lines of the program. Instead, it moves through a list of instructions, which the program serves to encode. This may sound abstract, but really it is the essence of CoreWar: simulated memory addresses holding instructions which are executed, one at a time, by instruction pointers for each of the programs. It's illuminating, if not essential, to see this in action, with a simulator such as CoreWin for Windows at http://corewar.co.uk/wendell/ .

So what, in the absence of JMP, SPL, and their derivative commands, is the default behavior of the instruction pointer? It simply moves forward, one instruction at a time, executing each in turn. Imp is designed with this in mind: it copies the MOV 0, 1 command one instruction forward, the instruction pointer moves one ahead, executes the MOV 0, 1 instruction just placed there, moving it one ahead, and so on, always moving it to the location it will next execute. A Redcode program is merely a set of instructions, and there is no obligation to stay within the confines of the original code.

I hope that this clarified to some extent your uncertainty, and if not, reply with any questions you have. If you still find CoreWar interesting, I'd recommend beginning with this excellent tutorial: http://vyznev.net/corewar/guide.html . It really helped me get started. If you're interested in my listing other useful resources I've come across, please mention that in your reply.