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 __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
Get Actions Method
The Nim class should have a get_actions() method that can be used to determine the actions available to
the current player. The header for get_actions() is shown below.
def get_actions(self):
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:
1. Create an empty list named actions.
2. 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 max_stones.
B. Add several action tuples to the action list. These tuples should be of the form:
(pile_index, 1),(pile_index, 2),...,(pile_index, max_stones)
3. Return the actions list.
As an example, suppose that the current board state for a Nim game is [2,5,1], and that the limit for the
game is equal to 3. Then the get_actions() method should return the following list:
[(0,1),(0,2),(1,1),(1,2),(1,3),(2,1)]

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!