Guest User

IA.hs

a guest
Dec 2nd, 2013
38
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Árbol de decisiones, tantas ramas como estados de humor se quieran poner,de más a intenso a menos conforme se desciende en la jerarquía.
  2. module IA(getResponse,IATree,Response) where
  3.     import qualified Commands
  4.     --import qualified Socket
  5.     type HumourInt = Int
  6.     data Humour = Cheerful HumourInt | Disappointed HumourInt | Angry HumourInt | Depressed HumourInt deriving (Eq,Ord)
  7.     type Response = String
  8.     data IATree a = Leaf [Response] | Branch [IATree a] deriving (Eq,Ord,Show)
  9.     type LastPhrase = String
  10.     type Patterns = String
  11.     type Params = String
  12.     type Message = String
  13.    
  14.     -- La IA será para gestionar los comandos, sacará mensajes dependiendo del estado de ánimo.
  15.     getResponse :: Humour -> (IATree a) -> Response
  16.     getResponse (Cheerful x) (Branch(p:ps))= walkBranch 0 x (Branch (p:ps))
  17.     getResponse (Disappointed x) (Branch (p:ps)) = walkBranch 1 x (Branch (p:ps))
  18.     getResponse (Angry x) (Branch (p:ps)) = walkBranch 2 x (Branch (p:ps))
  19.     getResponse (Depressed x) (Branch (p:ps)) = walkBranch 3 x (Branch (p:ps))
  20.    
  21.     -- x nº of branch, y nº of intensity
  22.     walkBranch :: Int -> HumourInt -> (IATree a) -> Response
  23.     walkBranch 0 y (Branch (p:ps)) = walkLeafs y p
  24.     walkBranch x y (Branch (p:ps)) = walkBranch (x-1) y (Branch ps)
  25.    
  26.     walkLeafs :: Int -> (IATree a) -> Response
  27.     walkLeafs 0 (Leaf (x:xs)) = x
  28.     walkLeafs y (Leaf (x:xs)) = walkLeafs (y-1) (Leaf xs)
  29.    
  30.     -- [] Lista con funciones, [!] lista de patrones, hacer zip cada lista y acceder a la funcion cuya posicion sea el patrón de lo último escrito
  31.    
  32.     -- zip [putMessage,kickUser,...,setName] ["!say","!kick",...,"!setName"]
  33.     -- Se hará Socket.sendFunction (funct ps)
  34.     -- Cambiar parámetros de commands por listas
  35.     carryOutCommand :: LastPhrase -> [Message->Response] -> [Patterns] -> [Params] -> [Response]
  36.     carryOutCommand t (x:xs) (y:ys) ps = [ funct ps| (funct,pattern) <- (zip (x:xs) (y:ys)) , t==snd (funct,pattern)]
RAW Paste Data