I didn&#39;t read the book, but your code seems very elegant, more than I even thought possible. I&#39;ve never programmed with fuzzy logic before, but I can understand your code - it reads naturally.<br><br clear="all">Fernando Henrique Sanches<br>

<br><br><div class="gmail_quote">On Wed, Oct 14, 2009 at 9:59 AM, Neal Alexander <span dir="ltr">&lt;<a href="mailto:relapse.dev@gmx.com">relapse.dev@gmx.com</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;">
So i was reading &quot;Programming Game AI by Example&quot; by Mat Buckland (<a href="http://www.ai-junkie.com/books/toc_pgaibe.html" target="_blank">http://www.ai-junkie.com/books/toc_pgaibe.html</a>) and decided to rewrite his chapter on Fuzzy logic in haskell (from C++).<br>

<br>
My initial impression: its one of those scenarios where OOP grossly over complicates things<br>
<br>
<br>
Heres an example taken from the book: An agent needs to decide what weapon to use based on his distance from the target and the amount of ammo each has. The result is in the desirability domain (0-100).<br>
<br>
<a href="http://code.haskell.org/%7Ehexpuem/fuzzyLogic/AI/Logic/Fuzzy/Example.hs" target="_blank">http://code.haskell.org/~hexpuem/fuzzyLogic/AI/Logic/Fuzzy/Example.hs</a><br>
<br>
An excerpt:<br>
<br>
<br>
------------------------------------<br>
<br>
weapons = [ Weapon &quot;RocketLauncher&quot; 9 rocketLauncher,<br>
            Weapon &quot;ShotGun&quot; 13 shotgun,<br>
            Weapon &quot;AssaultRifle&quot; 120 assaultRifle,<br>
            Weapon &quot;SniperRifle&quot; 7 sniperRifle,<br>
            Weapon &quot;Knife&quot; 1 knife ]<br>
<br>
chooseWeapon dist = maximum ratings<br>
  where<br>
    ratings = [ (f dist ammo, n) | Weapon n ammo f &lt;- weapons ]<br>
<br>
------------------------------------<br>
<br>
shotgun :: Double -&gt; Double -&gt; Double<br>
shotgun dist ammo =<br>
<br>
  unfuzz desireDom $ rules (fuzz distDom dist) (fuzz ammoDom ammo)<br>
<br>
  where<br>
<br>
    rules :: Fuzzy Distances -&gt; Fuzzy Ammo -&gt; FL Desirability<br>
    rules distance ammo = do<br>
<br>
      distance `is` SniperSuited =&gt;&gt; Pointless<br>
      distance `is` Far          =&gt;&gt; Undesirable<br>
      distance `is` Medium       =&gt;&gt; Undesirable<br>
      distance `is` Melee        =&gt;&gt; Undesirable<br>
<br>
      (distance `fairly` Near) &amp; (ammo `fairly` High) =&gt;&gt; VeryDesirable<br>
      (distance `fairly` Near) &amp; (ammo `fairly` Good) =&gt;&gt; Desirable<br>
      (distance `fairly` Near) &amp; (ammo `is` Low)      =&gt;&gt; Undesirable<br>
<br>
------------------------------------<br>
<br>
Full code at <a href="http://code.haskell.org/%7Ehexpuem/fuzzyLogic/" target="_blank">http://code.haskell.org/~hexpuem/fuzzyLogic/</a>.<br>
<br>
Suggestions welcome - maybe it&#39;d be useful to upload to hackage at some point.<br>
<br>
<br>
It only supports triangle, shoulder, and singleton memberships at the moment.<br>
<br>
<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br>