Co-routine a recursion help
I have 2 methods I need to put in coroutines: one that returns int and another which is void but is a recursion with 'out' parameters.
I can;t seem to be able to put the recursion method in a coroutine, either I get the syntax wrong, or it complains about 'out' parameters...I can;t change the recursion logic now.
How do I coroutine a method that returns int? it has several independant loops, do I yield after each This method is called by the recursion and separately as well.
this is the code for the recursion:
public void Minimax(bool maximizeOrMinimize, int color, int depth, int[][] board, out int move, out int score)
{
if (0 == depth)
{
move = -1;
score = ScoreBoard(board);
}
else
{
int bestScore = maximizeOrMinimize ? -10000000 : 10000000;
int bestMove = -1;
for (int column = 0; column < width; column++)
{
if (board[0][column] != (int)Mycell.Barren)
continue;
int rowFilled = dropDisk(board, column, color); // damage the state
if (rowFilled == -1)
continue;
int s = ScoreBoard(board);
if (s == (maximizeOrMinimize ? orangeWins : yellowWins))
{
bestMove = column;
bestScore = s;
board[rowFilled][column] = (int)Mycell.Barren;
break;
}
int moveInner, scoreInner;
Minimax(!maximizeOrMinimize, color == (int)Mycell.Orange ? (int)Mycell.Yellow : (int)Mycell.Orange,
depth - 1, board, out moveInner, out scoreInner);
board[rowFilled][column] = (int)Mycell.Barren; // Undo the damage
// No need for lists and sorting - just keep the best value you meet.
if (maximizeOrMinimize)
{
if (scoreInner >= bestScore)
{
bestScore = scoreInner;
bestMove = column;
}
}
else
{
if (scoreInner <= bestScore)
{
bestScore = scoreInner;
bestMove = column;
}
}
}
move = bestMove;
score = bestScore;
}
}
Comment