hw6/hw6_grader.py
def run(layname, pac, ghosts, nGames = 1, name = 'games'):
  """
  Runs a few games and outputs their statistics.
  """
  if grader.fatalError:
    return {'time': 65536, 'wins': 0, 'games': None, 'scores': [0]*nGames, 'timeouts': nGames}

  starttime = time.time()
  lay = layout.getLayout(layname, 3)
  disp = textDisplay.NullGraphics()

  print(('*** Running %s on' % name, layname,'%d time(s).' % nGames))
  games = pacman.runGames(lay, pac, ghosts, disp, nGames, False, catchExceptions=False)
  print(('*** Finished running %s on' % name, layname,'after %d seconds.' % (time.time() - starttime)))

  stats = {'time': time.time() - starttime, 'wins': [g.state.isWin() for g in games].count(True), 'games': games, 'scores': [g.state.getScore() for g in games], 'timeouts': [g.agentTimeout for g in games].count(True)}
  print(('*** Won %d out of %d games. Average score: %f ***' % (stats['wins'], len(games), sum(stats['scores']) * 1.0 / len(games))))

  return stats

  Runs a few games and outputs their statistics.
  
Runs a few games and outputs their statistics.
Runs a few games and outputs their statistics .
def run(layname, pac, ghosts, nGames = 1, name = 'games'):
  if grader.fatalError:
    return {'time': 65536, 'wins': 0, 'games': None, 'scores': [0]*nGames, 'timeouts': nGames}
  starttime = time.time()
  lay = layout.getLayout(layname, 3)
  disp = textDisplay.NullGraphics()
  print(('*** Running %s on' % name, layname,'%d time(s).' % nGames))
  games = pacman.runGames(lay, pac, ghosts, disp, nGames, False, catchExceptions=False)
  print(('*** Finished running %s on' % name, layname,'after %d seconds.' % (time.time() - starttime)))
  stats = {'time': time.time() - starttime, 'wins': [g.state.isWin() for g in games].count(True), 'games': games, 'scores': [g.state.getScore() for g in games], 'timeouts': [g.agentTimeout for g in games].count(True)}
  print(('*** Won %d out of %d games. Average score: %f ***' % (stats['wins'], len(games), sum(stats['scores']) * 1.0 / len(games))))
  return stats
def run ( layname , pac , ghosts , nGames = 1 , name = 'games' ) : if grader . fatalError : return { 'time' : 65536 , 'wins' : 0 , 'games' : None , 'scores' : [ 0 ] * nGames , 'timeouts' : nGames } starttime = time . time ( ) lay = layout . getLayout ( layname , 3 ) disp = textDisplay . NullGraphics ( ) print ( ( '*** Running %s on' % name , layname , '%d time(s).' % nGames ) ) games = pacman . runGames ( lay , pac , ghosts , disp , nGames , False , catchExceptions = False ) print ( ( '*** Finished running %s on' % name , layname , 'after %d seconds.' % ( time . time ( ) - starttime ) ) ) stats = { 'time' : time . time ( ) - starttime , 'wins' : [ g . state . isWin ( ) for g in games ] . count ( True ) , 'games' : games , 'scores' : [ g . state . getScore ( ) for g in games ] , 'timeouts' : [ g . agentTimeout for g in games ] . count ( True ) } print ( ( '*** Won %d out of %d games. Average score: %f ***' % ( stats [ 'wins' ] , len ( games ) , sum ( stats [ 'scores' ] ) * 1.0 / len ( games ) ) ) ) return stats
Runs a few games and outputs their statistics.
Runs a few games and outputs their statistics .
"""
  Runs a few games and outputs their statistics.
  """
layname
pac
ghosts
nGames
name