• No results found

Sample Controllers for Ms Pac–Man vs Ghosts

6.2 The Competition

6.2.1 Sample Controllers for Ms Pac–Man vs Ghosts

Having implemented PO for both Ms. Pac–Man and the ghosts, new controllers were needed as examples for people entering the competition. These new controllers, and those used in the experiments in this chapter, are described here.

StarterPacman (COP)

This is the original basic controller for the previous competition and works only in Com- pletely Observable environments. This controller follows a very basic algorithm with some simple sequential rules as shown in Algorithm1. The controller will avoid ghosts that are too close, chase ghosts that are edible, or travel to the nearest pill.

Algorithm 1StarterPacman basic algorithm

functionGETMOVE() limit←20

nearestGhost←GETNEARESTCHASINGGHOST(limit) ifnearestGhost then

returnNEXTMOVEAWAYFROM(nearestGhost) end if

nearestGhost←GETNEARESTEDIBLEGHOST(limit) if nearestGhost then

returnNEXTMOVETOWARDS(nearestGhost) end if

nearestPill←GETNEARESTPILL() returnNEXTMOVETOWARDS(nearestPill) end function

StarterGhosts (COG)

This is the original basic controller for the previous competition to control the four ghosts. It is a “puppet-master” style algorithm, meaning it is a single block of logic that generates moves for all four of the ghosts. The controller follows some basic strategies if a ghost is allowed to make a move as shown in Algorithm 2. The ghosts will run away from Ms.

80 Chapter 6. The Ms. Pac-Man Vs Ghost Team Competition

Pac–Man if she is able to eat the ghost, or near a power pill (Potential to eat ghost). If the previous rule doesn’t apply then the ghost will 90% of the time chase Ms. Pac–Man and 10% of the time move randomly.

Algorithm 2StarterGhosts basic algorithm

functionGETMOVE()

pacman←GETPACMANINDEX()

ifISEDIBLE() ORPACMANCLOSETOPPILL() then returnNEXTMOVEAWAYFROM(pacman) end if

ifNEXTFLOAT<0.9 then

returnNEXTMOVETOWARDS(pacman) else

returnNEXTRANDOMMOVE() end if

end function

POPacman (POP)

This is a modification of the StarterPac–Man where each strategy is followed if it is possible as shown in Algorithm3.

Algorithm 3POPacman basic algorithm

functionGETMOVE() limit←20

nearestGhost←GETNEARESTCHASINGGHOST(limit) if nearestGhost6=NULL then

returnNEXTMOVEAWAYFROM(nearestGhost) end if

nearestGhost←GETNEARESTEDIBLEGHOST(limit) if nearestGhost6=NULL then

returnNEXTMOVETOWARDS(nearestGhost) end if

nearestPill←GETNEARESTPILL() if nearestPill6=NULL then

returnNEXTMOVETOWARDS(nearestPill) end if

returnNEXTRANDOMMOVE() end function

Other than modifying the original strategies with guards against null, it was clear that a new default strategy was needed. This is because within the PO game, it was possible

6.2. The Competition 81

to proceed through the previous strategies without returning a move. This new default strategy was to simply return a random move.

Starter Pacman One Junction

This is a starter agent added to provide a demonstration of determinising the game state and forwarding the resulting state to provide a basic one junction lookahead (Algorithm4). The state is forwarded to the next junction rather than a single step of the game as this was considered to be too small a distance between decisions.

Algorithm 4Starter Pacman One Junction algorithm

functionGETMOVE() bestScore←-1 formove : MOVES do

score←EVALUATEJUNCTIONINDIRECTION(move)

ifscore>bestScore then bestScore←score bestMove←move end if

end for

returnbestMove end function

POGhosts (POG)

This is a modification of the StarterGhosts where each strategy is followed if it is possible in the PO case. If there is no information available to the ghost, then the ghost will behave randomly at intersections as shown in Algorithm5.

POCommGhosts (POGC)

This is a modification of the POGhosts that attempts to communicate each tick in order to improve its chances. If this ghost can see Ms. Pac–Man then it will send a message to everyone else. If it can’t see Ms. Pac–Man then it will check if anybody else has seen it. If someone else has seen Ms. Pac–Man then it pretends it can see Ms. Pac–Man and follows the original POGhosts strategy outlined above. The pseudo code for this is shown in Algorithm6.

82 Chapter 6. The Ms. Pac-Man Vs Ghost Team Competition

Algorithm 5POGhosts basic algorithm

functionGETMOVE()

pacman←GETPACMANINDEX() ifpacman then

ifISEDIBLE() ORISPACMANCLOSETOPOWERPILL() then returnNEXTMOVEAWAYFROM(pacman)

end if

ifNEXTFLOAT<0.9 then

returnNEXTMOVETOWARDS(pacman) end if

else

returnNEXTRANDOMMOVE() end if

end function

Algorithm 6POCommGhosts basic algorithm

functionGETMOVE()

ifPACMANINFONEEDSRESET( GETCURRENTTICK() ) thenRESETPACMANINFO() end if

pacman←UPDATEPACMANLOCATION() HANDLEMESSAGES()

pacman←GETPACMANINDEX() ifpacman6=NULL then

ifISEDIBLE() ORPACMANCLOSETOPPILL() then returnNEXTMOVEAWAYFROM(pacman) end if

ifNEXTFLOAT()<0.9 then

returnNEXTMOVETOWARDS(pacman) end if

else

returnNEXTRANDOMMOVE() end if

end function

The threshold used to determine when to forget Ms. Pac–Man’s location needs tuning. Every value from 0 to 200 was put to a test on 4000 games against the COP agent and 33, 300 games against the POP agents. The results are displayed in Figure6.1 and show that the value of 50 is a good value against these two agents. Interestingly the data against the POP algorithm is significantly noisier than COP. This is presumably due to COP being deterministic and POP being non-deterministic.

6.2. The Competition 83

FIGURE6.1: Tuning results of POGC against COP(Left) and POP(Right) both with error bars.

Related documents