Question: need help with get actions method: my current code: import numpy as np class Nim: def _ _ init _ _ ( self , piles,
need help with get actions 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
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
Get Actions Method
The Nim class should have a getactions method that can be used to determine the actions available to
the current player. The header for getactions is shown below.
def getactionsself:
This method has only one parameter, self, which refers to the instance of Nim from which the method is being
called.
The method should perform the following tasks:
Create an empty list named actions.
Loop over each pile in the game board. For each pile, the loop should do the following:
A Determine the maximum number of stones that can be taken from the pile. This will be equal to
either the limit attribute, or the number of stones currently in the pile, whichever is smaller. For
the sake of discussion, let's call the maximum number of stones for a certain pile maxstones.
B Add several action tuples to the action list. These tuples should be of the form:
pileindex, pileindex, pileindex, maxstones
Return the actions list.
As an example, suppose that the current board state for a Nim game is and that the limit for the
game is equal to Then the getactions method should return the following list:
need to run the error check below:
nim Nimpiles stones limit
assertsetnimgetactions set
nim Nimpiles stones limit
nim.board
assertsetnimgetactions set
nim Nimpiles stones limit
nim.board
nim.board
nim.getactions
assertsetnimgetactions set
printAll tests passed!
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
