Compare commits

..

No commits in common. "time" and "main" have entirely different histories.
time ... main

2 changed files with 2 additions and 16 deletions

11
game.py
View File

@ -650,9 +650,6 @@ class Game:
agentIndex = self.startingIndex agentIndex = self.startingIndex
numAgents = len(self.agents) numAgents = len(self.agents)
time_sum = 0
counter = 0
while not self.gameOver: while not self.gameOver:
# Fetch the next agent # Fetch the next agent
agent = self.agents[agentIndex] agent = self.agents[agentIndex]
@ -732,13 +729,7 @@ class Game:
self.unmute() self.unmute()
return return
else: else:
start = time.time()
action = agent.getAction(observation) action = agent.getAction(observation)
stop = time.time()
time_sum += (stop-start)
counter += 1
self.unmute() self.unmute()
# Execute the action # Execute the action
@ -771,8 +762,6 @@ class Game:
if _BOINC_ENABLED: if _BOINC_ENABLED:
boinc.set_fraction_done(self.getProgress()) boinc.set_fraction_done(self.getProgress())
print("TIME:", time_sum/counter)
# inform a learning agent of the game result # inform a learning agent of the game result
for agentIndex, agent in enumerate(self.agents): for agentIndex, agent in enumerate(self.agents):
if "final" in dir(agent): if "final" in dir(agent):

View File

@ -15,7 +15,6 @@
from util import manhattanDistance from util import manhattanDistance
from game import Directions from game import Directions
import random, util import random, util
import time
from game import Agent from game import Agent
from pacman import GameState from pacman import GameState
@ -163,8 +162,7 @@ class MinimaxAgent(MultiAgentSearchAgent):
Returns whether or not the game state is a losing state Returns whether or not the game state is a losing state
""" """
"*** YOUR CODE HERE ***" "*** YOUR CODE HERE ***"
action = self.result(gameState, 0, self.depth)[1] return self.result(gameState, 0, self.depth)[1]
return action
def result(self, state, agentIndex, depth): def result(self, state, agentIndex, depth):
if depth == 0 or state.isLose() or state.isWin(): if depth == 0 or state.isLose() or state.isWin():
@ -198,8 +196,7 @@ class AlphaBetaAgent(MultiAgentSearchAgent):
Returns the minimax action using self.depth and self.evaluationFunction Returns the minimax action using self.depth and self.evaluationFunction
""" """
"*** YOUR CODE HERE ***" "*** YOUR CODE HERE ***"
action = self.result(gameState, 0, self.depth, -1e9, 1e9)[1] return self.result(gameState, 0, self.depth, -1e9, 1e9)[1]
return action
def result(self, state, agentIndex, depth, alpha, beta): def result(self, state, agentIndex, depth, alpha, beta):
if depth == 0 or state.isLose() or state.isWin(): if depth == 0 or state.isLose() or state.isWin():