Browse Source

Change how brother count works

master
Noëlle 2 years ago
parent
commit
a91fbc770b
No known key found for this signature in database
1 changed files with 24 additions and 16 deletions
  1. 24
    16
      brontes.py

+ 24
- 16
brontes.py View File

@@ -2,16 +2,18 @@ import argparse
from random import randint, shuffle

class Sibling:
def __init__(self, state=None):
def __init__(self, brother_count=None, state=None, game=None):
self.tragedy = 0
self.masterpiece = 0
self.brother = 0
self.brother_count = 0
self.brother_max = int(brother_count) if brother_count else 3
self.brother_ok = True
self.alive = True
self.rounds = 0
self.success = False
self.state = state
self.game = game

def round_check(self):
if self.tragedy >= 10:
@@ -32,9 +34,12 @@ class Sibling:
else:
self.masterpiece = 0
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.masterpiece = 0

@@ -52,14 +57,17 @@ class Sibling:

class Game:
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.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:
self.brother_ok = True
self.per_sibling_brother = []
@@ -155,13 +163,13 @@ class Game:
self.vprint(sibling)
self.success = True
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

def brother_interferes(self):
self.brother_count -= 1
if self.brother_count <= 0:
self.brother_ok = False

def vprint(self, text):
if self.verbose:
print(text)
@@ -196,10 +204,10 @@ class GameState:

if __name__ == "__main__":
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("-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("-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()
gs = GameState(rounds=args.rounds, siblings=args.siblings, common_brother=args.common_brother, brother_count=args.brother_count, verbose=args.verbose)

Loading…
Cancel
Save