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 d, Num n)
- IndexedDice.Dice = IndexedDice[0] # IndexedDice.d
- IndexedDice.Index = IndexedDice[1] # IndexedDice.n
- 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), )
- Dice ->> Random Num
- roll = options => choice options
- Dice ->> Random Num
- double_roll = dice => roll dice + roll dice
- Dice, Dice ->> Random Bool
- duel = dice1, dice2 =>
- double_roll dice1 > double_roll dice2
- [Dice] ->> [(IndexedDice, IndexedDice)]
- create_pairs = with input(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
- [(IndexedDice, IndexedDice)] ->> [Random Num]
- round = {
- pairs ''> 0,
- (iDice1, iDice2) => duel iDice1.Dice iDice2.Dice
- ? iDice1.Index
- : iDice2.Index,
- winner => @winner
- }
- [T], T ->> Num
- count<T> = list, value => list >\ (acc, val => acc + Int <- val == value) 0
- [(IndexedDice, IndexedDice)] ->> [Random Num]
- get_scores_from_round = pairs => count round pairs
- [(IndexedDice, IndexedDice)], Num ->> [Random Num]
- complete_run = {
- pairs, timesteps => (_ => get_scores_from_round pairs) [0..timesteps]''0
- scores_map => (@scores_map)''1
- sum,
- }
Add Comment
Please, Sign In to add comment