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 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
def copyself:
newnode Nimselfpiles, self.stones, self.limit
newnode.winner self.winner
newnode.turns self.turns
newnode.curplayer self.curplayer
newnode.board self.board.copy
return newnode
Take Action Method
The Nim class should have a takeaction method that can be used to apply a selected action to the game.
The header for takeactions is shown below.
def takeactionsself 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 pileindex, stonesremoved
The method should perform the following tasks:
Use the copy method of self to create a copy of the current instance. Name the copy newnode.
Update the board attribute of newnode to remove stones from one of the piles. The correct pile and
the number of stones are indicated by the action, a
Increment the number of turns that have been taken by for newnode.
Switch the current player for newnode from to or from to
Call the checkforwin method of newnode to see if the current player has won.
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
