Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Structure Of The Relational Database Model

Authors: Jan Paredaens ,Paul De Bra ,Marc Gyssens ,Dirk Van Gucht

1st Edition

3642699588, 978-3642699580

More Books

Students also viewed these Databases questions

Question

Explain how FTTH works.

Answered: 1 week ago