Minimax Pseudo Code

Basic Minimax Algorithm

minimax(gameSituation, depthSoFar)

            If depthSoFar = this.maxDepthSearch OR gameSituation is end of game

                        heurEval = ratePosition(this.colorPlaying)

                        return minimax results object with heurEval and null path

            else

                        successors = moveGenerate(this.maxWidthSearch)      /// possible moves

                        if no successors

                                    heurEval = ratePosition(this.colorPlaying)

                                    return minimax results object with heurEval and null path

                        else

                                    loop through successors

                                                create game situation that would result from move

                                                resultForSucc = minimax(adjusted game situation – adjusted board, opposite color playing, depth+1

                                                newValue = resultForSucc.getHeurVal()

                                                curr path = put current successor in front of best path returned by lower level call to minimax

                                                if newValue is better than best value so far at this level

                                                            update best value and best path

                                    END LOOP

                        END IF

            END IF

            Return object with best value and best path