Last active
June 1, 2022 14:30
-
-
Save hugoferreira/47189ef3915fc07a69ba2b0ec5888521 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const _ = require('lodash') | |
const tournaments = _.range(1, 100000) | |
const dieA = [1, 1, 4, 4, 4, 4] | |
const dieB = [3, 3, 3, 3, 3, 3] | |
const dieC = [2, 2, 2, 2, 5, 5] | |
const roll = (die) => _.sample(die) | |
const count = (as, e) => _.filter(as, (x) => x === e).length | |
const fixedGame = (a, b) => (roll(a) > roll(b)) ? 'W' : 'L' | |
const AvsB = tournaments.map(() => fixedGame(dieA, dieB)) | |
const BvsC = tournaments.map(() => fixedGame(dieB, dieC)) | |
const CvsA = tournaments.map(() => fixedGame(dieC, dieA)) | |
console.log(`A (${count(AvsB, 'W')}) vs B (${count(AvsB, 'L')})`) | |
console.log(`B (${count(BvsC, 'W')}) vs C (${count(BvsC, 'L')})`) | |
console.log(`C (${count(CvsA, 'W')}) vs A (${count(CvsA, 'L')})`) | |
const randomGame = (choice, oppChoices = [dieA, dieB, dieC]) => { | |
const a = roll(choice) | |
const b = roll(_.sample(oppChoices)) | |
return (a === b) ? 'D' : ((a > b) ? 'W' : 'L') | |
} | |
const AvsRandom = tournaments.map(() => randomGame(dieA, [dieB, dieC])) | |
const BvsRandom = tournaments.map(() => randomGame(dieB, [dieA, dieC])) | |
const CvsRandom = tournaments.map(() => randomGame(dieC, [dieA, dieB])) | |
console.log(`A (${count(AvsRandom, 'W')}) vs Random (${count(AvsRandom, 'L')})`) | |
console.log(`B (${count(BvsRandom, 'W')}) vs Random (${count(BvsRandom, 'L')})`) | |
console.log(`C (${count(CvsRandom, 'W')}) vs Random (${count(CvsRandom, 'L')})`) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment