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 __init__(self, piles, stones, limit):
self.piles = piles
self.stones = stones
self.limit = limit
self.winner = None
self.turns =0
self.cur_player =1
self.board =[stones]* piles
def display(self):
print(f"Current Turn: {self.turns}
Current Player: {self.cur_player}
Piles: {self.board}")
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 copy(self):
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:
1. Create a new instance of Nim, naming it new_node (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 new_node.
2. Overwrite the winner, turns, and cur_player attributes of new_node with the corresponding values
from self.
3. Overwrite the board attribute of new_node 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.
4. Return new_node.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!