Haskell for Dead or Alive Fan

jjinkou2

Well-Known Member
hi
here is a little toy program in haskell. it converts a text file with strings with numbers to a unicode file that can be printed.

The use : I just want to have a small paper in front of me with some of the best moves for my main. i copy a lot of juggles or combo in several forum in this form "236P , 4K" , and this program converts them into :2: :3: :6: P, :4: K

so in a file "input.txt" i put strings like
Code:
6P+K 33P4P F 7P(CB) 113 damage
Fairly strict timing on the BKO cancel to CB
 
6P+K 8P SSP 7P(CB) 108 damage
SSP is a sit down stun
 
33P 8P SSP 7P(CB) 100 damage
SSP sit down stun.
 
33P 6PP 7P(CB) 100 damage
second hit of 6PP is a sit down stun
 
33P 3K 4PP 7P(CB) 107 damage
Everything can be held out of and it's all mid so be aware of that.

then in a terminal command i enter the following command:
Code:
cat input.txt | strToUtf8 > test.txt

and file test.txt contains the arrows in unicode.


compile the program with following command
Code:
ghc --make -O2 utf8v2.hs -o strToUtf8

i post this program here since it may interest inquiring minds ! more info here
http://learnyouahaskell.com/chapters

Code:
import Data.List
 
rightArr = "\x2192"
leftArr = "\x2190"
upArr  = "\x2191"
downArr = "\x2193"
r_D_Arr = "\x2198"
l_D_Arr = "\x2199"
r_U_Arr = "\x2197"
l_U_Arr = "\x2196"
 
dict = [('1',l_D_Arr),('2',downArr),('3',r_D_Arr)
      ,('4',leftArr),('6',rightArr)
      ,('7',l_U_Arr),('8',upArr),('9',r_U_Arr)]
 
numtoUtf8 = concat . unfoldr translate
    where translate [] = Nothing
          translate (x:xs) = case str2 x of
                    Just (c,he) -> Just (he,xs)
                    Nothing    -> Just ([x],xs)
                    where str2 n = find (\(val,_) -> val == n) dict
 
main :: IO ()
main =  interact $ unlines.map numtoUtf8.lines
 

dawnbringer

Active Member
Nice job.

But your program converts this:
Code:
6P+K 33P4P F 7P(CB) 113 damage
into this:
Code:
→P+K ↘↘P←P F ↖P(CB) [B]↙↙↘[/B] damage

Note that damage value (in bold) has been converted as well.

Now I've written effectively similar program on the same language. This is how it looks:
Code:
import qualified Data.Map
import Data.Maybe
 
symbolMap = Data.Map.fromList [('1', "\x2199"), ('2', "\x2193")
    , ('3', "\x2198") , ('4', "\x2190"), ('5', ""), ('6', "\x2192")
    , ('7', "\x2196"), ('8', "\x2191"), ('9', "\x2197")]
 
convertNotation = (>>= replaceSymbol)
    where replaceSymbol s = fromMaybe (return s) (Data.Map.lookup s symbolMap)
 
main = interact $ convertNotation

Using following symbol map it's possible to use it to produce simplified BB code:
Code:
symbolMap = Data.Map.fromList [('1', ":1:"), ('2', ":2:"), ('3', ":3:")
    , ('4', ":4:"), ('5', ":5:"), ('6', ":6:")
    , ('7', ":7:"), ('8', ":8:"), ('9', ":9:")
    , ('P', ":P:"), ('K', ":K:"), ('H', ":H:")]
 

jjinkou2

Well-Known Member
excellent!
your code has more readability. it has the same flaw as mine (it converts also the damage points), but that's not important for such a small code.
i wanted to use the function
to understand how it works, but your version is more satifying.
 

xINFINITELIGHTx

Active Member
excellent man it's always good to see people using their skills to solve THEIR problems and not anyone elses! now everyone who has htat problem can have it solved because this program exists I exhault it endlessly in JESUS who is GOD's name AMEN!
 
ALL DOA6 DOA5 DOA4 DOA3 DOA2U DOAD
Top