tools/confuse.hs
author Wuzzy <Wuzzy2@mail.ru>
Mon, 08 Jul 2019 21:44:26 +0200
changeset 15220 ceb289e8a582
parent 10075 dbaf90a0fbe0
permissions -rw-r--r--
King Mode: Fix king placement phase not working correctly with multiple teams in a clan New king placement phase rules: * Before the game begins, each team can walk with their king and teleport for free, everything else is disabled * This special round does not count towards the round counter, like in gfPlaceHog * TotalRounds is set to -1 during this round, like in gfPlaceHog Under the old rules, this was much more hacky. The delay of all delay-less weapons was just set to 1 The problem with the old rules was that if any clan had more than 1 team, eventually the weapon delay will time out before all kings have been placed.

{-# LANGUAGE OverloadedStrings #-}
module Confuse where

import Numeric
import Data.Char
import Control.Monad
import qualified Data.ByteString as B
import qualified Data.ByteString.UTF8 as UTF8
import qualified Data.Map as Map

hx :: [Char] -> String
hx cs = let ch = (chr . fst . last . readHex $ cs) in
            case ch of
                 '\'' -> "''"
                 '\\' -> "\\\\"
                 c -> c : []

conv :: String -> B.ByteString
conv s = B.concat ["('", UTF8.fromString i, "', '", UTF8.fromString r, "')"]
    where
        i :: String
        i = hx s
        r :: String
        r = concatMap hx . words . takeWhile ((/=) ';') . tail $ dropWhile ((/=) '\t') s

convRules :: (B.ByteString, [B.ByteString]) -> B.ByteString
convRules (a, b) = B.concat ["<reset>", u a, "</reset>\n<s>", B.concat $ map u b, "</s>"]
    where
        u a = B.concat ["\\","u",a]

toPair :: String -> (B.ByteString, [B.ByteString])
toPair s = (UTF8.fromString $ takeWhile isHexDigit s, map UTF8.fromString . words . takeWhile ((/=) ';') . tail $ dropWhile ((/=) '\t') s)


main = do
    ll <- liftM (filter (isHexDigit . head) . filter (not . null) . lines) $ readFile "confusables.txt"
    B.writeFile "rules.txt" . B.intercalate "\n" . map convRules . Map.toList . Map.fromList . filter notTooLong . filter fits16bit . map toPair $ ll
    where
        notTooLong = (>) 6 . length . snd
        fits16bit (a, b) = let f = (>) 5 . B.length in all f $ a:b