

This is a simplistic approach, just to get the ball rolling, ideally we would implement the logic as in the original arcade game. The direction must be valid and if both a horizontal and a vertical direction is valid it uses dynamic salience to pick the one with the highest difference. The implementation currently uses a simple distance diff from the Monster to the Pacman to determine the Monster direction. $monLoc : Location( character = $mon, col = $l, row = $pacLoc.row )ĮxitPoints.insert( "Killed!!!! score = " + $s.score + " n" ) rule MonsterCollision dialect "mvel" no-loop when Modify( $l ) Īmong other things it’s also looking out for Monster collisions. Insert( new ScheduledLocationUpdate($l, $l.row += $d.vertical,ĮxitPoints.insert( "set new Location " + $l + "n" ) Not ScheduledLocationUpdate( location = $l ) $target : Cell( row = ($l.row + $d.vertical), col = ($l.col + $d : Direction( character = $l.character ) The rule makes sure the new Location is valid, and if so schedules the move to the new Location, in time with the Tick. $oldD : Direction( character = $l.character )ĮxitPoints.insert( "insert " + $newD + "n" ) Īs the Tick, simulated time, increases we attempt to change a Character’s Location based on the given Direction. $target : Cell( row = ($l.row + $newD.vertical), col = ($l.col + $newD.horizontal) )ĬellContents( cell = $target, cellType != CellType.WALL ) $newD : Direction() from createDirection( $l.character, $keyEvent ) $keyEvent : KeyEvent() from entry-point "KeyListener" The exitpoint is used to send print information to a channel, which is appended to the GUI. If the new Direction is valid the old Direction is retracted and the new one inserted. From the KeyEvent it creates a derived (not in WorkingMemory) possible Direction and validates that Direction. The rules are split into four drl files base, key-handlers, Pacman and Monster.Ī KeyListener implementation is hooked up to a WorkingMemory EntryPoint and feeds in key presses. The arrow keys move Pacman around and the Monster tracks the Pacman. When the game starts off Pacman is in the lower empty cell and the Monster in the top empty cell. The grid is loaded from a text file that uses symbols to map the layout, currently I use a very simple layout that looks like this: * * * * * * * * * * * The basics are now in place, in that I can load a grid and guide a Pacman around it with a Monster (Ghost) tracking it. In the interests of finding a fun and more complex problem with multiple things happening, I decided to start writting a Pacman implementation.
