I am currently trying to create a recursive function, but i found out that it isn't working and i dont really understand why this happens or how i could fix it.
I use the following function:
public AIMove RecursiveMiniMaxAI(int Depth, int MaxDepth, gamestate StateOfBoard, int Player)
{
//Some general code
if (Player == 2)
{
for (int i = 0; i < MoveList.Count; i++)
//foreach (int i in MoveList)
{
//Some code
//Recursive function
ReturnMove = RecursiveMiniMaxAI(Depth + 1, MaxDepth, AIStates[Depth + 1, j], 1);
//Some code
}
}
else
{
for (int k = 0; k < MoveList.Count; k++)
//foreach (int k in MoveList)
{
//Some code
//Recursive function call
ReturnMove = RecursiveMiniMaxAI(Depth + 1, MaxDepth, AIStates[Depth + 1, j], 2);
//Some code
}
}
//Some code
return ReturnMove;
}
The problem is that both for loops only loop once. Even if i or k are 3,4 or 5, the loop runs once for i =0 and then doesn't loop again. This happens with both the for statement and the foreach statement.
If i remove the recursive function call, the loop runs just fine, so it must have something to do with that.
I would be really happy if anyone could point me in the right direction.
PS. i already posted this topic in the Artificial Intelligence forum, but since this doesn't really concern AI anymore I als posted it here.
For reference, here is the link to my older post with my complete code in it.
http://www.gamedev.net/topic/622037-connect-four-ai/