Question: need help with Python copy method: my current code: import numpy as np class Nim: def _ _ init _ _ ( self , piles,
need help with Python copy method:
my current code:
import numpy as np
class Nim:
def initself piles, stones, limit:
self.piles piles
self.stones stones
self.limit limit
self.winner None
self.turns
self.curplayer
self.board stones piles
def displayself:
printfCurrent Turn: selfturns
Current Player: selfcurplayer
Piles: selfboard
Copy Method
The Nim class should have a copy method. This method is used by the search agents to create child notes
when constructing a game tree. The header for copy is shown below.
def copyself:
This method has only one parameter, self, which refers to the instance of Nim that is being copied.
The method should perform the following tasks:
Create a new instance of Nim, naming it newnode or something similar When creating the new
instance, the piles, stones, and limit parameters for self should be passed to the constructor so
that the same values are used for newnode.
Overwrite the winner, turns, and curplayer attributes of newnode with the corresponding values
from self.
Overwrite the board attribute of newnode with a copy of the same attribute from self. Be sure to
use the copy method of the list to create a new copy of the list, as opposed to simply creating a
reference to the old list.
Return newnode.
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
