Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { choice } from "random.cf"
- import { stdout, write } from "sys.cf"
- data Dice = (...Num)
- data IndexedDice = (Dice dice, Num index)
- dices = ( (0, 0, 4, 4, 4, 4),
- (3, 3, 3, 3, 3, 3),
- (2, 2, 2, 2, 6, 6),
- (1, 1, 1, 5, 5, 5), )
- roll :: Dice ->> Random Num
- options => choice options
- double_roll :: Dice ->> Random Num
- dice => roll dice + roll dice
- duel :: Dice, Dice ->> Random Bool
- dice1, dice2 =>
- double_roll dice1 > double_roll dice2
- create_pairs :: [Dice] ->> [(IndexedDice, IndexedDice)]
- dices ~> do:
- pairs = Mut []
- for n, dice in zip [0..] dices:
- for j, dice2 in zip [0..] dices[n+1:]:
- pairs = [...pairs, (IndexedDice (dice1, n), IndexedDice (dice2, j))]
- return Const pairs
- round :: [(IndexedDice, IndexedDice)] ->> [Random Num]
- x ~> {
- pairs ''> 0,
- (iDice1, iDice2) => duel iDice1.dice iDice2.dice
- ? iDice1.index
- : iDice2.index,
- winner => @winner
- }
- count<T> :: [T], T ->> Num
- list, value => list >\ (acc, val => acc + Int <- v == value) 0
- get_scores_from_round :: [(IndexedDice, IndexedDice)] ->> [Random Num]
- pairs => count round pairs
- complete_run :: [(IndexedDice, IndexedDice)], Num ->> [Random Num]
- x ~> {
- pairs, timesteps => (_ => get_scores_from_round pairs) [0..timesteps]''0
- scores_map => (@scores_map)''1
- sum,
- }
Add Comment
Please, Sign In to add comment