Thursday, December 24, 2009

MinMax Pseudocode

As promised here is MinMax Pseudocode/explanation

MinMax Pseudocode

function minMax(board_state,current_depth, maximum_depth,whoseTurn) returns a number
{
    first of all check if the game has ended or maximum depth has been reached.
    if so, then evaluate the board and return a value for its importance.

    otherwise proceed
    {
       generate possible moves on the board
       if there are no possible moves then evaluate the board and return its value
       else proceed
       {
            for every possible move
           {
                    apply "move" depending on whose turn
                    update the localBoard details and state if necessary
                    call minMax again with new localBoard details and current_depth+1 and whoseTurn
                    store the value returned from minMax into a variable local_value
                  
                    check to see if this local_value is better than best value
                    if it is then make assign the best_value = this local_value
                    and also assign the corresponding best_move = this move (it is highlighted in para above)
           }
        }
     }
return bestMove;
}

I hope that is all clear, if you have any doubt ping me. :)

EDIT: all the variables used in this function should be local, if you are using some global variables either store them into local variables or "undomove" after every minMax call.

2 comments:

Anonymous said...

Hi all. How are you?

Anonymous said...

thank you so much ...that really helped..