Advertisement
Guest User

Untitled

a guest
Aug 29th, 2013
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (ns oops.core
  2.   (:require
  3.    [clojure.math.combinatorics :as combi]
  4.    [instaparse.core :as insta]))
  5.  
  6. (def deck
  7.   (concat
  8.    [\c]            ;; wild cantor
  9.    (repeat 4 \p)   ;; summoner's pact
  10.    (repeat 4 \l)   ;; lotus petal
  11.    (repeat 4 \x)   ;; mox
  12.    (repeat 4 \d)   ;; dark ritual
  13.    (repeat 4 \r)   ;; cabal ritual
  14.    (repeat 8 \g)   ;; spirit guide
  15.    (repeat 4 \m)   ;; manamorphose
  16.    (repeat 8 \w)   ;; voittokeino
  17.    (repeat 4 \t)   ;; tappo
  18.    (repeat 4 \n)   ;; narcomoeba
  19.    (repeat 3 \h))) ;; cabal therapy
  20.  
  21. (def bnf
  22.   "S           = (1B 2MORE win (ANY*)) |
  23.                 (2B (1MORE | dark) win (ANY*))
  24.  
  25.   2MORE       = (1MORE 1MORE) | dark
  26.  
  27.   2B          = (petal dark) |
  28.                 (BLACKMOX dark) |
  29.                 (CANTORBLACK dark) |
  30.                 (1B 1MORE)
  31.  
  32.   1B          = (manamorph (pact | guide | (mox (manamorph | cantor))) COLORLESS) |
  33.                 (petal COLORLESS) |
  34.                 (BLACKMOX COLORLESS) |
  35.                 (CANTORBLACK COLORLESS)
  36.  
  37.   CANTORBLACK = (pact | guide | (mox manamorph)) (pact | cantor)
  38.   1MORE       = pact | guide | petal | cabal | BLACKMOX | NONBLACKMOX
  39.   COLORLESS   = pact | guide | petal | dark | BLACKMOX | NONBLACKMOX
  40.   NONBLACKMOX = mox (manamorph | cantor | narco)
  41.   BLACKMOX    = mox (dark | cabal | therapy | win)
  42.   ANY         = cantor | pact | petal | mox | dark | cabal | guide | manamorph | win | kill | narco | therapy
  43.   cantor      = 'c'
  44.   petal       = 'l'
  45.   pact        = 'p'
  46.   guide       = 'g'
  47.   mox         = 'x'
  48.   dark        = 'd'
  49.   cabal       = 'r'
  50.   manamorph   = 'm'
  51.   win         = 'w'
  52.   kill        = 't'
  53.   narco       = 'n'
  54.   therapy     = 'h'")
  55.  
  56. (def parser
  57.   (insta/parser bnf))
  58.  
  59.  
  60. (defn hands
  61.   [n]
  62.   (->>
  63.    (combi/combinations deck n)
  64.    (map sort)
  65.    frequencies
  66.    seq))
  67.  
  68. (defn kill?
  69.   [hand]
  70.   (loop [hands (combi/permutations hand)]
  71.     (if (empty? hands)
  72.       false
  73.       (let [cur (apply str (first hands))
  74.             rst (rest hands)]
  75.         (if-not (insta/failure? (parser cur))
  76.           true
  77.           (recur rst))))))
  78.  
  79. (defn first-turn-kills
  80.   [hands]
  81.   (->>
  82.    hands
  83.    (filter (fn [[hand _]] (some #{\w} hand)))
  84.    (filter (fn [[hand _]] (kill? hand)))
  85.    (map (fn [[_ amount]] amount))
  86.    (reduce +)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement