[Haskell-cafe] Fuzzy Logic / Linguistic Variables

Fernando Henrique Sanches fernandohsanches at gmail.com
Wed Oct 14 23:07:07 EDT 2009


I didn't read the book, but your code seems very elegant, more than I even
thought possible. I've never programmed with fuzzy logic before, but I can
understand your code - it reads naturally.

Fernando Henrique Sanches


On Wed, Oct 14, 2009 at 9:59 AM, Neal Alexander <relapse.dev at gmx.com> wrote:

> So i was reading "Programming Game AI by Example" by Mat Buckland (
> http://www.ai-junkie.com/books/toc_pgaibe.html) and decided to rewrite his
> chapter on Fuzzy logic in haskell (from C++).
>
> My initial impression: its one of those scenarios where OOP grossly over
> complicates things
>
>
> 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).
>
> http://code.haskell.org/~hexpuem/fuzzyLogic/AI/Logic/Fuzzy/Example.hs<http://code.haskell.org/%7Ehexpuem/fuzzyLogic/AI/Logic/Fuzzy/Example.hs>
>
> An excerpt:
>
>
> ------------------------------------
>
> weapons = [ Weapon "RocketLauncher" 9 rocketLauncher,
>            Weapon "ShotGun" 13 shotgun,
>            Weapon "AssaultRifle" 120 assaultRifle,
>            Weapon "SniperRifle" 7 sniperRifle,
>            Weapon "Knife" 1 knife ]
>
> chooseWeapon dist = maximum ratings
>  where
>    ratings = [ (f dist ammo, n) | Weapon n ammo f <- weapons ]
>
> ------------------------------------
>
> shotgun :: Double -> Double -> Double
> shotgun dist ammo =
>
>  unfuzz desireDom $ rules (fuzz distDom dist) (fuzz ammoDom ammo)
>
>  where
>
>    rules :: Fuzzy Distances -> Fuzzy Ammo -> FL Desirability
>    rules distance ammo = do
>
>      distance `is` SniperSuited =>> Pointless
>      distance `is` Far          =>> Undesirable
>      distance `is` Medium       =>> Undesirable
>      distance `is` Melee        =>> Undesirable
>
>      (distance `fairly` Near) & (ammo `fairly` High) =>> VeryDesirable
>      (distance `fairly` Near) & (ammo `fairly` Good) =>> Desirable
>      (distance `fairly` Near) & (ammo `is` Low)      =>> Undesirable
>
> ------------------------------------
>
> Full code at http://code.haskell.org/~hexpuem/fuzzyLogic/<http://code.haskell.org/%7Ehexpuem/fuzzyLogic/>
> .
>
> Suggestions welcome - maybe it'd be useful to upload to hackage at some
> point.
>
>
> It only supports triangle, shoulder, and singleton memberships at the
> moment.
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091014/939c4aa4/attachment.html


More information about the Haskell-Cafe mailing list