So I’m trying to implement a recursive function that generates the entire game tree of Tic-Tac-Toe, and I can’t seem to get it to work.
void BuildTree(Node& nNode, const int& nextPlayer)
{
//Copy last board
Ticboard tBoard = nNode.m_board;
do
{
//Return first valid move
int validMove = tBoard.FirstValidMove();
if (validMove != -1)
{
Node f;
Ticboard tempBoard = nNode.m_board;
tempBoard.Move(validMove, nextPlayer);
tBoard.Move(validMove, nextPlayer);
f.m_board = tempBoard;
f.m_winCount = 0;
nNode.m_branches.push_back(f);
int currPlay = (nextPlayer == 1 ? 2 : 1);
BuildTree(f,currPlay);
}
else
{
break;
}
}while(true);
}
The actual function works, I’ve gone through and debugged it and it SHOWS it working as it is supposed to, but when I look at the nodes generated (for Tic-Tac-Toe, by the way) in Visual Studios via breakpoint, it only shows the first 9 branches. I know more were generated because it takes a few seconds, and I added a counter.
Here’s how I call the code:
Ticboard lol;
Node startTree;
startTree.m_board = lol;
int startPlay = 1;
BuildTree(startTree, startPlay);
Without copying all my code for bitboards and whatnot in here, can you see anything immediately wrong with the logic?
This will push_back a copy of the Node
f, so the stuff insidenNode.m_brancheswill be irrelevant to the modification offlater on.