Question: Write the program in Python (comments(#) included). Please follow the step below, thanks. Problem(minmax tree algorithm) : Implement the minimax tree functions specified in the

Write the program in Python(comments(#) included).

Please follow the step below, thanks.

Problem(minmax tree algorithm): Implement the minimax tree functions specified in the pseudocode down below, and use them to find the max (root's value) of a tree read in from the keyboard as a nested list. For example, the input tree would be: ((3,12,8),(2,4,6),(14,5,2)) 

Visual representation of the input:

-----------------------------(--------Root--------) Max

-----------------------/---------------|------------------\

----------------(subtree)------(subtree)------(subtree) Min

----------------/----|---\--------/-----|----\-------/----|----\

------------ 3-----12----8__2----4-----6__14---5------2

Visual representation of the MiniMax algorithm:

---------------------------(---------3----------) Max

-----------------------/--------------|------------\

---------------(-----3-----)--(----2-----)-----(-----2-----) Min

----------------/---|---\-------/-----|----\-------/----|----\

------------ 3---12----8__2----4-----6__14---5------2

And so the output should be 3, because 3 will be the max return value after the minimax tree program finished running.

So basically we prompt a message asking the user to input a tree(nested list), and the user enters the nested list specified above, once the program finsihes running it would output the max found value, which is 3 in this example.

Pseudocode(minimax tree):

01 function minimax(node, depth, maximizingPlayer) 02 if depth = 0 or node is a terminal node 03 return the heuristic value of node 04 if maximizingPlayer 05 bestValue :=  06 for each child of node 07 v := minimax(child, depth  1, FALSE) 08 bestValue := max(bestValue, v) 09 return bestValue 10 else (* minimizing player *) 11 bestValue := + 12 for each child of node 13 v := minimax(child, depth  1, TRUE) 14 bestValue := min(bestValue, v) 15 return bestValue 

The minimax function returns a heuristic value for leaf nodes (terminal nodes and nodes at the maximum search depth). Non leaf nodes inherit their value, bestValue, from a descendant leaf node. The heuristic value is a score measuring the favorability of the node for the maximizing player. Hence nodes resulting in a favorable outcome, such as a win, for the maximizing player have higher scores than nodes more favorable for the minimizing player. The heuristic value for terminal (game ending) leaf nodes are scores corresponding to win, loss, or draw, for the maximizing player. For non terminal leaf nodes at the maximum search depth, an evaluation function estimates a heuristic value for the node. The quality of this estimate and the search depth determine the quality and accuracy of the final minimax result.

Minimax treats the two players (the maximizing player and the minimizing player) separately in its code.

Note that if you find a better minimax algorithm that does meets the above requirements, then feel free to use it to implement this problem.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!