Question: 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 namedinit 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:
definitself piles, stones, limit iscopyFalse:
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
Create an attribute named self.curplayer, setting it equal to
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
Nimpiles stones limit then self.board should equal
The constructor does not need to return anything.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
