At the bottom of the following function where it says STARTING HERE I am trying to code an algorithm that will place a computer move, denoted as -1, into a board. My program has a pointer called children that points to 7 different boards. Therefore each board should have 1 potential move, 1 different move in each column. But when I run my code, it puts the correct move in the correct column in each ->board but it fills the entire column with that move instead of just the spot it should.. Any ideas would be greatly appreciated. Thanks!
void buildTree(gameTree *root/* in-out */, int move/* in */, int depth/* in */)
{
/* purpose: given a gameTree node containing the current board, and whose move
it is if the depth is greater than zero,
evaluate the board and copy that in the value field of the node
else generate all legal children nodes with appropriate boards,
and moves, call buildTree for each node with depth -1,
look at all children and choose max (or min) of children to
determine the value of the passed in node
pre : board is valid
move is 1 or -1 to determine who is to move next (redundant)
depth is an integer >=0
post : a full game tree is created with the root as the root
calls : cost
called by : puterMove
*/
if (depth>0)
{
depth--;
move = (depth%2==0)?-1:1;
int makechildren;
int made = 0;
for(makechildren = 0; makechildren < SIZE; makechildren ++)
{
//Determine if board is valid*************************************
int boardvalid = 0;
int valid = 0;
int toprow = SIZE - 1;
int t,s;
int col;
for (col = 0; col<SIZE; col++)
{
if(root->board[toprow][col] == 0)
{
root->children[col] = new gameTree; //new MAKING CHILDREN
root->children[col]->move = move;
root->children[col]->value = col;
for(t = 0; t < SIZE; t++)
for(s = 0; s < SIZE; s++)
root->children[col]->board[t][s] = root->board[t][s];
for (t= 0; t<SIZE && root->board[t][col] == 0; t++)
root->children[col]->board[t][col] = -1*move;
cout << "TEST: " << root->children[col]->board[t][col] << endl;
made++;
valid++;
}
}
cout << "MADE:" << made;
//Done determining if board is valid*******************************
//root->value = cost(root->children[7]->board);
}//end of for(makechildren) loop
//root->value = soemthing./!!!! max or min of all of your children
}//end of if(depth > 0)
//else cost();
int place = 0;
int rplace = 0;
int cplace = 0;
int d = 0;
int dcol = 0;
int dchild = 0;
//STARTING HERE!!!!
while(root->children[dchild]->board[d][dcol] != 0)
{
d++;
root->children[dchild]->board[d][dcol] = -1;
dchild++;
}
for(place = 0; place < SIZE; place++)
for(rplace = 0; rplace < SIZE; rplace++)
for(cplace = 0; cplace < SIZE; cplace++) //output tests
cout << root->children[place]->board[rplace][cplace];
cout << "HEY: " << root->children[0]->board[0][1];
//else
//root->value = cost(root->board);
}//end of function