Last active
February 10, 2019 11:14
-
-
Save textbook/ba14aff4d719936457ece6e0865170d4 to your computer and use it in GitHub Desktop.
Calculate the probability of a reward in R6 Siege
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
#! /usr/bin/env python3 | |
"""Simulate the probability of a reward in R6 Siege.""" | |
from argparse import ArgumentParser | |
import random | |
from textwrap import dedent | |
from typing import Mapping | |
BASE_PROBABILITY: float = 0.02 | |
"""The initial/reset/increment probability of a reward on a win.""" | |
VIP_BONUS_PROBABILITY: float = 0.003 | |
"""The bonus probability you get from VIP status.""" | |
def siege_rewards( | |
*, | |
win_loss: float=1., | |
vip: bool=False, | |
matches: int=1_000_000, | |
per_win: bool=False, | |
) -> float: | |
"""Per-match or per-win probability of receiving an award.""" | |
reward_probability = BASE_PROBABILITY | |
win_probability = win_loss / (1 + win_loss) | |
wins = 0 | |
rewards = 0 | |
for _ in range(matches): | |
if vip: | |
reward_probability += VIP_BONUS_PROBABILITY | |
if random.random() < win_probability: | |
wins += 1 | |
if random.random() < reward_probability: | |
rewards += 1 | |
reward_probability = BASE_PROBABILITY | |
continue | |
reward_probability += BASE_PROBABILITY | |
return rewards / (wins if per_win else matches) | |
def _create_parser() -> ArgumentParser: | |
"""Create the parser for command-line arguments.""" | |
parser = ArgumentParser(description=__doc__) | |
parser.add_argument( | |
"-w", | |
"--win-loss", | |
type=float, | |
default=1., | |
help="your ratio of wins to losses", | |
) | |
parser.add_argument( | |
"-v", | |
"--vip", | |
action="store_true", | |
help="whether you have VIP status (bonus 0.3%% probability)", | |
) | |
parser.add_argument( | |
"-m", | |
"--matches", | |
type=int, | |
default=1_000_000, | |
help="number of matches to simulate", | |
) | |
parser.add_argument( | |
"-p", | |
"--per-win", | |
action="store_true", | |
help="whether to calculate per win, rather than per match", | |
) | |
return parser | |
def _get_arg_help(parser: ArgumentParser) -> Mapping[str, str]: | |
"""Get the help text for the defined optional arguments.""" | |
return { | |
action.dest: action.help % () | |
for action in parser._action_groups[1]._actions | |
} | |
if __name__ == "__main__": | |
ARGS = _create_parser().parse_args() | |
REWARD_PROBABILITY = siege_rewards(**vars(ARGS)) | |
print(f"{REWARD_PROBABILITY * 100:.2f}%") | |
else: | |
siege_rewards.__doc__ = dedent( | |
"""{} | |
Arguments: | |
win_loss: {win_loss} | |
vip: whether {vip} | |
matches: {matches} | |
per_win: {per_win} | |
""".format( | |
siege_rewards.__doc__, | |
**_get_arg_help(_create_parser()), | |
), | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment