feat: q1 public test pass

This commit is contained in:
Ting-Jun Wang 2024-04-06 23:26:33 +08:00
parent 5a8f477b21
commit 359e3094ca
Signed by: snsd0805
GPG Key ID: D175E969960C4B16

View File

@ -75,6 +75,28 @@ class ReflexAgent(Agent):
newScaredTimes = [ghostState.scaredTimer for ghostState in newGhostStates]
"*** YOUR CODE HERE ***"
ans = successorGameState.getScore()
AVOID_GHOST_SCORE = 10
EAT_FOOD_SCORE = 20
nearest_ghost_distance = 1e9
for ghostState in newGhostStates:
if ghostState.scaredTimer == 0:
nearest_ghost_distance = min(nearest_ghost_distance, util.manhattanDistance(ghostState.getPosition(), newPos)+1)
nearest_food_distance = 1e9
for foodPos in newFood.asList():
nearest_food_distance = min(nearest_food_distance, util.manhattanDistance(foodPos, newPos)+1)
ans -= AVOID_GHOST_SCORE * (1/nearest_ghost_distance)
ans += EAT_FOOD_SCORE * (1/nearest_food_distance)
return ans
return successorGameState.getScore()
def scoreEvaluationFunction(currentGameState: GameState):