module RobotEx2 where import Array import List import Monad import IRL import GraphicsUtils import RobotWorld for :: Int -> Robot ()-> Robot () for n a = sequence_ (replicate n a) moven :: Int-> Robot () moven n = for n move treasureHunt :: Robot () treasureHunt = do penDown; loop 1 where loop n = cond blocked findDoor $ do turnRight; moven n cond blocked findDoor $ do turnRight moven n; loop (n+1) findDoor :: Robot () findDoor = do turnLeft loop where loop = do wallFollowRight cond doorOnRight (do enterRoom; getGold) (do turnRight; move; loop) wallFollowRight :: Robot () wallFollowRight = cond_ blockedRight $ do move; wallFollowRight blockedRight :: Robot Bool blockedRight = do turnRight b <- blocked turnLeft return b doorOnRight :: Robot Bool doorOnRight = do penUp; move b <- blockedRight turnAround; move; turnAround; penDown return b turnAround :: Robot () turnAround = do turnRight; turnRight enterRoom :: Robot () enterRoom = do turnRight move turnLeft moveToWall turnAround moveToWall :: Robot () moveToWall = while (isnt blocked) move getGold :: Robot () getGold = do getCoinsToWall turnLeft; move; turnLeft getCoinsToWall turnRight cond_ (isnt blocked) $ do move; turnRight; getGold getCoinsToWall :: Robot () getCoinsToWall = while (isnt blocked) $ do move; pickCoin main = runRobot treasureHunt s1 g3