<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
The example has been updated to have a monster in it that tracks the
Pacman's location, going in for the kill. I've done a blog that tracks
my progress to date.<br>
<a class="moz-txt-link-freetext" href="http://blog.athico.com/2009/11/drools-does-pacman.html">http://blog.athico.com/2009/11/drools-does-pacman.html</a><br>
<br>
Mauricio Salatino wrote:
<blockquote
 cite="mid:efac615a0911160559j39175553hf45e3f11eaaa68c@mail.gmail.com"
 type="cite">heh.. nice.. I will add the Wii mote (<a
 moz-do-not-send="true" href="http://en.wikipedia.org/wiki/Wii_Remote">http://en.wikipedia.org/wiki/Wii_Remote</a>)
support for that game, it's pretty easy. I have an example working.<br>
  <br>
  <div class="gmail_quote">On Mon, Nov 16, 2009 at 11:55 AM, Mark
Proctor <span dir="ltr">&lt;<a moz-do-not-send="true"
 href="mailto:mproctor@codehaus.org">mproctor@codehaus.org</a>&gt;</span>
wrote:<br>
  <blockquote class="gmail_quote"
 style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">For
anyone interested i just did an initial commit for the rudementary<br>
implementation parts for a Pacman game. Loads a Grid &nbsp;and a Character<br>
into the working memory and listens to the arrow keys to move the<br>
Character around (text output only). It only accepts valid directions<br>
and the Character cannot move off the grid, and score is updated as it<br>
eats Food.<br>
    <br>
It also demostrates entry and exit points. For instance this rule has<br>
it's "KeyListener" entry point hooked up to a KeyListener impl that<br>
inserts KeyEvents. From the KeyEvent it creates a Derived (not in<br>
working memory) possible Direction, validates that Direction. If valid<br>
the old Direction is retracted and the new one inserted. I use the<br>
exitpoint to send print information to a channel, which is appended to<br>
the GUI.<br>
    <br>
/**<br>
&nbsp;* Detects a new keypress (release). Creates derived possible Direction<br>
and validates it.<br>
&nbsp;* If the Direction is valid, delete the old Direction and replace with<br>
the new one.<br>
&nbsp;*/<br>
rule keyListenerRule dialect "mvel" when<br>
&nbsp; &nbsp;$keyEvent : KeyEvent() from entry-point "KeyListener"<br>
&nbsp; &nbsp;$l : Location()<br>
&nbsp; &nbsp;$newD : Direction() from createDirection( $l.character, $keyEvent )<br>
&nbsp; &nbsp;$target : Cell( row == ($l.row + $newD.vertical), col == ($l.col +<br>
$newD.horizontal) )<br>
&nbsp; &nbsp;CellContents( cell == $target, cellType != CellType.WALL )<br>
&nbsp; &nbsp;$oldD : Direction( character == $l.character )<br>
then<br>
&nbsp; &nbsp;exitPoints["ConsoleExitPoint" ].insert( "insert " + $newD + "\n" );<br>
&nbsp; &nbsp;retract( $keyEvent );<br>
&nbsp; &nbsp;retract( $oldD );<br>
&nbsp; &nbsp;insert( $newD );<br>
end<br>
    <br>
As the Tick, simulated time, increases we attempt to change it's<br>
Location based on the given Direction. We make sure the new Location is<br>
valid, and if so schedule the new Location, in time with the Tick.<br>
/**<br>
&nbsp;* Checks that the current Direction moves to a valid location, i.e. not<br>
a WALL.<br>
&nbsp;* It does not set the new direction straight away, this is because we<br>
need movement to be intime<br>
&nbsp;* with the Tick increase, so we schedule the new Location instead.<br>
&nbsp;*/<br>
rule validDirection dialect "mvel" when<br>
&nbsp; &nbsp;$l : Location( )<br>
&nbsp; &nbsp;$d : Direction( character == $l.character )<br>
&nbsp; &nbsp;$target : Cell( row == ($l.row + $d.vertical), col == ($l.col +<br>
$d.horizontal) )<br>
&nbsp; &nbsp;CellContents( cell == $target, cellType != CellType.WALL )<br>
&nbsp; &nbsp;not ScheduledLocationUpdate( location == $l )<br>
&nbsp; &nbsp;$t : Tick()<br>
then<br>
&nbsp; &nbsp;insert( new ScheduledLocationUpdate($l, $l.row += $d.vertical,<br>
$l.col += $d.horizontal, $t.tock + 1) );<br>
end<br>
    <br>
/**<br>
&nbsp;* When the Tick increases, update any Locations from inserted scheduled<br>
updates.<br>
&nbsp;*/<br>
rule setNewDirection dialect "mvel" when<br>
&nbsp; &nbsp;$s : ScheduledLocationUpdate()<br>
&nbsp; &nbsp;$l : Location( this == $s.location )<br>
&nbsp; &nbsp;Tick( tock == $s.tock )<br>
then<br>
&nbsp; exitPoints["ConsoleExitPoint"].insert( "set new Location " + $l +<br>
"\n" &nbsp;);<br>
&nbsp; modify( $l ) { row = $s.row, col = $s.col };<br>
&nbsp; retract( $s );<br>
end<br>
    <br>
Notice the whole thing id driven relationally, because everything is<br>
linked relationally we can exploit that to drive the engine<br>
declaratively with only a few rules.<br>
    <br>
I've committed everything to drools-examples for now, you'll need drools<br>
trunk, as there are a few fixes necessary for this to work:<br>
    <a moz-do-not-send="true"
 href="http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-examples/drools-examples-drl/src/main/java/org/drools/examples/pacman/"
 target="_blank">http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-examples/drools-examples-drl/src/main/java/org/drools/examples/pacman/</a><br>
    <a moz-do-not-send="true"
 href="http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-examples/drools-examples-drl/src/main/resources/org/drools/examples/pacman/"
 target="_blank">http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-examples/drools-examples-drl/src/main/resources/org/drools/examples/pacman/</a><br>
    <a moz-do-not-send="true"
 href="http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-examples/drools-examples-drl/src/main/rules/org/drools/examples/pacman/"
 target="_blank">http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-examples/drools-examples-drl/src/main/rules/org/drools/examples/pacman/</a><br>
    <br>
The grid1.dat holds the grid layout, it's a declarative symbol layout,<br>
trivial to change to explore new grids.<br>
    <br>
It's still very basic. Next I want to work on variable speed for<br>
characters, then I'll start to add Monsters and power pellets. Once we<br>
have the full backend working, the idea is to hook it up to an existing<br>
pacman gui such as SwtPacman. SwtPacman source code is available here:<br>
    <a moz-do-not-send="true"
 href="http://www.jboss.org/community/wiki/pacman" target="_blank">http://www.jboss.org/community/wiki/pacman</a><br>
    <br>
I'll probably blog this later, as a few more bits are added. But<br>
hopefully this will start to demonstrate to people some more complex<br>
problems, and also help drive the drools team on how to improve our<br>
language and engine.<br>
    <br>
Mark<br>
    <br>
_______________________________________________<br>
rules-dev mailing list<br>
    <a moz-do-not-send="true" href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a><br>
    <a moz-do-not-send="true"
 href="https://lists.jboss.org/mailman/listinfo/rules-dev"
 target="_blank">https://lists.jboss.org/mailman/listinfo/rules-dev</a><br>
  </blockquote>
  </div>
  <br>
  <br clear="all">
  <br>
-- <br>
- <a moz-do-not-send="true" href="http://salaboy.wordpress.com">http://salaboy.wordpress.com</a><br>
- <a moz-do-not-send="true" href="http://www.jbug.com.ar">http://www.jbug.com.ar</a><br>
- Salatino "Salaboy" Mauricio -<br>
  <pre wrap="">
<hr size="4" width="90%">
_______________________________________________
rules-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-dev">https://lists.jboss.org/mailman/listinfo/rules-dev</a>
  </pre>
</blockquote>
<br>
</body>
</html>