;redcode
;name StrategySwitcherV2
;author Skybuck Flying
;strategy demonstration code to switch strategies based on previous result
;strategy or if p-space is not present just cycle through strategies
;strategy for now assume p-space is available.
;comments idea is to simply use a counter somewhere in p-space to keep track
of last used
;strategy, at start read if we won, tied or lost, if lost then switch to
next strategy.
;so let's say we have 5 strategies (like recycledbits) then simply use a
thread kind of jumper
;to jump to the correct strategy, we could simply start executing there or
possibly copy the thing
;to somewhere in the core to prevent scanners from finding as too soon
also clear out the jumps
; best would be to copy to somewhere in the core, so let's do that. (Not yet
implemented

)
; strategies start at zero to n-1.
StrategyPSpaceLocation equ 10
Strategies equ 4
; load previous round results
PreviousRoundResult ldp.ab #0, $0
; load strategy value since we have to execute it possibly.
LoadStrategyValue ldp.a #StrategyPSpaceLocation, $StrategyValue
; if previous round result is zero (=lost) then skip over jump to strategy
table so that first
; the strategy is changed/incremented.
; if it is not zero then don't skip the jump, and thus jump to strategy
table.
seq.ab $0, $PreviousRoundResult
jmp.a $StrategyTable
; increment the strategy value
add.a #1, $StrategyValue
; mod the strategy value to max strategies
mod.a #Strategies, $StrategyValue
; store the strategy value back into space
stp.ab $StrategyValue, #StrategyPSpaceLocation
StrategyTable
add.a #1, $StrategyValue
StrategyValue
jmp.a $0, $0
StrategyJumps
jmp.a Strategy0
jmp.a Strategy1
jmp.a Strategy2
jmp.a Strategy3
Strategy0
dat $0000, $0000
Strategy1
dat $1111, $1111
Strategy2
dat $2222, $2222
Strategy3
dat $3333, $3333