First recursive program! (Tic tac toe)

Hey all,

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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  	//If initial call of function, play the best move.
	if (Level == 0)
	{
		Moves BestMove;
		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; 
		return 10;
		
	}


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.
https://github.com/NotWhatYouWanted/NoughtsandCrosses

Thanks for reading :)
Oops! >.<

Turns out i was initialising BestMove to 0 in the default arguments for Moves. Its working an absolute dream now, couldnt be more proud of it!

Anyone is welcome to roast my code and knock me down a few pegs!
Topic archived. No new replies allowed.