Question: The Game of Nim(Build a tree) Python 3 The goal of this assignment is to display or print out the minimax tree, not to implement

The Game of Nim(Build a tree) Python 3

The goal of this assignment is to display or print out the minimax tree, not to implement the game.

You will be asked to write a class Minimax that simply allows you to build a minimax tree with states of a Nim game and also display it.

class Minimax: def __init__(self, nimState, minMaxLevel): self.state = nimState self.level = minMaxLevel self.child = []

The algorithm for building the tree is as follows:

for each pile k in node.state do if k > 2 then list of possibilities = split k for each pair (i,j) in possibilities do newstate=node.state replace pile k in newstate with pile i add pile j in newstate sort newstate node.addChild(newstate) end for end if end for 

This algorithm is called after starting the first node which is the root of the tree and contains as a state a list with the initial pile.

create root with starting number of tokens call root.build()

The algorithm would look like this:

print_tree(indentation, last) print indentation if last then print '\-' indentation += " " else print '+ ' indentation += "| " end if print node.state if last print node.level for all children of node last = false if last child then last = true child.print_tree(indentation, last) end for

The result should be like:

Choose your initial size of the pile. Should be more than 2: abc Choose your initial size of the pile. Should be more than 2: 2 Choose your initial size of the pile. Should be more than 2: 6 \-[6] MAX + [1, 5] | + [1, 1, 4] | | \-[1, 1, 1, 3] MIN | | \-[1, 1, 1, 1, 2] MAX | \-[1, 2, 3] MAX | \-[1, 1, 2, 2] MIN \-[2, 4] MIN \-[1, 2, 3] MAX \-[1, 1, 2, 2] MIN

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!