Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Jan 31st, 2010 | Syntax: Haskell | Size: 0.89 KB | Hits: 67 | Expires: Never
Copy text to clipboard
  1. module Main where
  2. import Data.Char
  3. import Text.ParserCombinators.Parsec
  4. import Data.ByteString.Lex.Double
  5. import qualified Data.ByteString.Char8 as B
  6.  
  7. str2float x = case (readDouble x) of
  8.   Nothing -> 0
  9.   Just (k,rest) -> k
  10.  
  11. cleanstr s = [ n | n <- s , n/='\r']
  12. tfarm (s1:s2:s3:s4:s5:s6:s7:s8:[]) = [(s1,s2,s3,s4,s5,s6,s7,str2float $ B.pack s8)]
  13. tfarm (s1:s2:s3:s4:s5:s6:s7:s8:t) = (s1,s2,s3,s4,s5,s6,s7,str2float $ B.pack s8):tfarm t
  14.  
  15. makestr (s1,s2,s3,s4,s5,s6,s7,s8) = "\n<strategy class=\"Farmizzator\" desc=\"Farm"++s1++ "\" enabled=\"true\" uid=\""++s2++s3++"\">\n"++"<target x=\""++s2++"\" y=\""++s3++"\" movement=\"attack\" rate=\""++show (37/s8)++ "\"/>\n"++"<troops type=\"Clubswinger\" min=\"3\" randomise=\"true\" allowLess=\"true\">10</troops>\n"++"</strategy>\n"
  16.  
  17. main = do
  18.   s <- readFile "0_farm_targets.txt"
  19.   mapM_ (putStr) (map (makestr) (tfarm (map (cleanstr ) (lines s))))