Question: need help with python. part 3 class Nim: def _ _ init _ _ ( self , piles, stones, limit ) : self.piles = piles
need help with python. part
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
def checkforwinself:
if allpile for pile in self.board:
self.winner self.curplayer
def getactionsself:
actions
for pileindex, stonesinpile in enumerateselfboard:
maxstones minstonesinpile, self.limit
for stonestotake in range maxstones :
actions.appendpileindex, stonestotake
return actions
def takeactionself a:
newnode self.copy
pileindex, stonesremoved a
newnode.boardpileindex stonesremoved
newnode.turns
newnode.curplayer if self.curplayer else
newnode.checkforwin
return newnode
def getstateself:
s
for i in rangeselfpiles:
s self.boardiselfstones i
return s
def heuristicself agent, modeNone:
return
Part : Human vs AI Agents
In Part you will actually play games against the RandomPlayer and MininmaxPlayer agents.
A Human vs Random
Create an instance of Nim with piles, stones per pile, and with a limit of stones per action. Then create an instance of RandomPlayer and an instance of HumanPlayer. When creating the HumanPlayer, set clearFalse.
Then use playgame to play a game against the RandomPlayer agent. Set displayflags'aws' when calling playgame You can select which player plays first. When selecting actions, you can enter your actions as a tuple of the form pileindex, numberofstones You can also ommit the parentheses and the action will still be accepted.
You are welcome to play a few games against this agent, but your final submission should demonstrate a game in which you defeat the RandomPlayer agent. This should not require you to learn any deep strategy about playing Nim, and should not be that difficult to do If you are having difficulties defeating the random player, then I would suggest playing defensively, removing only a few stones at a time and waiting until you have an opportunity to force the random player to take the last stone.
B Human vs Minimax
Create an instance of Nim with piles, stones per pile, and with a limit of stones per action. Then create an instance of MinimaxPlayer with depth and an instance of HumanPlayer. When creating the HumanPlayer, set clearFalse.
Then use playgame to play a game against the MinimaxPlayer agent. Set displayflags'aws' when calling playgame You can select which player plays first.
You do not need to win this game but you are encouraged to try
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
