Skip to content

Commit

Permalink
Added stochastic nodes in minimax tree
Browse files Browse the repository at this point in the history
  • Loading branch information
kirklange committed May 12, 2018
1 parent 30ee70b commit 8fab743
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions src/rgu/rgu_ai.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,35 @@ uint8_t rgu_ai_mmab(rgu_game *game, uint8_t moves, uint8_t lookAhead,
}
else
{
/* Do recursive call */
int16_t temp;
if (rgu_ai_mmab(gameCopy, moves, lookAhead-1,
alpha, bravo, &temp, 0))
/* Do recursive calls and make this a chance
* node by making a weighted average */
int16_t branch[5];
uint8_t j;
for (j=0; j<5; j++)
{
utilityArray[i] = temp;
}
else
{
/* If recursion failed, i.e. if there are no
* moves that can be taken, then get the
* utility of the current board state */
utilityArray[i] =
rgu_board_getUtility(gameCopy->board);
int16_t temp;
if (rgu_ai_mmab(gameCopy, moves, lookAhead-1,
alpha, bravo, &temp, 0))
{
branch[j] = temp;
}
else
{
/* If recursion failed, i.e. if there are
* no moves that can be taken, then get
* the utility of the current board
* state */
branch[j] =
rgu_board_getUtility(gameCopy->board);
}
}

/* Weights are based on the nature of the RGU
* dice rolls (equivalent to flipping four
* coins) */
utilityArray[i] = branch[0] + (branch[1]*4) +
(branch[2]*6) + (branch[3]*4) + branch[4];
utilityArray[i] /= 16;
}

/* Unflip turn for following minimax and pruning */
Expand Down

0 comments on commit 8fab743

Please sign in to comment.