Question: need help with take action method: my code so far: import numpy as np class Nim: def _ _ init _ _ ( self ,

need help with take action method:
my code so far:
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}")
def copy(self):
new_node = Nim(self.piles, self.stones, self.limit)
new_node.winner = self.winner
new_node.turns = self.turns
new_node.cur_player = self.cur_player
new_node.board = self.board.copy()
return new_node
Take Action Method
The Nim class should have a take_action() method that can be used to apply a selected action to the game.
The header for take_actions() is shown below.
def take_actions(self, a):
This self parameter refers to the instance of Nim from which the method is being called and the a parameter is
an action tuple of the form (pile_index, stones_removed).
The method should perform the following tasks:
1. Use the copy() method of self to create a copy of the current instance. Name the copy new_node.
2. Update the board attribute of new_node to remove stones from one of the piles. The correct pile and
the number of stones are indicated by the action, a.
3. Increment the number of turns that have been taken by 1 for new_node.
4. Switch the current player for new_node from 1 to 2, or from 2 to 1.
5. Call the check_for_win() method of new_node to see if the current player has won.
6. 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!