User:Ais523/anticipation2.pl
Jump to navigation
Jump to search
This program generates the BF Joust program anticipation2.
# ( -*- brainfuck-joust-mode -*- )*0
my $clearlooppos = <<EOF;
((+)*65(-)*65(>{(+.)*55}<)%8)*5
((+)*65(-)*65(>{(+.)*54}<)%9)*5
((+)*65(-)*65(>{(+.)*53}<)%10)*5
((+)*65(-)*65(>{(+.)*52}<)%11)*5
((+)*65(-)*65(>{(+.)*51}<)%12)*5
((+)*65(-)*65(>{(+.)*50}<)%13)*6
((+)*65(-)*65(>{(+.)*49}<)%14)*6
((+)*65(-)*65(>{(+.)*48}<)%15)*6
((+)*65(-)*65(>{(+.)*47}<)%16)*6
((+)*65(-)*65(>{(+.)*46}<)%17)*6
((+)*65(-)*65(>{(+.)*45}<)%18)*6
((+)*65(-)*65(>{(+.)*44}<)%19)*6
((+)*65(-)*65(>{(+.)*43}<)%20)*6
((+)*65(-)*65(>{(+.)*42}<)%21)*7
((+)*65(-)*65(>{(+.)*41}<)%22)*7
((+)*65(-)*65(>{(+.)*40}<)%23)*7
((+)*65(-)*65(>{(+.)*39}<)%24)*7
((+)*65(-)*65(>{(+.)*38}<)%25)*7
((+)*65(-)*65(>{(+.)*37}<)%26)*7
((+)*65(-)*65(>{(+.)*36}<)%27)*8
((+)*65(-)*65(>{(+.)*35}<)%28)*8
((+)*65(-)*65(>{(+.)*34}<)%29)*1000
EOF
my $clearloopneg = $clearlooppos;
$clearloopneg =~ y/+-/-+/;
my $odcheck = "[" x 246;
($um1 = $_-1), $odcheck .= <<EOF for reverse (1..245, 1);
]<(+)*75<(-)*14>[[]](.)*$um1<+
$clearloopneg
EOF
my $clearloopnarrow = <<EOF . $clearlooppos;
((+)*65(-)*65(>{(+.)*57}<)%6)*5
((+)*65(-)*65(>{(+.)*56}<)%7)*5
EOF
my $prog = <<EOF;
set up tripwires
>(+)*4>>>>->--->>>-<<<<(-)*79<(+)*4<(+)*5<-<+<(-)*115>
reverse tripwire check
(-)*5[
enemy must have pierced our decoys via rule of 9 or tripwire avoiance
and is possibly on our flag
attempt to lock them immediately; we have no information on which
to base timing/parity so just guess
<$clearloopneg
](+)*5
>>>
another reverse tripwire check
(-)*4[
enemy hasn't reached our flag yet; but is near
switch to shudderlock strategy
<<<[[]]<$clearloopneg
]+
>([{
we get here against defence programs that wait on tripwires forever
/
simply use a crazy clear loop that they can't be expected to have a
lock for; the clear loop used here is a 3 in 5 loop with a large
reverse offset and antishudder/antivibration
>>>(>(+)*100[+.++[+.++]][-.--[-.--]])*21
}
now go onto the main program
[[]]<
the basic idea: we check to see on what cycle our size 1 tripwires
disappear; we hope for it to be very soon after the previous cell is
cleared
/
in other words: we rely on the fact that programs nearly always adjust
a cell after checking that it's zero; and the cycle before the first
adjustment must be the first check
/
this would be easiest with the cell at zero but then the opponent
probably wouldn't adjust at all unless trailing: so we have to use 1
[[
fastest the opponent can get here with a normal clear loop
[[[[[
did the opponent check in the other direction?
<(+)*75[[]]< ..
/
[
$odcheck
]<(+)*75<(-)*14>[]<+
$clearloopneg
/
]<<<(+)*75<(-)*12>[[]]...<-
$clearlooppos
]<<<(+)*75<(-)*12>[[]]..<-
$clearlooppos
]<<<(+)*75<(-)*12>[[]].<-
$clearlooppos
]<<<(+)*75<(-)*12>[[]]<-
$clearlooppos
]<<<(+)*75<(-)*12>[]<-
$clearlooppos
]
if we get here then the opponent either had a tripwire clash
with us; or offsets without checking if the cell is 0 first
in either case our ordinary strategy won't work; so try to lock
them
<$clearloopnarrow
]
<$clearloopnarrow
]
)%8000
EOF
$prog =~ s/[^\[\]<>.\+\-(){}*%\d]//g;
$prog =~ s/\([^()]+\)\*0//g;
print $prog;