Core war - addition

Another intelligent and certainly original program is Mirror. This keeps a
second copy of itself and compares itself with the other copy. Once it
discovers a difference it repairs the second copy (it always assumes the
running copy is correct) and then transfers execution to this one:

   10 REM Mirror
   20 from=start-1
   30 to=start-2
   40 .start
   50 MOV #-280 to
   60 MOV #24 from
   70 .copy_loop
   80 MOV (from) (to)
   90 SUB #1 to
  100 DJZ from compare_start
  110 JMP copy_loop
  120 .compare_start
  130 MOV #0 from
  140 MOV #-280-24 to
  150 .compare_loop
  160 CMP from #24
  170 JMP compare_start
  180 ADD #1 from
  190 ADD #1 to
  200 CMP (from) (to)
  210 JMP compare_loop
  220 .repair_start
  230 MOV #1 from
  240 MOV #-280-23 to
  250 .repair_loop
  260 CMP (from) (to)
  270 JMP over
  280 MOV (from) (to)
  290 .over
  300 ADD #1 from
  310 ADD #1 to
  320 CMP from #25
  330 JMP to-280-23
  340 JMP repair_loop
  350 END

Lines 40 to 120 make a copy of Mirror 280 locations in front of the
executing copy. Then lines 120 to 210 compare the running program to its
clone. Once a difference is discovered, lines 220 to 340 repair the faulty
instructions and control is transferred to the clone in line 330. This
then makes another copy of itself and then starts checking again.

If you can follow how Mirror works, you will see it is inefficient at some
places. Still it is a nice example of a self-repairing program and in the
competition it comes out third after Bat and Monkey.

The fun of Core War is that there is always a better program possible. A
few pages ago you might have thought that small agressive programs had the
future. But also Bat and Mirror are not the end-stage. (Did you, for
example, note they are only protected against attcks from one side.)

I have written a program called Che that could be described as an
agressive combination of Pyramus and Dwarf. It follows a guerilla-tactic:
it shows up somewhere, bombs a few locations and then disappears again.
Bat and Mirror don't have a chance against it. Also static programs that
are more intelligent than Dwarf and Monkey have good chances against Bat
and Mirror. But there are again programs that will defeat these latter
ones... It is the never-ending story of Core War.

As you can see, Che works is quite a simple program. Lines 50 to 100 are
almost the same as Dwarf/Monkey. And lines 110 to 210 arevery similar to
Pyramus, with the difference that the program doesn't initially copy
itself 60 locations ahead, but 450 locations.

   10 REM Che
   20 target=start-1
   30 .start
   40 MOV #9 target
   50 .bomb_loop
   60 ADD #6 target
   70 MOV #0 (target)
   80 CMP target #117
   90 JMP copy_loop
  100 JMP bomb_loop
  110 .copy_loop
  120 MOV (from) (to)
  130 SUB #1 from
  140 CMP from #-14
  150 JMP (to)
  160 SUB #1 to
  170 JMP copy_loop
  180 .to
  190 DAT #450
  200 .from
  210 DAT #0
  220 END

In the competition, Che appears to be very effective and comes out on top:

            | Bo | D  | H  | I  | P  | S  | M  | Ba | C  | Total | Rank  |
Booby       | XX |  8 |  6 | 18 |  7 | 16 |  0 |  5 |  1 |  61   |  7    |
Dwarf       | 12 | XX | 12 | 17 |  0 | 20 | 16 |  0 |  4 |  81   |  4    |
Hopper      | 14 |  8 | XX | 15 | 16 |  8 |  1 |  7 |  0 |  69   |  6    |
Imp         |  2 |  3 |  5 | XX |  5 |  4 |  5 |  5 |  5 |  34   |  9    |
Pyramus     | 13 | 20 |  4 | 15 | XX |  8 |  4 | 10 |  0 |  74   |  5    |
Slider      |  4 |  0 | 12 | 16 | 12 | XX |  0 |  1 |  4 |  49   |  8    |
Monkey      | 20 |  4 | 19 | 15 | 16 | 20 | XX |  6 |  4 | 104   |  3    |
Bat         | 15 | 20 | 13 | 15 | 10 | 19 | 14 | XX |  4 | 110   |  2    |
Che         | 19 | 16 | 20 | 15 | 16 | 16 | 16 | 20 | XX | 138   |  1    |
                                                           720

Finally I ask attention for an original program. It doesn't have a chance
in a competition, but that's not I wrote it for. It was designed to win
battles against Monkey in a very original way: by making Monkey commit
suicide.

The listing of this program, called Zombie, follows:

   10 REM Zombie
   20 to=start-1
   30 .start
   40 MOV #-293 to
   50 .bar_loop
   60 MOV #1 (to)
   70 SUB #1 to
   80 CMP to #-301
   90 JMP check_start
  100 JMP bar_loop
  110 .check_start
  120 MOV #-292 to
  130 .check_loop
  140 CMP to #-300
  150 JMP check_start
  160 SUB #1 to
  170 CMP (to) #1
  180 JMP check_loop
  190 SUB #121 to
  200 .bomb_loop
  210 MOV #-10 (to)
  220 SUB #8 to
  230 JMP bomb_loop
  240 END

Zombie starts almost like Bat. It constructs a picket filled with "1"'s,
300 locations in front of itself. Just like Bat it then continues checking
this picket. If it has found a difference it interprets this as a bomb
(coconut) thrown by Monkey. Then it begins bombing locations, starting in
front of the picket, working its way back towards Monkey (lines 210-230).
Just like Monkey throws its "0"-bombs at locations 8 after the previous
one, Zombie now throws "-10" bombs at locations 8 in front of the previous
one. The value of 121 (found by trial and error) subtracted from the
contents of "to" ensures that one of the "-10"-bombs will fall on the DAT
location of Monkey, changing this into DAT -10.

The listing of Monkey:

   ADD #8 target
   MOV #0 (target)
   JMP -2
   .target
   DAT #-7

If the DAT instruction is changed in DAT -10, you can see what happens.
The ADD #8 target instruction changes the DAT -10 into DAT -2, after which
MOV #0 (target) is executed. -2 counted back from the DAT instruction
gives the location of the MOV instruction. So this bombs itself! The next
time it is executed, Monkey is declared the loser. Tests show that Zombie
wins in this way in 88% of all battles!