def run(layout_str, pac, ghosts, disp, nGames=1, name='games', maxMoves=-1, quiet=True): "Runs a few games and outputs their statistics." starttime = time.time() lay = layout.Layout(layout_str) #print '*** Running %s on' % name, layname,'%d time(s).' % nGames games = busters.runGames(lay, pac, ghosts, disp, nGames, maxMoves) #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]} statTuple = (stats['wins'], len(games), sum(stats['scores']) * 1.0 / len(games)) if not quiet: print('*** Won %d out of %d games. Average score: %f ***' % statTuple) return stats
def run(layout_str, pac, ghosts, disp, nGames = 1, name = 'games', maxMoves=-1, quiet = True): "Runs a few games and outputs their statistics." starttime = time.time() lay = layout.Layout(layout_str) #print '*** Running %s on' % name, layname,'%d time(s).' % nGames games = busters.runGames(lay, pac, ghosts, disp, nGames, maxMoves) #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]} statTuple = (stats['wins'], len(games), sum(stats['scores']) * 1.0 / len(games)) if not quiet: print '*** Won %d out of %d games. Average score: %f ***' % statTuple return stats