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.

69 lines
1.6KB

  1. module Format where
  2. {---
  3. - Format Module
  4. -
  5. - Functions for generating new formats
  6. - Little bit of a shitshow
  7. -
  8. - Shaun Kerr
  9. -}
  10. import System.Random
  11. import State
  12. import Timestamp
  13. import Config
  14. import Utils
  15. -- Calculate the format starting from Genesis
  16. currentFormat :: Timestamp -> State
  17. currentFormat t = strictApplyN n nextFormat initialRotation
  18. where
  19. n = t `monthsSince` genesis
  20. -- Take a format and return the next months format
  21. nextFormat :: State -> State
  22. nextFormat (p, b, r) = (np, nb, nr)
  23. where
  24. ip = rotateOld p
  25. (np, nr) = (addNewPack . addNewPack) (ip, r)
  26. nb = rotateBox b
  27. -- Returns the out rotation packs that are legal
  28. legalOutRot :: [OutRot] -> [OutRot]
  29. legalOutRot x = filter (\(Or _ n) -> n == 0) x
  30. -- Updates out rotation pack legality
  31. updatePackAge :: [OutRot] -> [OutRot]
  32. updatePackAge p = map (\(Or s n) -> (Or s $ max 0 (n-1))) p
  33. -- Illegalise a pack
  34. setIllegal :: InRot -> OutRot
  35. setIllegal (Ir n) = Or n 3
  36. -- Legalise a pack
  37. setLegal :: OutRot -> InRot
  38. setLegal (Or n _) = Ir n
  39. -- Drop two oldest packs
  40. rotateOld :: Pool -> Pool
  41. rotateOld (i, o) = (ni, no)
  42. where
  43. ni = drop 2 i
  44. no = (updatePackAge o) ++ dropped
  45. dropped = map setIllegal (take 2 i)
  46. -- Add a new pack
  47. addNewPack :: (Pool, StdGen) -> (Pool, StdGen)
  48. addNewPack ((i, o), r) = ((ni, no), nr)
  49. where
  50. lp = length $ legalOutRot o
  51. (ip, nr) = randomR (0, lp-1) r
  52. np = (legalOutRot o) !! ip
  53. ni = i ++ [(setLegal np)]
  54. no = filter (\x -> x /= np) o
  55. -- Update the banned box
  56. rotateBox :: BoxQueue -> BoxQueue
  57. rotateBox (Bq x) = Bq $ rotate 1 x