Question: my code currently run and pass all the public test case but it fail for the hidden one which said Make sure that 'evaluate' is
my code currently run and pass all the public test case but it fail for the hidden one
which said Make sure that 'evaluate' is called with the correct input, especially for white I dont really understand why, as i already inverted after processing white turn.
def minimax
board: Board,
depth: int,
maxdepth: int,
isblack: bool
tupleScore Move:
Finds the best move for the input board state.
Note that you are black.
Parameters
board: D list of lists. Contains characters BW and
representing black pawn, white pawn, and empty cell, respectively.
depth: int, the depth to search for the best move. When this is equal
to maxdepth you should get the evaluation of the position using
the provided heuristic function.
maxdepth: int, the maximum depth for cutoff.
isblack: bool. True when finding the best move for black, False
otherwise.
Returns
A tuple evalutationsrcrow, srccoldstrow, dstcol:
evaluation: the best score that black can achieve after this move.
srcrow, srccol: position of the pawn to move.
dstrow, dstcol: position to move the pawn to
if depth maxdepth or utils.isgameoverboard:
return evaluateboard None
# Determine the best move and its evaluation
if isblack:
bestevaluation floatinf'
bestmove None
for action in generatevalidmovesboard:
newboard utils.statechangeboard action action inplaceFalse
opponentevaluation, minimaxnewboard, depth maxdepth, False
if opponentevaluation bestevaluation:
bestevaluation opponentevaluation
bestmove action action
return bestevaluation, bestmove
else:
bestevaluation floatinf
bestmove None
for action in generatevalidmovesutilsinvertboardboard inplaceFalse:
newboard utils.statechangeutilsinvertboardboard inplaceFalse action action inplaceFalse
opponentevaluation, minimaxutilsinvertboardnewboard, inplaceFalse depth maxdepth, True
if opponentevaluation bestevaluation:
bestevaluation opponentevaluation
bestmove action action
return bestevaluation, bestmove
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
