;redcode-94 ;name Alladin's Cave ;author P.Kline ;assert CORESIZE == 8000 ;strategy pswitch stone, CLP, one-shot dclear, and one-shot spl/dat wiper slStone mov clGate djn.f -1 ,>clGate jmp -3 dat {5335,12 clBomb dat {5335,12 dat 0,0 Sweep add #2671 ,#2681 ;one-shot scan jmz.f Sweep ,@Sweep ;with spl-dat wipe jmp @6 ,Sweep mov @1 ,>Sweep djn.b -2 ,{swWipe jmp swWipe ,swWipe PSTATE EQU 110 STATES EQU (loss_table-win_table) dat 0,init_table-state in dat 0,loss_table-state dat 0,win_table-state dat 0,tie_table-state think ldp.a #0,in ; get input value load ldp.a #PSTATE,state ; load old state mod.a #STATES,state ; brainwash protection add.ba *in,state ; select correct state table store stp.a *state,load ; store new state mov 0,-1 ; eliminate accidental stp's ; p-table managing four options plus bw ; note that any number of brainwash vals ; could be put in between valid values ; ; loss-table is designed to speed up ; search for best routine by skipping ; one or more trials of each program w0 EQU slClear w1 EQU slSweep w2 EQU slStone w3 EQU slDodger state jmp @0 ,w1 tie_table win_table spl #wx0-win_table,w0 ; Brainwash (zero should not happen!) ww1 spl #ww1-win_table,w1 ; Sweep wx1 spl #ww1-win_table,w1 spl #ww1-win_table,w1 ww0 spl #ww0-win_table,w0 ; Clear wx0 spl #ww0-win_table,w0 spl #ww0-win_table,w0 ww2 spl #ww2-win_table,w2 ; Stone spl #ww2-win_table,w2 spl #ww2-win_table,w2 ww3 spl #ww3-win_table,w3 ; Dodger spl #ww3-win_table,w3 spl #ww3-win_table,w3 loss_table spl #wx0-win_table ,w0 ; Brainwash spl #1-loss_table ,w1 ; Sweep spl #1-loss_table ,w1 spl #2-loss_table ,w0 spl #1-loss_table ,w0 ; Clear spl #1-loss_table ,w0 spl #3-loss_table ,w2 spl #1-loss_table ,w2 ; Stone spl #1-loss_table ,w2 spl #wx1-win_table ,w1 spl #1-loss_table ,w3 ; Dodger (never selected after first trial) init_table spl #1-loss_table ,w3 spl #wx1-win_table ,w1 slDodger mov p1-pstep pmove add preset ,psnare ; adjust snare for new base mov pb ,pescape ; set copy pointers pcopy mov >pescape ,}pescape ; make copy jmn.b -1 ,pescape ; preset jmp p1+pstep ,-p1-pstep; jump to new location psnare jmp ptrap-2000,+2000 ptrap mod.x #10 ,#1 ; allow only one process stp.ab #0 ,#0 ; complete brainwash djn.b -1 ,-1 pincr mov 1 ,-1 ; opponent dies pb dat pstep+p1-pescape,-plen end think