Answered step by step
Verified Expert Solution
Link Copied!

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 __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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Inductive Databases And Constraint Based Data Mining

Authors: Saso Dzeroski ,Bart Goethals ,Pance Panov

2010th Edition

1489982175, 978-1489982179

More Books

Students also viewed these Databases questions