Skip to content

Instantly share code, notes, and snippets.

@yagamuu
Created June 24, 2021 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yagamuu/5c277493273066f99a835d6a8ae18bad to your computer and use it in GitHub Desktop.
Save yagamuu/5c277493273066f99a835d6a8ae18bad to your computer and use it in GitHub Desktop.
モンゲWCルール戦闘シミュレーター
const shaffleArray = array => {
for(let i = array.length - 1; i > 0; i--){
const r = Math.floor(Math.random() * (i + 1));
const tmp = array[i];
array[i] = array[r];
array[r] = tmp;
}
return array;
};
// index0はプレイヤーAが1P側だった場合、index1はプレイヤーAが2P側だった場合とする
const probabilityList = [[
[33, 67, 0],
[47, 53, 0],
[20, 78, 2],
[54, 45, 1],
[73, 22, 5],
[84, 16, 0],
[38, 57, 5],
[41, 52, 7],
[68, 32, 0],
[61, 38, 1],
[16, 72, 12],
[22, 78, 0],
[73, 27, 0],
[39, 51, 10],
[36, 64, 0],
],
[
[20, 80, 0],
[65, 35, 0],
[20, 80, 0],
[19, 81, 0],
[50, 42, 8],
[73, 26, 1],
[62, 36, 2],
[75, 19, 6],
[39, 61, 0],
[37, 62, 1],
[81, 14, 5],
[57, 43, 0],
[49, 51, 0],
[63, 21, 16],
[45, 55, 0],
]];
const count = 1000000;
const result = {
win1P: 0,
win2P: 0,
draw: 0
};
for (let i = 0; i < count; i++) {
const map = shaffleArray([...Array(15).keys()]);
let win1P = 0;
let win2P = 0;
let selectPlayerSide = Math.floor(Math.random() * 2) + 1;
while (map.length > 0 && win1P < 2 && win2P < 2) {
const selectedMap = map.shift();
const rand = Math.random() * 100;
const probability = probabilityList[selectPlayerSide % 2][selectedMap];
if (rand < probability[0]) {
if (selectPlayerSide % 2 === 0) {
win1P++;
} else {
win2P++;
}
} else if(rand < (probability[0] + probability[1])) {
if (selectPlayerSide % 2 === 0) {
win2P++;
} else {
win1P++;
}
}
selectPlayerSide++;
}
if (win1P === 2) {
result.win1P++;
} else if(win2P === 2) {
result.win2P++;
} else {
result.draw++;
}
}
console.log(`win1P : ` + result.win1P / count * 100 + `%`);
console.log(`win2P : ` + result.win2P / count * 100 + `%`);
console.log(`draw : ` + result.draw / count * 100 + `%`);
console.log(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment