Post-Cancellation, Pre-Nisei Netrunner Rotation
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.2KB

  1. module Format where
  2. import System.Random
  3. import State
  4. import Timestamp
  5. import Config
  6. import Utils
  7. currentFormat :: Timestamp -> State
  8. currentFormat t = strictApplyN n nextFormat initialRotation
  9. where
  10. n = t `monthsSince` genesis
  11. nextFormat :: State -> State
  12. nextFormat (p, b, r) = (np, nb, nr)
  13. where
  14. ip = rotateOld p
  15. (np, nr) = (addNewPack . addNewPack) (ip, r)
  16. nb = rotateBox b
  17. legalOutRot :: [OutRot] -> [OutRot]
  18. legalOutRot x = filter (\(Or _ n) -> n == 0) x
  19. updatePackAge :: [OutRot] -> [OutRot]
  20. updatePackAge p = map (\(Or s n) -> (Or s $ max 0 (n-1))) p
  21. setIllegal :: InRot -> OutRot
  22. setIllegal (Ir n) = Or n 3
  23. setLegal :: OutRot -> InRot
  24. setLegal (Or n _) = Ir n
  25. rotateOld :: Pool -> Pool
  26. rotateOld (i, o) = (ni, no)
  27. where
  28. ni = drop 2 i
  29. no = (updatePackAge o) ++ dropped
  30. dropped = map setIllegal (take 2 i)
  31. addNewPack :: (Pool, StdGen) -> (Pool, StdGen)
  32. addNewPack ((i, o), r) = ((ni, no), nr)
  33. where
  34. lp = length $ legalOutRot o
  35. (ip, nr) = randomR (0, lp-1) r
  36. np = (legalOutRot o) !! ip
  37. ni = i ++ [(setLegal np)]
  38. no = filter (\x -> x /= np) o
  39. rotateBox :: BoxQueue -> BoxQueue
  40. rotateBox (Bq x) = Bq $ rotate 1 x