Hello,
I decided to give the health scanner one more try so I started from scratch
to copy two instances to a location with good offsets and spawn programs
etc... (copy program from scratch rest of the program copy pasted into it

and modified just a little bit.)
So now it's kinda working as it should, I simply patched up the offsets and
euhm... only thing missing is the dead/alive status thing... so once a copy
goes dead it can't be revived by the other.
Still interesting to see the code in action... it's not so great at
surviving... threads keeping hanging in the trap or are killed off...
There is code present to spawn new threads... but it doesn't seem very
effective or anything... they just keeping dieing again.
Still failures can be interesting as well, so that's why I am posting it
Maybe some other scanning concept might work better
( code follows below )
Bye,
Skybuck.
;redcode
;name HealthRepairV4
;author SkybuckFlying
;strategy repairs itself
;version 4
;date 20 december 2007
;
; Let's try the health scanner again, but this time start from the start,
first copy two instances
; somewhere, then spawn enough threads to start them both, yeah, don't let
them spawn each other or so
; just fix and maybe add a little respawner.
;
;
;
;
; It works but it needs to respawn it's killed of threads than maybe it
could survive, do that in a next version.
; Ok that's now fixed.
;
; Only problem that remains is reviving the dead copy that was restored. At
least against core bombers/core clear.
; It should be able to survive random/nasty bombers...
; Nope it doesn't even survive that... threads just keeping hanging in the
trap, or die off or something
; maybe the concept is just flawed or needs to be different.
;
; Even survivor v8 or so is better at surviving
; Hmm not true... even survivor v8 dies pretty fast
; maybe the trick is to complete a full loop of instructions and only then
figure out if something is dead or not... might be better
; than you known if the copy is intact or dead...
; but that's difficult because you can't execute the healing code... so you
won't know... you probably have to scan to be sure if it's intact or not
;
; Another problem is it only detects disease spl $0, $0 and dat $0, $0.
;
; For example disease dat #0 is not detected
;
; Code is messy and uses patched-up offsets... just testing out the concept
;
;
; copy one instance to location 2000
; copy second instances to location 5000
; makes it easy to set offsets later
CopyBegin
; mov.ab #3000-19, HealthScannerScanPosition
; mov.ab #-20, HealthScannerOwnPosition
mov.ab #3000-(19+12), HealthScannerScanPosition
mov.ab #-20-12, HealthScannerOwnPosition
mov.ab #(2000 - SourceDest)-2, SourceDest
CopyReCopy
mov.a #InstanceBegin - SourceDest, SourceDest
mov.ab #InstanceLength, CopyRepeat
Copy mov }SourceDest, >SourceDest
CopyRepeat djn Copy, #0
mov.ab #(5000 - SourceDest)-7, SourceDest
; mov.ab #-3000-19, HealthScannerScanPosition
; mov.ab #-20, HealthScannerOwnPosition
mov.ab #-3000-(19+12), HealthScannerScanPosition
mov.ab #-20-12, HealthScannerOwnPosition
CopyAgain djn CopyReCopy, #2
SourceDest nop $0, $0
; if you disable any instruction make sure to replace with nop's otherwise
offsets wrong
spl SpawnProgram2Begin ; maybe not really necessary but this gets it up
running faster
spl SpawnProgram1Begin
; nop 1
; nop 1
djn 0, #5 ; wait a bit
mov.ab #1, Activate ;activate
; djn 0, #2 ; wait another little bit, no need to wait it seems
nop 0
spl 2000-17 ; spawn thread checker
spl 5000-18 ; spawn thread checker
Activate dat $0, $0
SpawnProgram1Begin
processes1 equ 37 ; works for 1 to 512, should be adequate!
for 9+0* (a=512)
for ((processes1-1)/(a=a/2))%2==1 && processes1>a
spl 1
rof
for ((processes1-1)/a)%2==0 && processes1>a
mov.i -1,#0
rof
rof
SpawnProgram1End
jmz 0, Activate
Jump1 jmp 2000 - 15; ok let's start them at the trap then they will be
released by thread releasor.. hopefully, bit dangerous if they dont get
released but ok

, they gonna get trapped anyway sooner or later
SpawnProgram2Begin
processes2 equ 37 ; works for 1 to 512, should be adequate!
for 9+0* (a=512)
for ((processes2-1)/(a=a/2))%2==1 && processes2>a
spl 1
rof
for ((processes2-1)/a)%2==0 && processes2>a
mov.i -1,#0
rof
rof
SpawnProgram2End
jmz 0, Activate
Jump2 jmp 5000 - 23; should start at HealthScannerScanForStunDisease
CopyEnd
InstanceLength equ InstanceEnd - InstanceBegin
InstanceBegin
; rough estimate for now... some jumps jump over instructions so the real
ammount of cycles is lower
; might fine tune this later when done coding.
HealthScannerScanCycles equ 13 ; 13 more accurate
(HealthScannerScanEnd - HealthScannerScanBegin) ; rough estimate.
HealthScannerScanInstances equ InstanceLength
; for now don't scan the thread checker
;HealthScannerScanInstances equ HealthScannerScanEnd -
HealthScannerScanBegin
; spl HealthScannerCheckThreadCountBegin
WarriorMainLoopBegin
HealthScannerCheckThreadCountBegin
; trap any living threads
mov.a $0, HealthScannerTrap
; reset waiting time
mov.ab #HealthScannerScanCycles, HealthScannerWaitForTrap
; wait a while till they trapped
; they waiting time should equal the ammount of instructions the threads
have to execute to recycle a full loop cycle.
HealthScannerWaitForTrap djn HealthScannerWaitForTrap, #0
; reset threads to spawn
mov.ab #HealthScannerScanInstances, HealthScannerCalculateThreadsToSpawn
; see how many are trapped
; subtract trapped count from max instances
HealthScannerCalculateThreadsToSpawn sub HealthScannerTrappedThreadCount,
#0
; if no threads to spawn then jump to release threads
; or alternatively jump to check if remote checker thread is alive... if
not spawn one... nice !
jmz HealthScannerCreateMissingThreadsDone,
HealthScannerCalculateThreadsToSpawn
; one is not handled for now hope for the best
; create the missing threads
; let's use something simpel for now
; just spawn one thread for now
spl HealthScannerSpinnerBegin
; jmp FastThreadSpawnerBegin
HealthScannerCreateMissingThreadsDone
HealthScannerCheckThreadCountReleaseThreads
; reset trap count
mov #0, HealthScannerTrappedThreadCount
; release thread by modifieng the trap
mov.a #(HealthScannerSpinnerEnd-HealthScannerTrap), HealthScannerTrap
; jump back to thread checker
jmp HealthScannerCheckThreadCountBegin
HealthScannerCheckThreadCountEnd
HealthScannerScanBegin
HealthScannerSpinnerBegin
; prevent the threads from going for, this instruction can be used to trap
to threads and release them again by change the jump etc.
; can be used to synchronize threads
add #1, HealthScannerTrappedThreadCount
HealthScannerTrap jmp $0, $0
HealthScannerSpinnerEnd
; algorithm will be:
; scan for bad instruction
; if bad instruction found jump to cure, otherwise skip and do next line
; scan for next bad instruction
; if bad instruction found jump to cure, otherwise skip and do next line
; repeat scan etc.
HealthScannerScanForStunDisease
; we must not forget it has to be conccurent so increment scan position
for next thread to scan next cell.
; each thread will heal one cell only
; scan for bad instruction
sne HealthScannerStunDisease, >HealthScannerScanPosition
jmp HealthScannerCureStunDisease, <HealthScannerScanPosition; each jump
has to decrement the scan position to make it usefull and keep it as it was
nop $0, <HealthScannerScanPosition
HealthScannerStunDiseaseNotPresent
nop $0, >HealthScannerScanPosition
nop $0, <HealthScannerScanPosition
jmp HealthScannerStunDiseaseCured
HealthScannerCureStunDisease
; do something to the infected cell, make sure to increment scan position
for next thread
; let's bomb the infected cell which contains spl 0, 0 it will be
overwritten with dat $0, $0 to kill off spinning instances.
; only problem is if other warrior has it's own spl 0, 0 instruction
which will be killed and later restored
; warriors could therefore destroy each other's stun instruction so be
carefull with that and check it out what happens later on
mov HealthScannerBomb, >HealthScannerScanPosition; mov
HealthScannerDebug, >HealthScannerScanPosition
nop $0, <HealthScannerScanPosition
jmp HealthScannerStunDiseaseCured
HealthScannerStunDiseaseCured
; place additional scans here etc.
HealthScannerScanForBombDisease
; we must not forget it has to be conccurent so increment scan position
for next thread to scan next cell.
; each thread will heal one cell only
; scan for bad instruction
sne HealthScannerBombDisease, >HealthScannerScanPosition
jmp HealthScannerCureBombDisease, <HealthScannerScanPosition; each jump
has to decrement the scan position to make it usefull and keep it as it was
nop $0, <HealthScannerScanPosition
HealthScannerBombDiseaseNotPresent
nop $>HealthScannerOwnPosition, >HealthScannerScanPosition
nop <HealthScannerOwnPosition, <HealthScannerScanPosition
jmp HealthScannerBombDiseaseCured
HealthScannerCureBombDisease
; do something to the infected cell, make sure to increment scan position
for next thread
; let's copy our own instruction to the other warrior, assuming our copy
is still good
mov >HealthScannerOwnPosition, >HealthScannerScanPosition; mov
HealthScannerDebug, >HealthScannerScanPosition
nop <HealthScannerOwnPosition, <HealthScannerScanPosition
jmp HealthScannerBombDiseaseCured
HealthScannerBombDiseaseCured
; place additional scans here etc.
; repeat scan
jmp HealthScannerScanBegin
HealthScannerScanEnd
HealthScannerData
HealthScannerScanPosition dat $0, #0
HealthScannerOwnPosition dat $0, #0
HealthScannerBomb dat $0, $0
HealthScannerTrappedThreadCount dat $0, #0
HealthScannerDiseases
HealthScannerStunDisease spl $0, $0
HealthScannerBombDisease dat $0, $0
; HealthScannerDebug dat $666, $666
InstanceEnd
dat $777, $777