コード例 #1
0
def main(argv):
	sampledata = pacman.main("l")
	maxfit = sampledata.total
	popsize = 10000
	print("Generating a population of {0} individuals for a level containing {1} points.".format(popsize, maxfit))
	time_start = time.clock()
	population = [Individual() for i in range(popsize)]
	generation = 0
	while(True):
		for individual in population:
			individual.payoff()
		population.sort(key = lambda x: x.fitness, reverse = True)
		print("Generation {0:04d}, best solution: {1:03d}/{2:03d} points. Time taken: {3:09.4f} seconds."\
			.format(generation, population[0].fitness, maxfit, time.clock()-time_start))

		if (population[0].fitness >= maxfit):
			print("Moves:\n{0}".format(" ".join(population[0].moves)))
			with open("solution.txt", "w") as outfile:
				outfile.write(" ".join(population[0].moves)+"\n")
			return population[0].moves

		for individual in population[popsize//4:popsize//2]:
			individual.mutate()
		for individual in population[popsize//2:]:
			individual.scramble()
		generation += 1
コード例 #2
0
ファイル: run.py プロジェクト: anw10/pac3man
import pacman
import autograder

"""
run.py runs things that look like command-line arguments
for Berkeley Python. Leave the 'python pacman.py' part
at the beginning, just like running from the command line.

You should comment out all lines in the file except the one
you wan to run!
"""

#pacman.main('python pacman.py --layout tinyMaze --pacman GoWestAgent')
#pacman.main('python pacman.py -l tinyMaze -p SearchAgent -a fn=tinyMazeSearch')
pacman.main('python pacman.py -l trickySearch -p AStarFoodSearchAgent')


# autograder
#autograder.run('python autograder.py')
#autograder.run('python autograder -q q1')
#autograder.run('python autograder.py -t test_cases/q2/graph_bfs_vs_dfs')
コード例 #3
0
ファイル: run.py プロジェクト: icdlvru2021/project1-ai
import pacman
import autograder

"""
run.py runs things that look like command-line arguments
for Berkeley Python. Leave the 'python pacman.py' part
at the beginning, just like running from the command line.

You should comment out all lines in the file except the one
you wan to run!
"""

#pacman.main('python pacman.py --layout tinyMaze --pacman GoWestAgent')
#pacman.main('python pacman.py -l tinyMaze -p SearchAgent -a fn=tinyMazeSearch')
pacman.main('python pacman.py -l mediumMaze -p SearchAgent -a fn=dfs')


# autograder
#autograder.run('python autograder.py')
#autograder.run('python autograder -q q1')
#autograder.run('python autograder.py -t test_cases/q2/graph_bfs_vs_dfs')
コード例 #4
0
import pacman
'''
metarun.py runs things that look like command-line arguments
for Berkeley Python. You can leave the 'python pacman.py' part
at the beginning, or remove it, since we are not really running
from the command line.

You should comment out all lines in the file except one!
'''

#pacman.main('--layout tinyMaze --pacman GoWestAgent')
#pacman.main('-l tinyMaze -p SearchAgent -a fn=tinyMazeSearch')
#pacman.main('python pacman.py -l mediumMaze -p SearchAgent -a fn=dfs')
pacman.main('python pacman.py -t test_cases/q2/1-bridge-grid')
コード例 #5
0
            sys.argv.append('-q')
            sys.argv.append('-k')
            sys.argv.append(depth_p)
            sys.argv.append('-l')
            sys.argv.append(layout)
            sys.argv.append('-g')
            sys.argv.append(ghost)
            sys.argv.append('-n')
            sys.argv.append('50')

            print(sys.argv)
            stream = StringIO()
            sys.stdout = stream
            print(sys.argv)
            # args_i = ['run.py', '-p', 'ReflexAgent', '-q']
            pacman.main()
            # a = stream.getvalue()
            del sys.argv[:11]
            average_score = float(
                stream.getvalue().split("\n")[6].split(":")[1])
            average_time = float(
                stream.getvalue().split("\n")[10].split(":")[1])
            with open('miniClassic.csv', mode='a', newline='') as f:
                writer = csv.DictWriter(f, fieldnames=fieldnames)
                writer.writerow({
                    'Agent': pacman_i,
                    'layout': layout,
                    'ghost': ghost,
                    'average score': average_score,
                    'average turn time': average_time
                })
コード例 #6
0
	def payoff(self):
		self.fitness = pacman.main(self.moves).collected
コード例 #7
0
import pacman
import autograder
"""
run.py runs things that look like command-line arguments
for Berkeley Python. Leave the 'python pacman.py' part
at the beginning, just like running from the command line.

You should comment out all lines in the file except the one
you wan to run!
"""

# pacman
#pacman.main('python pacman.py')
#pacman.main('python pacman.py -p ReflexAgent -l testClassic')
pacman.main('python pacman.py --frameTime 0 -p ReflexAgent -k 2')
#pacman.main('python pacman.py -p MinimaxAgent -l minimaxClassic -a depth=4')

# autograder
#autograder.run('python autograder.py')
#autograder.run('python autograder -q q1')
#autograder.run('python autograder.py -q q1 --no-graphics')
#autograder.run('python autograder.py -t test_cases/q2/0-small-tree')
コード例 #8
0
import pacman
import autograder
"""
run.py runs things that look like command-line arguments
for Berkeley Python. Leave the 'python pacman.py' part
at the beginning, just like running from the command line.

You should comment out all lines in the file except the one
you wan to run!
"""

#pacman.main('python pacman.py --layout tinyMaze --pacman GoWestAgent')
#pacman.main('python pacman.py -l tinyMaze -p SearchAgent -a fn=tinyMazeSearch')
#pacman.main('python pacman.py -l mediumMaze -p SearchAgent -a fn=dfs')
#pacman.main('python pacman.py -l mediumMaze -p SearchAgent -a fn=bfs')
#pacman.main('python pacman.py -l mediumMaze -p SearchAgent -a fn=ucs')
#pacman.main('python pacman.py -l bigMaze -z .5 -p SearchAgent -a fn=ucs')
pacman.main(
    'python pacman.py -l bigMaze -z .5 -p SearchAgent -a fn=astar,heuristic=manhattanHeuristic'
)

# autograder
#autograder.run('python autograder.py')
#autograder.run('python autograder -q q1')
#autograder.run('python autograder.py -t test_cases/q2/graph_bfs_vs_dfs')
コード例 #9
0
# dfs, bfs
#pacman.main('python pacman.py -l mediumMaze -p SearchAgent -a fn=dfs')
#pacman.main('python pacman.py -l mediumMaze -p SearchAgent -a fn=bfs')

# ucs
#pacman.main('python pacman.py -l mediumMaze -p SearchAgent -a fn=ucs')
#pacman.main('python pacman.py -l bigMaze -z .5 -p SearchAgent -a fn=ucs')
#pacman.main('python pacman.py -l mediumDottedMaze -p StayEastSearchAgent')
#pacman.main('python pacman.py -l mediumScaryMaze -p StayWestSearchAgent')

# aster
#pacman.main('python pacman.py -l bigMaze -z .5 -p SearchAgent -a fn=astar,heuristic=manhattanHeuristic')

# corner problem with bfs
#pacman.main('python pacman.py -l tinyCorners -p SearchAgent -a fn=bfs,prob=CornersProblem')
#pacman.main('python pacman.py -l mediumCorners -p SearchAgent -a fn=bfs,prob=CornersProblem')

# corner problem with aster
#pacman.main('python pacman.py -l mediumCorners -p AStarCornersAgent -z 0.5')

# all food problem with ucs
#pacman.main('python pacman.py -l trickySearch -p SearchAgent -a fn=ucs,prob=FoodSearchProblem')

# all food problem with aster
#pacman.main('python pacman.py -l testSearch -p AStarFoodSearchAgent')
#pacman.main('python pacman.py -l trickySearch -p AStarFoodSearchAgent')
pacman.main('python pacman.py -l bigSearch -p AStarFoodSearchAgent')

# all food problem with greedy
#pacman.main('python pacman.py -l bigSearch -p ClosestDotSearchAgent -z .5')