Answered step by step
Verified Expert Solution
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started