2

I'm going to implement a game application on a hardware(fpga) and because of recognizable hardware difficulty i can't implement function recursion. I've just searched for non-recursive alpha-beta pruning algorithm on minimax trees. unfortunately nothing appropriate found. any algorithm or implementation that solve the problem of recursion using stack or other data structures will be appreciated.

muradin
  • 1,249
  • 2
  • 14
  • 34
  • 2
    Is it possible in your environment to use a selfmade or predefined stack, perhaps my means of an array? Conceptually, it cannot be done without recursion. What language can be used? – Codor Jul 23 '14 at 11:12
  • yes it is possible to use stack. conceptually any recursive function can be implemented by selfmade stack just the way compiler do this job with program stack! c/c++ is more appropriate but algorithm is the gist. – muradin Jul 23 '14 at 12:02
  • Ok, do you have any implementation of the minimax algorithm you can start with? If yes, the problem is mainly to implement recursion using the stack, however this is a bit difficult without referring to a specific implementation. Furthermore, one must not only handle call arguments but also return values. – Codor Jul 23 '14 at 12:11
  • Did you try to implement an iterative DFS? http://en.wikipedia.org/wiki/Depth-first_search – user189 Jul 23 '14 at 13:00

1 Answers1

1

Looking at my alpha-beta maximin code I have a suggestion:

There is only one recursive method in my algorithm, which is something like this:

/** 
  * Returns maximin value of node with alpha-beta pruning for a certain level of forecasting.
     */
double getMaxAlphaBeta(Node currentState, Player player, int level, double alpha, double beta) {
// [ . . . ]
if(player == MAX){
for(State s : currentState.nextStates){
   utility = getMaxAlphaBeta( s, MIN, level - 1, alpha, beta);
   if (utility > alpha)
      alpha = utility;
   if (alpha >= beta)
      break;
}
}
else{ // [. . .] MIN is playing, do the same things with oppisite sign }

return newBeta;
}

This method is called by another method like this:

public Action getMinimaxStrategy(Node currentState, Player player, int level) {
    double max = this.getMaxAlphaBeta(currentState, player, level, -inf, +inf);
// [ . . . ]

What I would do is to change the second method in something like this:

public Action getMinimaxStrategy(Node currentState, Player player, int level) {
    DATA max = new DATA(currentState);
    for(!max.isOptimal){
    Array<Node> nextNodes = max.currentState.getNextNodes();
    for(Node max.s : nextNodes){
        max = this.getMaxAlphaBeta(currentState, player, level, currentAlpha, currentBeta);
        // [ . . .]
    }
    }
    // [ . . . ]

Where DATA is a data structure containing all you would pass as recursion argument (current state, player, level, alpha, beta) and also the optimality (which is the condition for which you would return from recursion).
Then you can use the same logic to modify the first method. This solution can be optimized and I didn't try it.

Try it if you like and tell me if it's good.

HAL9000
  • 3,562
  • 3
  • 25
  • 47