#if 1
static const unsigned framelimit = 56950;
#define NXT { if(BqtDamaged) \
{ fail_line = __LINE__; goto WalkFail; } \
if(framecount >= framelimit) \
{ fail_line = __LINE__; goto NextFail; } }
#define RunFramesWhile(condition, input, maxframes, if_fail) \
({ static signed long cnt, maxv; \
for(maxv=(maxframes), cnt=0; (condition); ++cnt) { \
if(cnt >= maxv) { fail_line = __LINE__; if_fail; } \
static unsigned in; \
in = (input); \
\
if(walk_done < walk_length) { in |= K_R; } \
else if(BqtRockXS == 0x0080) { in |= K_R; } \
++walk_done; \
RunFrameWith(in); \
\
\
BqtRockY = RAM[0x600]; \
BqtRockXS = RAM[0x4C0]*256+RAM[0x4E0]; \
NXT; \
} \
cnt; \
})
if(!FCEUI_EmulationPaused()) FCEUI_ToggleEmulationPause();
static unsigned prefix;
static unsigned frames_best;
static SaveState begin_anchor, best;
static int fail_line;
begin_anchor.Create();
frames_best=9999999;
fprintf(stderr, "Frame counter at start: %u\n", (unsigned)framecount);
for(prefix=39; prefix<=40; ++prefix)
{
static unsigned walk_length;
for(walk_length=26; walk_length<30; ++walk_length)
{
__label__ NextFail;
static std::string current_option;
{ char Buf[512];
sprintf(Buf, "idle=%u[walk=%u]",
prefix, walk_length);
current_option = Buf;
}
begin_anchor.Load();
BqtRockY=255;
BqtFiring=0;
BqtBossHit=0;
BqtDamaged=0;
static unsigned walk_done, jump_done;
walk_done = 0; jump_done = 0;
RunFramesWhile(true, 0, prefix, break);
RunFramesWhile(BqtRockY > 134, K_A, 26, goto FailPrefix);
RunFramesWhile(!BqtFiring, K_B, 3, goto FailPrefix);
RunFramesWhile(!BqtBossHit, 0, 20, goto FailPrefix);
if(walk_done < walk_length) break;
static SaveState action_begin;
action_begin.Create();
static unsigned undu_delay; static unsigned begin_pausestart; static unsigned end_pausestart; static unsigned end_skip; static unsigned pausestart_hp; pausestart_hp = BqtBossRemHp;
for(undu_delay=1; undu_delay-->0; )
for(begin_pausestart = 0; begin_pausestart < 4; ++begin_pausestart)
for(end_pausestart = 0; end_pausestart < 8-begin_pausestart; ++end_pausestart)
for(end_skip=0; end_skip < 4; ++end_skip)
{
if(end_skip > 0 && end_pausestart == 0) break;
__label__ NextFail;
static std::string pause_option;
{ char Buf[512];
sprintf(Buf, ",start=[%u,%u,%u,%u]",
begin_pausestart, end_pausestart, end_skip, undu_delay);
pause_option = current_option + Buf;
}
BqtBossRemHp = pausestart_hp;
action_begin.Load();
static SaveState last_action;
static unsigned hit_counter, undu_counter;
undu_counter = 0;
for(hit_counter = 0; BqtBossRemHp; ++hit_counter)
{
if(framecount + (BqtBossRemHp-1)*7 > framelimit)
{ fail_line = __LINE__;
if(BqtBossRemHp > end_pausestart+end_skip)
goto FailEndPausePoint;
goto NextFail; }
BqtSelPushed=0;
RunFramesWhile(!BqtSelPushed, K_SE, 3, goto FailPauseMethod);
static bool UnpauseWithStart;
UnpauseWithStart = false;
if(hit_counter < begin_pausestart) UnpauseWithStart = true;
else if(end_skip && BqtBossRemHp == 1) UnpauseWithStart = false;
else if(BqtBossRemHp < end_pausestart + end_skip) UnpauseWithStart = true;
if(!UnpauseWithStart)
{
RunFrameWith(0); NXT;
RunFrameWith(K_SE); NXT;
last_action.Create();
BqtBossHit=BqtBossRemHp=0;
if(undu_counter >= undu_delay)
{
static SaveState anc2;
static long k;
for(k=0; !BqtBossHit; ++k)
{
if(k >= 27) goto FailPauseMethod;
anc2.Create();
RunFrameWith(K_R);
}
anc2.Load();
RunFrameWith(K_R | K_A);
}
else
{
RunFramesWhile(!BqtBossHit, K_R, 27, goto FailPauseMethod);
}
++undu_counter;
}
else
{
static unsigned n;
for(n=0; ; )
{
static SaveState anc2;
anc2.Create();
BqtBossHit=BqtBossRemHp=0;
RunFrameWith(K_ST); NXT;
if(BqtBossHit) { last_action.Create(); break; }
if(++n >= 10) { fprintf(stderr, "Missed the boss! hitcounter=%u\n", hit_counter);
fail_line = __LINE__; goto FailEndPausePoint; }
anc2.Load();
RunFrameWith(0); NXT;
}
}
}
last_action.Load();
fprintf(stderr, "With %s, it ends at frame %u!\n",
pause_option.c_str(), (unsigned)framecount);
if(framecount <= frames_best)
{
frames_best = framecount;
best.Create();
}
continue;
FailEndPausePoint:
end_pausestart=100; end_skip=10;
FailPauseMethod:
NextFail:
fprintf(stderr, "%s is not acceptable (fail_line=%d,framecount=%u)\n",
pause_option.c_str(), fail_line, (unsigned)framecount);
}
continue;
WalkFail:
walk_length=999;
FailPrefix:
NextFail:
fprintf(stderr,
"%s is not acceptable (fail_line=%d, Y=%d, frno=%u)\n",
current_option.c_str(), fail_line, BqtRockY, (unsigned)framecount);
}
}
fprintf(stderr, "Loading best savestate: %u frames\n", frames_best);
best.Load();
BotFrontEnd();
FCEUSS_Save("botfront-end");
goto Restart;
#endif