Spent the day writing my first recursive program, this is the first program ive written entirely from knowledge, working it out on my own rather than copying half of it from stackoverflow :P So forgive me if im overlooking factors or missing established recursive syntax/flow.
Ive got it into what i thought should be the final state, however there seems to be a problem with my cost calculations and deciding the best move at the very top level of the function.
Unless it is presented with a board where it can win in the next move, it will always choose position 0, despite knowing the highest value move.
If anyone could let me know if im just code blind atm and missing obvious logic id be hugely appreciateive! (Or if i need to burn it all and restart)
Either way im rather proud just at the fact this runs! (Wrote 90% on an android IDE out and about)
Heres the problem bit, despite there being positive values in PossCost, BestMove never changes.
//If initial call of function, play the best move.
if (Level == 0)
for (unsigned int i = 0; i < PossMoves.size(); i++)
if (PossMoves[i].Cost > BestMove.Cost)
BestMove = PossMoves[i];
//Plays the best move to original board passed by ref
BoardOUT[BestMove.Index].Empty = false;
And heres my github link for anyone willing to check out the full code! The 1st and 2nd turns can take a while to run due to the nature of it.
Thanks for reading :)