Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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