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,
max_depth: int,
is_black: bool
)-> tuple[Score, Move]:
"""
Finds the best move for the input board state.
Note that you are black.
Parameters
----------
board: 2D list of lists. Contains characters "B","W", 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 `max_depth`, you should get the evaluation of the position using
the provided heuristic function.
max_depth: int, the maximum depth for cutoff.
is_black: bool. True when finding the best move for black, False
otherwise.
Returns
-------
A tuple (evalutation,((src_row, src_col),(dst_row, dst_col))):
evaluation: the best score that black can achieve after this move.
src_row, src_col: position of the pawn to move.
dst_row, dst_col: position to move the pawn to.
"""
if depth == max_depth or utils.is_game_over(board):
return evaluate(board), None
# Determine the best move and its evaluation
if is_black:
best_evaluation = float('-inf')
best_move = None
for action in generate_valid_moves(board):
new_board = utils.state_change(board, action[0], action[1], in_place=False)
opponent_evaluation, _= minimax(new_board, depth +1, max_depth, False)
if opponent_evaluation > best_evaluation:
best_evaluation = opponent_evaluation
best_move =(action[0], action[1])
return best_evaluation, best_move
else:
best_evaluation = float('inf')
best_move = None
for action in generate_valid_moves(utils.invert_board(board, in_place=False)):
new_board = utils.state_change(utils.invert_board(board, in_place=False), action[0], action[1], in_place=False)
opponent_evaluation, _= minimax(utils.invert_board(new_board, in_place=False), depth +1, max_depth, True)
if opponent_evaluation < best_evaluation:
best_evaluation = opponent_evaluation
best_move =(action[0], action[1])
return best_evaluation, best_move

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!