P-Space
P-space is the latest addition to Redcode, introduced by pMARS 0.8. The "P" stands for private, permanent,
personal, pathetic and so on, whichever you like. Basically, the P-space is an area of memory which only your
program can access, and which survives between rounds in a multi-round match.
The P-space is in many ways different from the normal core. First of all, each P-space location can only store
one number, not a whole instruction. Also, the addressing in P-space is absolute, ie. the P-space address 1 is
always 1 regardless of where in the core the instruction containing it is. And last but not least, the P-space
can only be accessed by two special instructions, LDP and STP.
The syntax of these two instructions is a bit unusual. The STP, for example has an ordinary value in the core as
its source, which is put into the P-space field pointed to by the destination. So the P-space location isn't
determined by the destination address, but by its value, ie. the value that would be overwritten if this were
a MOV.
So STP.AB #4, #5 for example would put the value 4 into the P-space field 5. Similarly,
STP.B 2, 3
...
DAT #0, #10
DAT #0, #7
would put the value 10 into the P-space field 7, not 3! This can get pretty confusing if the STP itself uses
indirect addressing, which leads into a sort of "double-indirect" addressing system.
LDP works the same way, except that now the source is a P-space field and the destination a core instruction.
The P-space location 0 is a special read-only location. Any writes to it will be ignored, and it is initialised
to a special value before each round. This value is -1 for the first round, 0 the program died in the previous
round, and otherwise the number of surviving programs. This means that, for one-on-one matches, 0 means a loss,
1 a win and 2 a tie.
The size of the P-space is usually smaller than that of the core, typically 1/16 of the core size. The addresses
in the P-space wrap around just like in the core. The size of the P-space must naturally be a factor of the core
size, or something weird will happen.
There is one little peculiarity in the pMARS implementation of P-space. Since the intention was to keep access
to P-space slow, loading or saving two P-space fields with one instruction isn't allowed. This is a Good Thing,
but the result is at the very least a kludge. What this actually means is that LDP.F, .X and .I all work like
LDP.B! (and the same for STP too, of course)
Absolutely the most common use of P-space is to use it to select a strategy. In its simplest form, this means
saving the previous strategy in P-space, and switching strategies if the P-space field 0 shows the program lost
last time. This kind of programs are called P-warriors, P-switchers or P-brains. (pronounced pea-brains)
Unfortunately, the P-space isn't as private as it seems. While your opponent can't read or write your P-space
directly, your processes may be captured and made execute your opponents code, including STPs. This kind of
technique is known as brainwashing, and all P-switchers must be prepared for it, and not freak out if the
strategy field contains something weird.
|