Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

needing help creating contructor for NIM game in pythonThe Constructor The constructor method is named _ _ init _ ( ) . This method is

needing help creating contructor for NIM game in pythonThe Constructor
The constructor method is named__init_(). This method is called whenever a new instance of the class is
created and is responsible for initializing the attributes of the instance. The header for the constructor for the
Nim class looks like this:
def__init_(self, piles, stones, limit, is_copy=False):
A description of each of the parameters for _() is provided below.
self - This refers to the instance being created.
piles - This should be an integer indicating the number of piles to be used.
stones - This should be an integer indicating the number of stones per pile.
limit - This should be an integer that indicates the maximum number of stones that can be taken in a
single move.
The constructor should perform the following task:
Create attributes self.piles, self.stones, and self.limit, setting each one equal to the
corresponding parameter.
Create an attribute named self.winner, setting it equal to None.
Create an attribute named self.turns, setting it equal to 0.
Create an attribute named self.cur_player, setting it equal to 1.
Create an attribute named self . board, setting it equal to a list whose length is equal to piles, and with
each entry containing the value stones. For example, if we were to create a Nim instance using
Nim(piles=4, stones=7, limit=3), then self.board should equal 7,7,7,7.
The constructor does not need to return anything.
image text in transcribed

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

More Books

Students also viewed these Databases questions

Question

What persuasive techniques can you identify?

Answered: 1 week ago

Question

9. Power and politics can be destructive forces in organizations.

Answered: 1 week ago