Genetic Algorithm Optimization in Pacman
Genetic Algorithm Optimization in Pacman
Abstract-Previous artificial intelligence education research an automated Pacman player using at least a greedy search
(DeNero and Klein, 2010) has used the classic video game Pacman with different heuristic functions (more details about this
to teach introductory artificial intelligence concepts. One of the
assignment are presented in Section 2). This is necessary as
advantages of the work proposed in (DeNero and Klein, 2010)
is that the same framework, in this case using the video game
by using different heuristic functions the students will need
Pacman, can be used for different student assignments covering to combine the outputs of the different heuristics. The way
different artificial intelligence algorithms and methods. The issue the students combine the outputs is to assign weights to each
of how to use the same practical framework is an important heuristic and they use a manual trial and error approach
one, because if students have to learn a different framework
to adjust the weights, i.e. they try different parameters for
for every assignment they will often feel discouraged. For this
reason, the main contribution of this paper is to present a
each heuristic weight and evaluate what happens with their
practical assignment to teach students about genetic algorithm developed Pacman player.
based parameter optimization using the Pacman framework. The remainder of this paper is organized as follows: Section
III presents a brief overview of Genetic Algorithms. Section IV
I. INTRODUCTION
presents the GA-based pacman assignment. Section V presents
Genetic Algorithms (GAs) are a search and optimIzation the discussion about the assignment in practice as well as
procedure that can be used to find solutions to several scientific student feedback and learning outcomes. Section VI presents
and engineering problems [1]. The GAs were originally devel the related work and finally in Section VII we present the
oped by John Holland in the 70's [2] and given its importance conclusions of this work.
to real world problems they are often taught in the context of
artificial intelligence undergraduate classes. II. PRE-REQUISITES
Previous approaches to teach GAs to undergraduate students In order to use the assignment proposed in this work
include: Using a "hands on" strategy using poppet beads to (presented in Section IV) it is important that the students
represent Biston betula moths [3]; Developing visual and inter have already completed a previous assignment, which was
active tutorials, such as the GATutor [4] and the Evolutionary originally suggested by DeNero and Klein. The main idea of
Algorithms Sandbox [5]; Using Japanese nanograms to teach the assignment is to use informed search methods to create an
about advanced GA features [6], [7]; and using GAs to design automatic player for Pacman.
controllers for non-player characters in games [8].
In the context of artificial intelligence education research, A. The Java Pacman Framework
DeNero and Klein [9] have used the classic video game In our classes, we use a java-based version of the Pacman
Pacman to teach several introductory artificial intelligence framework that was developed by Ted Grenager. The java
concepts. One of the advantages of the work proposed in Pacman framework runs with a textual interface by default
DeNero and Klein [9] is that the same framework, in this (Figure 1), with a graphical user interface (Figure 2) with
case using the video game Pacman, can be used for different the parameter -display gui or with no interface with the
student assignments covering different artificial intelligence parameter -display none (Figure 3). As it can be noted
algorithms and methods. The issue of how to use the same from Figure 2, this version of the game does not contain the
practical framework is an important one, because if students powerups (fruits) that allows pacman to eat the ghosts.
have to learn a different framework for every assignment they In order to execute an automated player, it is necessary
will often feel discouraged. to pass the player as a parameter to the framework using
For this reason, the main contribution of this paper is to -pacman player where player is the name of the class
present a practical assignment to teach students about genetic that has the implemented Pacman player. In order to create an
algorithm-based parameter optimization using the Pacman automated player the students need to realize (implements in
framework. In order to use the approach present in this paper java) two interfaces, namely PacmanPlayer and StateEvalua
it is mandatory that the students have already developed tor.
0 0 0 ••• 0 0 0 ••• 0 0 0 0 0 . 0 . 0 0 0 0
o . • •
• • ••• 0 0 0 0 • • •
•
o
•
• •
• • • • ••• 0 0 0 • •
0
•
•
0
•
B. Pacman as an Informed Search Problem
... ................ ...
• • 0 • • 0
0 0 0 ••• • • •• 0 0 0 0 •• • • • •
· .
· .
0 0 0 ••• • • • ••• 0 0 0 0 0 0 0 ••• • • • •
Team Framework # of Heuristics Representation Selection Cross-over Type Mutation Type Improved Results
with the GA?
1 ECl 8 Float (Diff. Ranges) Tournament OnefTwo Gauss �
2 ECl 10 Float (Diff. Ranges) Tournament OnefTwo/Any Gauss �
3 ECl 3 Integers (0 to 100) Tournament OnefTwo Reset �
4 ECl 8 Float (Diff. Ranges) Tournament OnefTwo Gauss �
5 ECl 8 Integers (0 to 100) Tournament OnefTwo Reset �
6 ECl 4 Integers (0 to 100) Tournament OnefTwo Reset �
7 ECl 8 Integers (Diff. Ranges) Tournament One Reset �
8 ECl 8 Integers (0 to 100) Tournament Two Reset �
9 ECl 8 Integers (0 to 100) Tournament One Reset �
10 ECl 8 Integers (0 to 100) Tournament One Reset �
11 ECl 8 Integers (-100 to 100) Tournament One Reset �
12 ECl 9 Integers (-100 to 100) Tournament OnefTwo Reset �
13 ECl 8 Integers (-100 to 100) Tournament OnefTwo Reset �
understand both the core concepts as well as why the standard V. EVALUATION OF THE ASSIGNMENT
GA's might need to be modified. For this reason, in our classes,
Table I presents an overview of GA-based pacman assign
we also demonstrate how the GA could be used to provide
ment evaluation. The analysis of Table I and of the reports
solutions to the Travelling Salesman Problem (TSP). The TSP
handed in by the students after they completed the assignment
in an interesting example because the individual representation
show some interesting insights.
can be based on the list of cities (one route in the TSP), there
First, all students choose to use the Java-based Evolutionary
is a clear fitness function (find the smallest route) and the
Computation Research System (ECJI). This choice might
standard genetic operators of mutation and crossover might
have been influenced by the use of the ECJ framework in
generate invalid routes. This two examples are enough, in our
one of our practical classes where the students run some
experience, to prepare the students to deal with the parameter
simulations using the max one tutorial. However, despite the
based optimization problem presented in the next section.
students familiarity with the framework, this shows that the
students decided to take a deep understanding of how the
IV. THE GA-B ASED PACMAN ASSIGNMENT ECJ framework works rather than implementing their own
AG. When we asked the students about their reason for using
In order to motivate the students and help them develop the ECJ framework, their common answer was that within
practical skills for using GAs to solve an optimization prob the framework they only needed to implement/modify a few
lem, we use the same Pacman framework that the students classes to have their assignment working. Furthermore, the
have used in a previous assignment (presented in Section II) students liked some of the built-in facilities that the ECJ
and ask the students to: framework offers, such as parallelism and the ability to create
• Design and Implement a representation that takes into and restore checkpoints.
account the search depth (only if they implemented the Second, most teams have used a vector of Integers to
Breath First and/or A * Search Algorithm with fixed represent their individuals. While some teams used only pos
depth) and the weights assigned to each heuristic. itive values (normally from 0 to 100), others allowed their
• Design and Implement at least two fitness functions to chromosomes to receive negative values as well. It should
evaluate their developed individuals. be noted that for the teams that implemented the breath first
• Decide whether or not it is necessary to modify the search and A * search algorithms, they normally encoded the
genetic operators of mutation and crossover. depth of the search as being the first gene in the chromosome.
• Design and run experiments in at least two ghost settings Furthermore, all teams that implemented the depth-limited
to evaluate: search methods took safe guard measures to not allow the use
What is the impact of changing the population size? negative or relatively high (e.g. higher than 5) values in the
gene responsible for the depth. Figure 6 presents information
What is the impact of changing the probability values
about which search methodes) were used in the GA-based
of the genetic operators of mutation and crossover?
What was the best individual found in your experi optimization of each team.
ments? Is this individual better than the solution you Third, all teams used the selection by tournament. Fourth,
found in the previous assignment? while some teams only used the one point crossover that they
learned about during the lectures, the majority of the teams
• Write a detailed report explaining everything that they
did and reporting any issues they had. I Available at: [Link]
1 1 1 1 1 111 10 1 1
. G reedy
Team 01 Team 02 Team 03 Team 04 Team 05 Team 06 Team 07 Team 08 Team 09 Team 10 Team 11 Team 12 Team 13
Fig. 6. Search methodes) used by each team in the GA-based Pacman assignment.
250000 ,-----
200000 +------
150000 +------
.Manual
.GA-Based
100000 +-----
50000
o
Team 01 Team 02 Team 03 Team 04 Team 05 Team 06 Team 07 Team 08 Team 09 Team 10 Team 11 Team 12 Team 13
Fig. 7. Comparison of the scores obtained by manuaUy adjusting the weights against the GA-based approach for each team.
also researched about the two point crossover or, in the case of their importance, different authors have addressed the issue
one particular team, the any point crossover. Figure 8 presents of how to teach Genetic Algorithms in different ways.
the crossover types percentage used by the different teams. In the work of Venables and Tan [3] the authors proposed a
Fifth, due to the representation being used (Integers in "hands on" strategy to teach genetic algorithms using poppet
all but three cases, in which floats were used), the students
also had to research how to adapt the mutation operator. For
the integers representation the students employed the reset
mutation type, which randomly changed the current value of
a gene by a random value within the gene valid values range.
Sixth, as we have requested the students to design and
implement at least two fitness functions, they all implemented
the absolute score as one of the fitness function. Figure
9 presents the percentage of the different types of fitness
functions used by the different teams. The analysis of Figure 9
shows that 31 % of the teams did not propose a second fitness
function, while the others teams used the score and the game Fig. 8. Different types of crossover used by the students.
time in different ways or the last achieved level before death.
Seventh, all teams reported that by using the GA-based
.None • level .Time .Score - Time .Score / TIme
approach, they were able to achieve better Pacman players than
.8%
the one developed by manual trial and error. Figure 7 presents
a comparison of the best scores obtained by manually adjusting
the weights against the best GA-based approach weights for
each team. .38%