Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0e7e1c922d | |||
| f3afe492cf |
11
game.py
11
game.py
@ -650,6 +650,9 @@ class Game:
|
||||
agentIndex = self.startingIndex
|
||||
numAgents = len(self.agents)
|
||||
|
||||
time_sum = 0
|
||||
counter = 0
|
||||
|
||||
while not self.gameOver:
|
||||
# Fetch the next agent
|
||||
agent = self.agents[agentIndex]
|
||||
@ -729,7 +732,13 @@ class Game:
|
||||
self.unmute()
|
||||
return
|
||||
else:
|
||||
start = time.time()
|
||||
action = agent.getAction(observation)
|
||||
stop = time.time()
|
||||
time_sum += (stop-start)
|
||||
counter += 1
|
||||
|
||||
|
||||
self.unmute()
|
||||
|
||||
# Execute the action
|
||||
@ -762,6 +771,8 @@ class Game:
|
||||
if _BOINC_ENABLED:
|
||||
boinc.set_fraction_done(self.getProgress())
|
||||
|
||||
print("TIME:", time_sum/counter)
|
||||
|
||||
# inform a learning agent of the game result
|
||||
for agentIndex, agent in enumerate(self.agents):
|
||||
if "final" in dir(agent):
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
from util import manhattanDistance
|
||||
from game import Directions
|
||||
import random, util
|
||||
import time
|
||||
|
||||
from game import Agent
|
||||
from pacman import GameState
|
||||
@ -162,7 +163,8 @@ class MinimaxAgent(MultiAgentSearchAgent):
|
||||
Returns whether or not the game state is a losing state
|
||||
"""
|
||||
"*** YOUR CODE HERE ***"
|
||||
return self.result(gameState, 0, self.depth)[1]
|
||||
action = self.result(gameState, 0, self.depth)[1]
|
||||
return action
|
||||
|
||||
def result(self, state, agentIndex, depth):
|
||||
if depth == 0 or state.isLose() or state.isWin():
|
||||
@ -196,7 +198,8 @@ class AlphaBetaAgent(MultiAgentSearchAgent):
|
||||
Returns the minimax action using self.depth and self.evaluationFunction
|
||||
"""
|
||||
"*** YOUR CODE HERE ***"
|
||||
return self.result(gameState, 0, self.depth, -1e9, 1e9)[1]
|
||||
action = self.result(gameState, 0, self.depth, -1e9, 1e9)[1]
|
||||
return action
|
||||
|
||||
def result(self, state, agentIndex, depth, alpha, beta):
|
||||
if depth == 0 or state.isLose() or state.isWin():
|
||||
|
||||
Loading…
Reference in New Issue
Block a user