Skip to content

Instantly share code, notes, and snippets.

@uhyo
Created October 1, 2013 05:18
Show Gist options
  • Save uhyo/6774159 to your computer and use it in GitHub Desktop.
Save uhyo/6774159 to your computer and use it in GitHub Desktop.
for jinrou
type Rank = Int
data Jobname = Human | Diviner | Werewolf Rank deriving (Eq,Show)
data State=State Jobname Bool deriving (Show)
type Plid=String
type Pattern = (Plid,State)
-- 配列を一つ抜く
cutoff :: Int -> [a] -> (Maybe a,[a])
cutoff _ [] = (Nothing,[])
cutoff n list = case (splitAt n list) of (mae, []) -> (Nothing,mae)
(mae,(nth:ato)) -> (Just nth,concat [mae,ato])
-- 0,1,...,(n-1)の中からkコ選んだ組み合わせを返す
combi :: Int -> Int -> [[Int]]
combi n k
| k <= 0 = [[]]
| n<=k = [take n [0..]]
| otherwise = concat $ map (\i -> map (\x -> i:(map ((i+1)+) x)
) (combi (n-i-1) (k-1))) $ take (n-k+1) [0..]
makelist :: [Plid] -> [(Jobname,Int)] -> [[Pattern]]
makelist _ [] = [[]]
makelist plids ((thisjob,num):jobs) =
let coms = combi (length plids) num
bass = map (\onepat -> makebase thisjob plids onepat) coms
in concat $ map (\(restplids,base)->
map (\patternlist->concat [base,patternlist] ) $ makelist restplids jobs
) bass
-- makebase :: Jobname -> [Plid] -> [Int] -> ([Plid],[Pattern])
where makebase _ plids [] = (plids,[])
makebase job plids (idx:coms) =
let (Just plid,cutt) = cutoff idx plids
(lastpls,res) = makebase job cutt $ map (subtract 1) coms
in (lastpls,(plid,State job False):res)
main = let number=20
plids=map (\num -> "Player" ++ (show num)) [1..number]
jobs=[(Human,15),(Werewolf 1,1),(Werewolf 2,1),(Werewolf 3,1),(Werewolf 4,1),(Diviner,1)]
in print $ length $ makelist plids jobs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment