| from random import randint, shuffle | from random import randint, shuffle | ||||
| class Sibling: | class Sibling: | ||||
| def __init__(self, state=None): | |||||
| def __init__(self, brother_count=None, state=None, game=None): | |||||
| self.tragedy = 0 | self.tragedy = 0 | ||||
| self.masterpiece = 0 | self.masterpiece = 0 | ||||
| self.brother = 0 | self.brother = 0 | ||||
| self.brother_count = 0 | self.brother_count = 0 | ||||
| self.brother_max = int(brother_count) if brother_count else 3 | |||||
| self.brother_ok = True | self.brother_ok = True | ||||
| self.alive = True | self.alive = True | ||||
| self.rounds = 0 | self.rounds = 0 | ||||
| self.success = False | self.success = False | ||||
| self.state = state | self.state = state | ||||
| self.game = game | |||||
| def round_check(self): | def round_check(self): | ||||
| if self.tragedy >= 10: | if self.tragedy >= 10: | ||||
| else: | else: | ||||
| self.masterpiece = 0 | self.masterpiece = 0 | ||||
| if self.brother_ok and self.brother >= 5: | if self.brother_ok and self.brother >= 5: | ||||
| self.brother_count += 1 | |||||
| if self.brother_count >= 3: | |||||
| self.brother_ok = False | |||||
| if self.game.common_brother: | |||||
| self.game.brother_interferes() | |||||
| else: | |||||
| self.brother_count += 1 | |||||
| if self.brother_count >= self.brother_max: | |||||
| self.brother_ok = False | |||||
| self.brother = 0 | self.brother = 0 | ||||
| self.masterpiece = 0 | self.masterpiece = 0 | ||||
| class Game: | class Game: | ||||
| def __init__(self, siblings=None, common_brother=None, brother_count=None, verbose=None, state=None): | def __init__(self, siblings=None, common_brother=None, brother_count=None, verbose=None, state=None): | ||||
| self.num_siblings = int(siblings) if siblings != None else 3 | |||||
| self.common_brother = bool(common_brother) if common_brother != None else False | |||||
| self.brother_count = int(brother_count) if brother_count != None else self.num_siblings | |||||
| self.verbose = bool(verbose) if verbose != None else True | |||||
| self.num_siblings = int(siblings) if siblings is not None else 3 | |||||
| self.common_brother = bool(common_brother) if common_brother is not None else False | |||||
| self.brother_count = int(brother_count) if brother_count is not None else self.num_siblings | |||||
| self.verbose = bool(verbose) if verbose is not None else True | |||||
| self.state = state | self.state = state | ||||
| self.siblings = [] | self.siblings = [] | ||||
| for _ in range(self.num_siblings): | for _ in range(self.num_siblings): | ||||
| self.siblings.append(Sibling(state=self.state)) | |||||
| if self.common_brother: | |||||
| self.siblings.append(Sibling(state=self.state, game=self)) | |||||
| else: | |||||
| self.siblings.append(Sibling(brother_count=self.brother_count, state=self.state, game=self)) | |||||
| if self.common_brother: | if self.common_brother: | ||||
| self.brother_ok = True | self.brother_ok = True | ||||
| self.per_sibling_brother = [] | self.per_sibling_brother = [] | ||||
| self.vprint(sibling) | self.vprint(sibling) | ||||
| self.success = True | self.success = True | ||||
| return False | return False | ||||
| if self.common_brother and self.brother_ok and not current_sibling.brother_ok and self.per_sibling_brother[cur_sib_num]: | |||||
| self.brother_count -= 1 | |||||
| self.per_sibling_brother[cur_sib_num] = False | |||||
| if self.brother_count <= 0: | |||||
| self.brother_ok = False | |||||
| return True | return True | ||||
| def brother_interferes(self): | |||||
| self.brother_count -= 1 | |||||
| if self.brother_count <= 0: | |||||
| self.brother_ok = False | |||||
| def vprint(self, text): | def vprint(self, text): | ||||
| if self.verbose: | if self.verbose: | ||||
| print(text) | print(text) | ||||
| if __name__ == "__main__": | if __name__ == "__main__": | ||||
| parser = argparse.ArgumentParser() | parser = argparse.ArgumentParser() | ||||
| parser.add_argument("-v", "--verbose", help="Each round prints its results", action="store_true") | |||||
| parser.add_argument("-r", "--rounds", help="Number of game rounds to simulate", type=int, nargs="?", default=10000, const=10000) | parser.add_argument("-r", "--rounds", help="Number of game rounds to simulate", type=int, nargs="?", default=10000, const=10000) | ||||
| parser.add_argument("-s", "--siblings", help="Number of players", type=int, nargs="?", default=3, const=3) | parser.add_argument("-s", "--siblings", help="Number of players", type=int, nargs="?", default=3, const=3) | ||||
| parser.add_argument("-c", "--common_brother", help="The siblings share a brother, instead of each having their own", action="store_true") | parser.add_argument("-c", "--common_brother", help="The siblings share a brother, instead of each having their own", action="store_true") | ||||
| parser.add_argument("-b", "--brother_count", help="How many times can a brother overwhelm a sibling?", type=int, nargs="?", default=3, const=3) | |||||
| parser.add_argument("-v", "--verbose", help="Each round prints its results", action="store_true") | |||||
| parser.add_argument("-b", "--brother_count", help="How many times can a brother overwhelm a sibling?\nIf common_brother is set, this is total; otherwise, it is per sibling.", type=int, nargs="?", default=3, const=3) | |||||
| args = parser.parse_args() | args = parser.parse_args() | ||||
| gs = GameState(rounds=args.rounds, siblings=args.siblings, common_brother=args.common_brother, brother_count=args.brother_count, verbose=args.verbose) | gs = GameState(rounds=args.rounds, siblings=args.siblings, common_brother=args.common_brother, brother_count=args.brother_count, verbose=args.verbose) |