Pseudocode for minmax algorithm

I want to get pseudocode for minmax algorithm. I have to do 2 functions, def maxAgent (gameState, depth) and minAgent. Is there any body that has the correct and easy pseudo-code for it.

+3
source share
2 answers

Two players, A and B, take turns playing.

We are given a scoring function f, which estimates the given position in the fields P. Large values ​​of f (P) are better for A and worse for B (that is, f (P) is an estimate of how “good” P is for A without any or further searches).

Consider the position of the board P.

P - node (.. P - , , ), f (P) node.

P node C1,..., Cn. , S1,..., Sn.

A P, P max {S1,..., Sn}, A , .

B P, P min {S1,..., Sn}, B , .

, .

, -, () , . -- , A , B , M, - , M, B A !

+2

minmax A B. node, , max ( A) min ( B ) -.

, (1 A, -1 B), 0. A -

  getMaxScore(node) {
    score = node.score;
    for each child node 
       score = max(score, getMaxScore(node))  
    next

    return score;
  }

. , 1, A.

B, getMinScore, min, , -1. ​​

+2

Source: https://habr.com/ru/post/1757068/


All Articles