towforce wrote: ↑Sat Nov 23, 2024 9:07 pm
Not quite: you're basically right - but here's a counterexample:
if (bool) {
..call methodA;
..call methodB;
}
else {
..call methodC;
..call methodD
}
call methodE;
call methodA;
call methodC;
The competition preamble states that they're looking for new types of AI, so the developers need to be require to do something different to what they have done before - hence the no looping and no recursion rule.
OK, I assumed that 'no recursion' meant 'no function calls', and this is formally not correct. But if your example is allowed, the rule 'no recursion' basically becomes ineffective. I would rewrite my alpha-beta searcher that wants to recursively call search up to depth 10 like
Code: Select all
function SearchRoot() { Search1(); }
function Search1() { Search2(); }
...
function Search9() { Search10(); }
So I would just add a different dummy routine for each recursion level, which call each other but never call back to themselves, and the only thing these do is call the routine I would really have liked to call itself. This takes up almost no extra space.
Same with loops: you make a different dummy function for every iteration, which all call the function that does what you want the iteration to do, and make sure there are sufficiently many for the worst case. And after each you should test whether you are done, and then skip the remaining ones:
Code: Select all
function LooplessLoop()
{
if(Iter1()) return;
if(Iter2()) return;
...
if(Iter99()) return;
Iter100()
}
function Iter1() { Iter(1); return done(); }
function Iter2() { Iter(2); return done(); }
...
function Iter100() { Iter(100); return done(); }
I could even pass 'Iter' and 'done' as arguments to LooplessLoop(), so that this function can be universally used for unrolling all loops in the program.