Teaching Artificial Intelligence with Pac-Man

madbrainedmudlickΤεχνίτη Νοημοσύνη και Ρομποτική

20 Οκτ 2013 (πριν από 3 χρόνια και 9 μήνες)

108 εμφανίσεις

Teaching Artificial Intelligence with Pac
-
Man

Dr Jim Smith

Department of Computer Science and Creative Technologies

University of the West of England

james.smith@uwe.ac.uk


Abstract

We describe a series of resources and practical exercises supporting the teaching of
introductory topics in Artificial Intelligence using the metaphor of the well
-
known arcade
game “Pac Man”. They are aimed at level one students from a range of disciplines

and
promote

a view of Artificial Intelligence as a means of automating the problem solving
process. The first set of exercises start with search strategies and gradually build up via rule
-
based and expert
-
system approaches to create a Pac
-
Man player based

on “traditional AI”.
Subsequent
ly

artificial neural networks and evolutionary computation provide a radically
different approach to generating and improving controllers
. Throughout, the stud
ents gain
experience of formalizing their approaches to problem
-
s
olving, coding,

a
nd working with

a
range of AI techniques.

Keywords
: Artificial Intelligence, Problem
-
solving, search, expert systems, neural net
works,
evolutionary computation

Aims

The primary aim of this project is to
facilitate
engagement and the teach
ing of A
rtificial
Intelligence (AI)

by providing a

lively and
easy to understand set of tutorials covering the
major topics in an introductory course.

The resources
developed aimed to:



E
nhance the

student learning experience by

providing them with early ex
perience in
programming and building their own artificial agents that do something concrete, and
provide opportunities for reflection on their own problem
-
solving behaviour.



A
ssist in the incorporation o
f AI topics into other courses
. Documentation of

the activities
includes links
to reading materials, and open educational resources such as lecture notes
and self
-
assessment tests to produce a suite of e
-
learning activities
. Most of these

could
be used in isolation to teach specific topics.




Support ac
ademic staff by producing a coherent set of activities. Current approaches to
teaching AI
often appear rather fragmented
, especially in terms of using consistent
examples. This is because
,
it

can be hard to find examples to illustrate different concepts
an
d techniques which are sufficiently complex to illustrate the need

for A
I, yet don’t
require excessive time spent describing each individual problem.



P
romote widening participation
, and learning at work

by supporting learning of AI in a
structured and se
lf
-
paced manner beyond the traditional modes of delivery.



Enhance the quality of provision by enriching the range of teaching activities and
materials used.

Outcomes

The outcomes of this project are a set of structured activities to be undertaken in the ag
ent
-
based
environment NetLogo [
Wilensky 1999
].
These

activities could be done by students
singly
(possibly remotely)
or in groups,
with findings and insights shared in
a “wrap
-
up”
discussion at the end of each session.
Each activity
is supported by
: (i)

a

netlogo s
cript (
with
inbuilt instructions for the students
)

and
(ii)
a
text

file with details for the course tutor. This
sup
porting file (in .rtf format)
details the speci
fic rationale for the activity,

and provides
some

pointers to guide the “wrap
-
up” d
iscussion at the end of the activity. It also details the
other

files involved (e.g. netlogo scripts, netlogo “world models”, training/test data),
and
provides full instructions for the students
. These
can be copied into paper documentation, a
V
irtual
L
earning
E
nvironment (VLE)

or onto a web
-
page depending on the mode of delivery.

The materials for

each

activity are kept in separate directories
. A

top
-
level “readme”

file
describes the activities

and provides links to a range of additional materials
hoste
d on
JORUM. These include
lecture slides, and self
-
assessment tests that can be imported into
the Blackboard VLE.

These materials and activities have been developed and successfully
deployed during the academic year 2009/10 at UWE, Bristol.

Methodology:

T
his project built

on a range of prototype
tutorials
developed
by Doctors Smith and Cayzer
during
October

2009
-
10

as
part of the

UWE
-
funded project
“Development of interactive
small group tasks embedded within larger group tutorials”
. That project
concerned

the
pedagogical aspects of using different
-
sized group activities

within a

single session, and
many of the activities were tried with group sizes varying between 2 and 20. This usefully
provided additional staff to support the tutorial sessions while the

scripts were

being
developed. The materials

were used in the module “
Introduction to Artificial Intelligence”
,
which has a cohort of 150 taught in three tutorial sessions. This allowed for comparison of
alternative versions of scripts and rapid refinement

between tutorial sessions.

The syllabus for

the first semester is “traditional AI”


covered in the activities
“intro
-
search”

and
“knowledge representation”
.

The
activities can b
e broken into three broad
types: (i) I
nteractive activities

-

such as

guidi
ng a pac
-
man around a maze, or creating
“edible” and “inedible” ghosts. T
hese

are designed to encourage thinking about, and
describing
, cognitive processes, and

have the addition
al benefit of providing
light r
elief

for
those students

who find coding troublesome.

(ii) Formalising and coding activities (e.g.
depth
-
first search strategies, expert systems). Students
creat
e

their own
rule
-
based
code
from a range of pr
e
-
supplied primitives
, then
run
and refine

it in
side

supplied netlogo
scr
ipts.
(iii) “Selective uncommenting” activities. These are
designed to aid

understanding
the difference between alternative strategies or techniques
. Students

select appropriate
statements to co
m
ment and uncomment within

netlogo script
s

to achieve desired

goals


for example

different search algorithms

.

Informed by
weekly
Blackboard access statistics,
notes from post
-
tutorial discussion
between staff,
and feedback from the students, the project start
ed

with a thorough
examination of what aspects of the i
nitial materials worked well, and/ how they could be
improved.

The findings were generally positive
. A
ttendance at tutorials sessions w
as

significantly higher than in previous years



for example over 75% at 5:30
-
7pm

session in
mid
-
December. I
nformal feedb
ack from both staff and students was in favour of the
materials.
It was agreed that the mixture of different types of activities worked well
. Since
this w
as a level 1 module there was
initially a wide range of experience of, and

attitudes
towards, program
ming. I
t was felt that mixing “coding” with “uncommenting” and
interactive

activities provided a good breathing space and a chance for the less confident
students to catch up
, while providing adequate challenges

for th
e more confident
.

A conscious
decision w
a
s

taken at this stage to trial more “GUI” based activities in the
second semester
. For example
,

the final Evolutionary Computing activity
involves

des
ig
ning

the rep
resentation, the Genetic Algori
thm, and the fitness function, to evolve a maze
solver,
but this is mediated
via buttons /sliders rather than by

editing scripts
.

Deliverables

The project deliverables include the scripts and documentation referred to above, two
conference publications [Smith

2009, Smith and Cayzer 2010] and this repor
t. The first set
of four activities uses the metaphor of exploring a maze/graph with Pac
-
Man to illustrate
the concept of learning as search
. Two interactive activities focus on recognising, expressing
and formalising human strategies. The third activitie
s codes depth
-
first search and in the
final students select appropriate statements to implement and compare the time and space
requirements of other heuristics including best
-
first
, breadth
-
first, hill
-
climbing,

and A*.
This
is illustrated

in Figure 1.

Th
e next four activities concern knowledge representation, logic,
rule
-
bases and expert systems.

Starting with an interactive exercise designing and
describing “ghosts”, these exercises grow in complexity until in the final one the students
synthesise

code
they have developed
previously

to cr
e
ate their own
automatic pac
-
man
player.

There are two more “GUI
-
based” exercises for each of artificial neural networks and
evolutionary computation in which students apply relevant technology to create systems
that res
pectively recognise ghosts, and evolve rules for maze negotiation.

More details
may

be seen in [Smith 2009, Smith and Cayzer 2010],
and in the appendices.



Figure 1: Left: Screenshot of Breadth
-
first search.

Current p
acman is coloured yellow. Two other pacmen at
same depth are white, three at the next depth is
red. Some pacme
n are slightly overlaid. Right:
code
fragment
. Students can

create different search strategies

by uncommenting different statements
.

The benefits of adopting these resource are that they provide a sound basis for gaining
practical experience

and understanding of the basic elements of AI, using a well
-
understood
application (Pac
-
Man) that provides a rich source of sub
-
problems to tackle and metaphors
to extend. Moreover, it does this within a lightweight software tool that is well
documented
, user
-
friendly, and free. The scripts are easy to extend and customise by either
tutors or students. In particular, tutors can easily provide “primitives” to hide the coding
...

if need
-
to
-
pick
-
another
-
pacman?

[

set current
-
pacman
-
id get
-
oldest
-
pacman

;;set current
-
pacm
an
-
id get
-
youngest
-
pacman

;;set current
-
pacman
-
id get
-
closest
-
of
-
all
-
pacmen

;;set current
-
pacman
-
id get
-
furthest
-
of
-
all
-
pacmen

;;set back
-
tracking
-
allowed? FALSE

;;set current
-
pacman
-
id get
-
closest
-
child
-
of
-
last
-
parent

;;set current
-
pacman
-
id get
-
oldest
-
ch
ild
-
of
-
last
-
parent

;;set current
-
pacman
-
id get
-
youngest
-
child
-
of
-
last
-
parent

update
-
parent
-
id

]


complexity for less experienced students. Thus for example students can create de
pth
-
first
search out of construct such as “
if (wall
-
ahead?)
” or “
turn
-
left
” and the supplied scripts
handle the pac
-
man movement and the rest of the game. At the same time, the richness of
the environment provides plenty of scope (and suggestions are pro
vided) for keener or
more able students to develop more complex algorithms or extend the game scenarios.
Finally, the NetLogo package comes with an ever
-
expanding set of existing models
that

provide additional resources for covering materials such as swar
m int
elligence,
meta
-
heuristics, and emergent phenomena.

Background

Systems containing some kind of Artificial Intelligence (AI) form the state of the art in many
applications of computing, across the spectrum of social and economic activity,
and t
he
futur
e is certain to contain more, rather than less such systems
. Moreover, since AI
fundamentally concerns itself with problem solving, it should provide an ideal medium to
explore issues and provide generic transferable skills.
Despite this, many undergraduat
es
view AI as a rather dry subject matter, a situation that is not helped by many of the learning
exercises to be found in textbooks and on
-
line coursework materials. Several authors have
attempted to address these
using robotics
-
based tutorials [Kumar and

Meeeden 1998,
Karapetsas
and Stamatis

2008, Parsons and Sklar 2004]

but these tend to be specific to
certain aspects, and often require programming skills beyond a typical level one student
.
More importantly, a series of

informal conversations with curren
t and potential students
revealed a view of anything using robots as somewhat “techie” and off
-
putting. Certainly
there is a concern that they can reinforce a view

of AI as primarily relevant to

robotics
rather than to all disciplines within computing.

A s
econd problem facing the would
-
be
teacher of a general course on AI is that books are often specialised, and/or often use
different examples, and different software to illustrate and teach different types of AI. This
raises issues where either students fa
ce the overheads of learning many different software
packages, or are required to code their own algorithms, which risks turning AI classes into
cod
ing tutorials. This analysis le
d to the identification of the following “wish
-
list” to which
any new set of
activities should adhere:



Use of a “metaphor” which is well
-
known and like
d across a range of backgrounds;



Emphasis on problem
-
solving skills that can inform and assist other topics.



Use of a common programming environment, supporting tutor
-
provided
scripts /
functi
ons to create a “naturalistic”
style of programming with as low
a learning overhead
as possible;



Coverage of the syllabus elements of search strategies, rule
-
based systems, expert
-
systems, artificial neural networks, evolutionary computati
on and swarm inte
lligence
(multi
-
agent systems);



Use of a free, lightweight, and simple to install software environmen
t, p
referably one
that also contains or supports a range of other examples to stimulate the more able
students
.


These materials were developed for the UWE level one module “Introduction to Artificial
Intelligence”. This module is compulsory on several degrees such as the BSc’s in Computer
Science, Robotics, and Games Technology, and optional on several others. The s
yllabus of
the module is fairly conventional. In the first semester the students briefly cover
“philosophical issues” such as Turing’s test, and Searle’s Chinese Room problem, but
primarily as a means of focussing on what “AI in practice” can or might invo
lve, in
opposition to what Hollywood might portray. From there a number of scenarios (driving a
car unaided, acting as a tour guide, playing table tennis) are used to highlight how “AI”
behaviour can be broken down into groups of related tasks, and the “in
put
-
model
-
output”
paradigm of computing is used to group these and introduce the idea of all learning as a
search through a space of possible inputs (or sequences), models, or outputs. The formal
lectures then move on to cover blind and informed search str
ategies as means of
automating search (depth
-
/breadth
-
/best
-

first, hill
-
climbing, A*) then knowledge
representation: moving through first order logic and rule
-
base systems, via expert systems
to the Semantic Web.

Semester two starts with by recapping the

idea of learning as search, the three principle
classes of search space and some examples of relevant Machine Learning technologies, and
then covers three areas in more depth. The first is Artificial Neural Networks: perceptrons
and simple Multi
-
Layer Pe
rceptons with back
-
propagation as a hill
-
climbing search method.
The second is Evolutionary Computation as a general
-
purpose search method, illustrated by
Genetic Algorithms for optimisation and Genetic Programming for model building. Finally
the cellular
Genetic Algorithm is recast as an emergent process and used to introduce the
topic of “swarm intelligence” illustrated by optimisation (Ant Colony Algorithms), model
building (ant
-
based clustering) and simulation (“Boids” [Reynolds 1987]).

The majority of
the activities designed to support this learning had the students working in
groups of three or four. Typically, after the task was introduced, everyone would be asked
to think about it individually for five minutes before the group activities commenced
.
S
essions ended with a

“wrap
-
up” discussion w
hich saw

the groups working together either
in competition or collectively to come up with ideas how this work could be used to solve
some larger task.

Putting it into Practice

In practice at UWE these were deplo
yed alongside a range of non
-
computer
-
based
activities, such as our own “Turing test”,
solving Logic puzzles,
the “human perceptron” and
the “human Genetic Algorithm”. All were deployed in large (~60) group tutorials, where
we made extensive use of “pyr
amiding”.
Frequently students would begin

in large groups to
d
ecompose problems, then work
in pairs on different elements before coming together to
synthesis complete solutio
ns and discuss their findings.

Many of the activities naturally lend
themselves t
o friendly inter
-
group competition. While this can be motivating it does of
course risk stratifying a class. Therefore the students were frequently asked to “self
-
organise” into groups of mixed ability


with the added benefit that this provides for
disc
ussion of different methods for clust
ering

and /or sorting data. Probably most
important is that time was allowed at the end of each session for a “wrap
-
up” discussion
where the specific iss
ues encountered were explored,
put into the wider context beyond
Pac
-
Man
,

and grounded via reference to the staff’s current research projects. These were
documented in a discussion forum, with all the relevant s
cripts etc. attached to provide

a
resource the students could return to.

Specific details of how these activi
ties were used can be found in [Smith 2009, Smith and
Cayzer 2010], extracts from
which are provided in Appendix 2
.


Embedding

This module is taught by a combination of weekly lectures, 90 minutes large group tutorials,
and directed self
-
study via the pro
vision of additional reading materials, videos, podcasts
and weekly online self
-
assessment tests. The materials produced in this project now form
the core “hands
-
on” activities

for the tutorial session,

augmented by some larger group
activities such as tho
se mentioned in the previous section
.

These were used for the firs
t

time in the year 2009
-
10. In future years it is anticipated that
we will extend the range of activities to include other
NetL
ogo models illustrating
techniques such as swarm intelligence,

and look at evolving more comp
l
e
x P
a
c
-
M
an
controllers. Ultimately the goal would be
to

end the year by holding
competitions between
human, “expert sys
t
ems”, neuro
-

and evolved

controllers.
As we build up a repository of
student work and scripts, we will

make these available as a resource to the students. We
will also examine their use in other ways


for example by developing exercises where the
students critique different versions of expert systems
for efficiency, clarity, and
maintainability.


From th
e next academic year these resources will also be used in a sister organisation to
UWE, providing a valuable source of feedback and information to ensure that the
sustainability is not limited by the presence and enthusiasm of one tutor.

Benefits

The devel
opment of these materials has benefitted the staff involved by providing a fresh
look at how we can find and illustrate examples of AI in practice. It has led to far more lively
and stimulating tutorial sessions, which have been much better attended.
This

has been
reflected in increased engagement, lower drop
-
out rates and higher pass
-
rates
,

when
compared to the previous three years since this module was rewritten and made ”core” to
most computing
-
based degrees at UWE.

Most importantly, many students were

visibly emp
owered

by their achievements.
T
he
majority started with no coding experience, and were obviously daunted whe
n,
in

the first
session we said they would be produced an AI
-
based

Pacman player by Christmas.
The vast
majority completed this by early December, and were justifiably proud of their
achievements. We confidently expect a follow
-
on benefit in terms of their attitude towards
designing and coding systems.

Student’s Views

As detailed in the methodology

section, students


opinions were used to drive the review of
the original materials and the development of the second semester’s activities. Views were
gather
ed by: informal conversations,
use of authored and anonymous on
-
line discussion
fora ( provided

at b
oth a module and award level) , timetabled

staff
-
student award group
meetings,
and via anonymous end
-
of
-
year module review and co
mment forms. This
feedback
was overwhel
mingl
y positive
.

Impact

As detailed in the “benefits” section the evidence suggest that incorporating these materials
has had a highly positive benefit on the student outcomes.
Unfortunately i
t is not
meaningful to compare average examination marks. Previously a mixed exam cover
ed both
practical problems solving exercises (eg. Logic problems) and knowledge of core material.
This year the former was extended and moved into two coursework assessments to
complement a shorter examination.

Feedback gathered by the means above suggests

that the students found the materials
relevant and enjoyable, and appreciated the use of a familiar metaphor to illustrate
different aspects and techniques of AI.

Issues and Debates

Most of these issues have been dealt with earlier in the report. The ma
jor ongoing issue
concerns the relative strength of GUI
-
based versus coding exercises. Given the timetab
ling
of hand
-
in

dates for other modules, it is probably unwise to draw firm conclusions from one
year, but the impression gained is that in fact askin
g students to edit scripts may lead to
more engagement. This may result from the large number of “point
-
and
-
click”
demonstrations applets etc. available on the internet. Certainly the documentation and
activities in the deliverables for
Artificial

Neural

Networks
, and Genetic Algorithms are now
far more
prescriptive

in nature
than the original versions produced. It was
found students
needed far more guidance to
lead them towards meaningful exploration of issues as
opposed to just

“playing” with the to
ol
s.

This contrasts quit
e heavily with the experience of
the more “coding” type activities.

Bibliography

Kumar, D, and Meeden, L. “A Robot Laboratory for Teaching Artificial Intelligence”,
Proceedings of the Twenty
-
ninth SIGCSE Technical Symposium on Comput
er Science
Education (SIGCSE
-
98), Daniel Joyce, Editor, ACM Press, 1998.

Karapetsas , E. and Stamatis, D., “Teaching AI Concepts Using a Robot as an Assistant”, in
Fasli, M. (ed.) Proceedings of the 4th Artificial Intelligence in Education Workshop,
Cambr
idge, UK. HEA
-
ICS, 2009.

Parsons, S. and Sklar, E. Teaching AI using LEGO mindstorms, Proceedings of the AAAI Spring
Symposium on Accessible Hands
-
on Artificial Intelligence and Robotics Education, Stanford,
2004.

Wilensky, U. NetLogo. Available from htt
p://ccl.northwestern.edu/netlogo. Center for
Connected Learning and Computer
-
Based Modeling. Northwestern University, Evanston, IL.
1999

Smith, J.E. “Re
-
usable Online Assessment Materials for Teaching Artificial Intelligence” in
Fasli, M. (ed.) Proceedings

of the 4th Artificial Intelligence in Education Workshop,
Cambridge, UK. HEA
-
ICS, 2009.

Reynolds, Craig (1987), "Flocks, herds and schools: A distributed behavioral model.",
SIGGRAPH '87: Proceedings of the 14th annual conference on Computer graphics and
interactive techniques (Association for Computing Machinery): 25
--
34,
doi:10.1145/37401.37406, ISBN 0
-
89791
-
227
-
6

J.E.

Smith.
Learning Through Programming Games: Teaching AI with Pacman and Netlogo.

2009. in
Proc 5th UK Conference on AI in Education
. Highe
r Education Academy Information
and Computer Sciences Subject Centre (HEA
-
ICS).

J.E.

Smith and S.

Cayzer.
Teaching Problem Solving and AI with PacMan.

2010. in
Proceedings of the 11th Annual Conference on the Teaching of Computing,

pages in press.
Higher Education Academy Information and Computer Sciences Subject Centre (HEA
-
ICS).





Appendix1: NetLogo

and PacMan

The Netlogo environment is an open
-
source multi
-
platform package for developing and
running simulations of multi
-
agent s
ystems. Based on a variant of the logo programming
language, it combines a simple interpreted scripting tool with an interactive interface for
running, pausing and manipulating scripts. Scripts can also be saved as applets embedded in
a web page containing

the instructions. Netlogo has been used for both research and
teaching in a range of disciplines covering the physical sciences, sociology, economics etc. A

screenshot is shown in Figure 2
.
In addition to the very well written, user
-
friendly
environment,
Netlogo has the advantage of a small language and syntax, and great
extensibility. Thus the students only need to learn how to use Boolean constructs (which
end in “?”), and the syntax of if, ifelse, while and foreach.
By writing
suitably named
procedures

the tutors

can hide a
ll the rest of the detailed syntax and coding niceties

such as
list

operations, observer functions,
and
exception handling
.


Pac
-
Man is a classic arcade game in which the player steers a character (the pacman)
around a maze eating pell
ets of food and trying to avoid a number of mobile “ghosts” which
attempt to eat the pacman


reducing the number of “lives” left. As extra complications
“power pellets” temporarily change the appearance of the ghosts, rendering them edible to
the pacman.

While conceptually simple, the game involves search (finding the valid paths to
uneaten pellets), classification (recognizing the edibility of ghosts), tasks hierarchies
(avoiding being eaten) and planning (e.g. not eating the “power pellet” if no ghosts
are
within range).



Figure
2
: Screenshot of Netlogo PacMan model. Note tabs for switching between interface, Information
and scripts (Procedures).

Appendix 2: Description of Deployment at UWE

Introduction to

Problem Solving as Search

In order to
accustom the students to the idea of blind search, how people use memory and
clues, and how making assumptions can help search, the first tutorial takes the form

of an
interactive applet which

presents the students with an initially blank grid

and asks the
m to
manoeuvre the pacman to find a gold square. T
he students are encouraged to write down
the strategies they are using
, and a
n on
-
screen
display

of the number of moves taken

form
s

a natural basis for competition and comparing strategies. One powerful teaching tool is the
ability to toggle the maze’s
visibility
, either by displaying a limited ‘window’ around the
pacman, or by simply displaying the whole maze at all times; the latt
er allowing strategies
which employ ‘look ahead’. Another equally important parameter is
memory
. T
his is
achieved by colouring visited cells green
,

and hence facilitating movements that prioritise
unexplored directions. The students were asked to formalis
e how these factors af
fected
their planning strategy, and to

document their “solution” online sufficiently unambiguously
that another group could follow it.

The role of the tutors in these sessions is critical to it becoming more than just a play
session.

We used two or three tutors per session, who moved between the groups asking
questions, prompting and commenting. The other factor critical to success is the use of a
twenty
-
minute “wrap
-
up” session with plenty of student interaction. During this stage a

number of common points should be drawn out and then related back to the more formal
language of the lectures. As mentioned above, this module is core to several different
degrees, so in addition to the obvious points about memory and the value of heuri
stics (e.g.
most students do “turn towards the middle”) the exercise could facilitate discussion tailored
to different degrees


e.g. global vs
.

local models for Robotics students, storage and run
-
time analysis for Computer Science students etc. At the end

the students are asked


In the second session the students are asked to modify the scripts from the first tutorial to
implement either depth
-
first of bread
-
first search. The scripts are heavily commented to
show where the new automated code should go. Th
ey are provided with examples of “if”,
“if
-
else” and nested versions of these, to aid them with syntax. Most importantly, they are
give
n a

set of primitive constructs from which to build their code. These include Boolean
tests (e.g. “
can
-
turn
-
left?”, “wa
ll
-
ahead?”
) and functions to turn the pacman (“
turn
-
left”,
“go
-
ahead”, “turn
-
around”, “turn
-
north
”,…). The surrounding code deals with the
movement of the pacman, so their code only needs to decide which way the pacma
n should
face at each timestep.

Most s
tudents correctly identified their previous wall
-
following strategy as a version of
depth
-
first chose to implement that, and recognise
d that they should use relative

rather
tha
n global co
-
ordinate systems. They were given various

mazes so that the more abl
e
students could think about how to modify their code to cope with recursive or looping
mazes. Most groups successfully built the controller to navigate the loop
-
free maze.

In session three t
hey are then shown a new Netlogo script in which, rather than a s
ingle
pacman moving around the web, the current pacman moves along the maze to the next
junction whereupon it spawns one child facing along each unexplored path (if there are any)
and then dies, whereupon a decision has to be made which of the extant pacme
n to move
next. Each pacman contains variables recording their “depth” and the initial
“distance_to_goal”. This latter records the Euclidean distance to the goal, which is of course
not necessarily the “path” distance but it is at least an optimistic heur
istic, which is a
prerequisite for the optimality of A* search. Manhattan distance is another

alternative that
can be used
. All these details can be hidden from the students but are available for
dis
cussion if appropriate. Figure 1

shows a screen shot of b
readth
-
fi
rst search with this
model, and

the
relevant
code

fragment
.
T
he
learning task is to apply the conceptual ideas of
search to this particular scenario and thus

create implementations of depth/breadth and
best
-
first search, Hill
-
Climbing and A*. A nu
mber of mazes are provided, and an informal
competition between the groups encourages experimentation. At the end of these sessions
all groups had working implementations of procedures that could be built into a final
pacman controller to provide different

search mechanisms, and some understanding of the
characteristics of each search method.

Knowledge Representation

The decision to ask the students to build a controller that decided which way to face at each
timestep, while hiding the looping and movement
phases, allowed a deliberately focus on
conditional logic. Once the lectures move on to consider knowledge representation, rule
-
based and expert systems this is further extended in a series of exercises which build on this
rather stylised form of propositi
onal logic.

In the first exercise the students are asked to create and save new ghost shapes

in
netlogo’s
“turtle shape editor”
, then

to create some classification rules that will assign this ghost
shape to the class “edible” or “inedible” based on visib
le characteristics. They are asked to
add the ghost details into a “world map”
-

a spreadsheet
that contains

maze and ghosts
characteristics. They need to instantiate new ghosts, label them as edible or inedible and
finally create new attributes describing

their ghosts. The students are also provided with a
script, which loads the map and calls a stub function that classifies each ghost in turn. The
primary learning task is thus to write the code that correctly classifies all the ghosts.
Depending on how th
e ghosts are labelled, and the number of attributes used in the
classification rules, this activity provides scope for discussion of rule
-
hierarchies, default
rules, disjoint and conjoint logic.

Of course there are many equivalent ways of doing this,
provi
ding scope for a “wrap
-
up” session where the different versions produced by students
are shown to be formally equivalent.

T
he
penultimate

set of tutorials focussed on the specification, creation and maintenance of
expert systems. Using the maze from the pr
evious tutorial, the students were asked to
devise a set of rules to
control the Pac
-
man
using a

range of (supplied) primitives
. Choice
functions include returning a set of directions to test
and c
ondition clauses include simple
tests (clear, safe), ones t
hat involve lookahead (ghost ahead), classification (edible ghost
ahead), heuristics (nearer to edible ghost) and memory (unexplored). Higher level planning
for the more advanced students was provided through the use of route planning (choose
next edible
ghost). The rule production was done as a “pyramiding” activity


each member
of the group was asked to come up with single rule describing a particular situation, and
then the group collectively refined the combined rule set and implemented it


iterati
ng as
necessary to achieve the desired behaviour. The groups were free to use the procedures
provided, or any other ones they had developed or used previously.

In the final practical of this section, the students were invited to put their classification,
s
earch and expert system work together in a series of provided mazes, with challenges such
as dead ends and moving ghosts. Supporting material has been made available for
motivated students to extend this work into the full pacman game with pellets and powe
r
pills.
As hoped, t
his activity provided a valuable experience in the “naturalness” of expert
systems, but also of the difficulties of ensuring correctness and maintaining the rule bases. It
also showed how increasing levels of knowledge could be built in
to rules that deal with
environments at a range of complexities. The classification, expert system and route
planning activities also showed how AI techniques could be employed at different levels of
abstraction.

Artificial Neural Networks

The lectures f
or this topic cover the use of perceptrons as a stylized representation of the
action of biological neurons, Hebbian learning, and the strengths and weaknesses of single
perceptrons


e.g. the XOR problem. They move on to cover simple multi
-
layer perceptr
ons
(MLPs) and back
-
propagation. Among the set of models that come provided with Netlogo
are a simple perceptron and a three
-
input, two
-
hidden node MLP. These come with
train/test routines for learning and testing simple functions such as or/and/xor. A
p
articularly nice feature is that the values of the weights are shown graphically by varying
the width of the link between nodes.

Next, u
sing training and test sets built from varia
tions
on the set of four ghosts
, students learn how these formal functions relate to practical
problems by showing that neural networks are capable of learning rules that correctly
classify ghosts.
A range of exercises, and careful placement of (static) ghosts on mazes is
used to illust
rate issues such as over
-
fitting, problems of feature selection/sparse datasets.

Evolutionary Computation

Like many agent
-
based systems, netlogo comes complete with a model of a simple genetic
algorithm using one
-
point crossover, bitwise mutation and fitne
ss
-
proportionate selection
to evolve a solution to the binary “OneMax” problem, where the fitness is simply the
number of bits in a string.
The students begin with a structured series of exercises, using
s
liders in the interaction tab
to explore
the effect

of changing
population size,
selection
pressure, mutation and crossover rates

so as to illuminate the effect and value of these
operators and settings. The second exercise uses a fitness function that periodically switches
between “OneMax” and “ZeroMax”.
Students are asked to first design on paper, and then
evaluate, strategies which maximize the response time, and time
-
averaged vales of the
mean and maximum population fitness. This aids discussions of issues such as the need for
multiple runs with stochas
tic algorithms

The final set of exercises concerns the task of designing an EA that will evolve a controller
for a Pac
-
Man to find the “gold” in a maze. Solutions are

interpreted as
a set of rules
governing motion, so a
t each time step the “state” of the
neighbourhood is queried and
t
he
evolving solution is

queried to provide the relevant action.
The students are given a choice
of two representations


in the first the “state” is the timestep


so a solutions is
represented as a sequence of moves. In the
second, the state is inferred from the Pac
-
Man’s current location and orientation, so the
binary representation for this problem is a
Pittsburgh
-
style
classifier system. The occupancy (wall/empty) of the three squares (left,
ahead, right) provides for 8 s
tates, which with four directions requires a sixteen
-
bit
representation. The extension to consider ghosts etc is trivial.
Students must also

select
appropriate
GA oper
ators and
parameters for their chosen representation.

The final design decision requir
es the students to create a fitness function based on
weighting factors such as final distance from goal, number of cells explored, the reward for
reaching the goal, and the number of steps taken to reach it. In practice most explored both
representations,

and the particular choice of maze nicely illustrated issues such as over
-
fitting


the rule based version first “evolved” depth first, then “refined” it to exploit
characteristics of the specific maze used.