Don't like ads? PRO users don't see any ads ;-)
Guest

working

By: a guest on Apr 15th, 2012  |  syntax: Haskell  |  size: 2.35 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. module Robot
  2. where
  3.  
  4. import Types
  5.  
  6. data Memory = Memory
  7.         {visited::[Point]
  8.         ,dfsstack::[Point]
  9.         ,currentPoz::Point
  10.         }deriving(Eq)
  11.  
  12. {-
  13. When the robot enters the mine it receives as input the size of the mine (it
  14. is always placed at (0, 0)). This function should return the initial memory
  15. element of the robot.
  16. -}
  17. --startRobot :: Size -> a
  18. startRobot s = (Memory [] [] (0, 0))
  19. --can_go_there :: Point -> [Point] -> Bool
  20. --can_go_there p lst
  21.  -- |
  22. --can_not_go_there b =
  23. {-
  24. At each time step the robot sends a light beam in all 4 cardinal directions,
  25. receives the reflected rays and computes their intensity (the first argument
  26. of the function).
  27.  
  28. The robot sees nearby pits. The second argument of this function is the list
  29. of neighbouring pits near the robot (if empty, there are no pits).
  30.  
  31. Taking into account the memory of the robot (third argument of the function),
  32. it must return a tuple containing a new cardinal direction to go to and a new
  33. memory element.
  34.  
  35. If the cardinal direction chosen goes to a pit or an wall the robot is
  36. destroyed. If the new cell contains minerals they are immediately collected.
  37. -}
  38. --perceiveAndAct :: SVal -> [Cardinal] -> a -> (Action, a)
  39. perceiveAndAct s cs m
  40.   | elem W cs && elem N cs && elem E cs && notElem S cs = (Just S, m)
  41.   | notElem W cs && elem N cs && elem E cs && elem S cs = (Just W, m)
  42.   | elem W cs && elem N cs && notElem E cs && elem S cs = (Just E, m)
  43.   | elem W cs && notElem N cs && elem E cs && elem S cs = (Just N, m)
  44.  
  45.   | elem W cs && elem N cs && notElem E cs && notElem S cs = (Just E, m)
  46.   | notElem W cs && elem N cs && elem E cs && notElem S cs = (Just S, m)
  47.   | elem W cs && notElem N cs && notElem E cs && elem S cs = (Just N, m)
  48.   | elem W cs == False && elem N cs == False && elem E cs && elem S cs = (Just W, m)
  49.  
  50.   | elem W cs && elem N cs == False && elem E cs && elem S cs == False = (Just N, m)
  51.   | elem W cs == False && elem N cs && elem E cs == False && elem S cs = (Just E, m)
  52.  
  53.   | elem W cs && elem N cs == False && elem E cs == False && elem S cs == False = (Just N, m)
  54.   | elem W cs == False && elem N cs && elem E cs == False && elem S cs == False = (Just E, m)
  55.   | elem W cs == False && elem N cs == False && elem E cs && elem S cs == False = (Just S, m)
  56.   | elem W cs == False && elem N cs == False && elem E cs == False && elem S cs = (Just W, m)
  57.   | otherwise = (Just S, m)