Wankan

DiceRolls in CF 2

Sep 8th, 2020
1,576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import { choice } from "random.cf"
  3. import { stdout, write } from "sys.cf"
  4.  
  5.  
  6. data Dice = (...Num)
  7. data IndexedDice = (Dice dice, Num index)
  8.  
  9. dices = ( (0, 0, 4, 4, 4, 4),
  10.           (3, 3, 3, 3, 3, 3),
  11.           (2, 2, 2, 2, 6, 6),
  12.           (1, 1, 1, 5, 5, 5), )
  13.  
  14. roll :: Dice ->> Random Num
  15. options => choice options
  16.  
  17. double_roll :: Dice ->> Random Num
  18. dice => roll dice + roll dice
  19.  
  20. duel :: Dice, Dice ->> Random Bool
  21. dice1, dice2 =>
  22.   double_roll dice1 > double_roll dice2
  23.  
  24. create_pairs :: [Dice] ->> [(IndexedDice, IndexedDice)]
  25. dices ~> do:
  26.   pairs = Mut []
  27.   for n, dice in zip [0..] dices:
  28.     for j, dice2 in zip [0..] dices[n+1:]:
  29.       pairs = [...pairs, (IndexedDice (dice1, n), IndexedDice (dice2, j))]
  30.   return Const pairs
  31.  
  32. round :: [(IndexedDice, IndexedDice)] ->> [Random Num]
  33. x ~> {
  34.   pairs ''> 0,
  35.   (iDice1, iDice2) => duel iDice1.dice iDice2.dice
  36.     ? iDice1.index
  37.     : iDice2.index,
  38.   winner => @winner
  39. }
  40.  
  41. count<T> :: [T], T ->> Num
  42. list, value => list >\ (acc, val => acc + Int <- v == value) 0
  43.  
  44. get_scores_from_round :: [(IndexedDice, IndexedDice)] ->> [Random Num]
  45. pairs => count round pairs
  46.  
  47. complete_run :: [(IndexedDice, IndexedDice)], Num ->> [Random Num]
  48. x ~> {
  49.   pairs, timesteps => (_ => get_scores_from_round pairs) [0..timesteps]''0
  50.   scores_map => (@scores_map)''1
  51.   sum,
  52. }
Add Comment
Please, Sign In to add comment