def check_resolvable_for_single_flag(flag: Flag, used_cards: Collection[TroopCard]) -> int: n_cards = flag.get_required_card_num() resolver_funcs = [ possible_maximum_strength_for_wedge, possible_maximum_strength_for_phalanx, possible_maximum_strength_for_battalion, possible_maximum_strength_for_skirmish, possible_maximum_strength_for_host, ] if flag.is_formation_disabled(): # all formation is disabled and only hosts available resolver_funcs = [possible_maximum_strength_for_host] for resolver in resolver_funcs: a_cards = flag.get_stacked_cards(PLAYER_A) b_cards = flag.get_stacked_cards(PLAYER_B) a_strength, a_resolvable = resolver(a_cards, n_cards, used_cards) b_strength, b_resolvable = resolver(b_cards, n_cards, used_cards) if a_resolvable and b_resolvable and a_strength == b_strength: # faster user wins return PLAYER_A if flag.get_last_stacked_player( ) == PLAYER_B else PLAYER_B if a_resolvable: if a_strength > b_strength: return PLAYER_A if b_resolvable: if b_strength > a_strength: return PLAYER_B if a_strength > 0 or b_strength > 0: # could not be resolved yet return PLAYER_UNRESOLVED # could not build the formation, continue to weaker formation type... # not resolved return PLAYER_UNRESOLVED
def test_flag_env_fog(): # noqa flag = Flag() assert not flag.is_formation_disabled() c_fog = CardGenerator.tactic(Tactics.FOG) flag.add_env(PLAYER_B, c_fog) assert len(flag.get_stacked_envs(PLAYER_B)) == 1 assert flag.is_formation_disabled()
def test_flag_env_mud(): # noqa flag = Flag() assert flag.get_required_card_num() == 3 c_mud = CardGenerator.tactic(Tactics.MUD) flag.add_env(PLAYER_A, c_mud) assert len(flag.get_stacked_envs(PLAYER_A)) == 1 assert flag.get_required_card_num() == 4
def __repr__(self) -> str: text = "" # player b operations (in reverse) for op in reversed(self._operations[PLAYER_B]): text += repr(op) # flags text += Flag.repr_flags(self._flags) # player a operations for op in self._operations[PLAYER_A]: text += repr(op) return text
def test_flag_stack_tacticmorales(): # noqa flag = Flag() c_ld = CardGenerator.tactic(Tactics.LEADER_DARIUS) flag.add_stack(PLAYER_B, c_ld) assert len(flag.get_stacked_cards(PLAYER_B)) == 1 assert (flag.remove_stack_tacticmorales( PLAYER_B, TacticMorales.LEADER_DARIUS) == c_ld)
def new() -> "GameState": troops = TroopsDeck.shuffled() a_list: List[Card] = list( sorted([troops.draw() for _ in range(NUM_INITIAL_HAND)]) ) b_list: List[Card] = list( sorted([troops.draw() for _ in range(NUM_INITIAL_HAND)]) ) return GameState( troops, TacticsDeck.shuffled(), [Flag() for _ in range(9)], [[], []], [a_list, b_list], )
def test_flag_stack_troop(): # noqa flag = Flag() c_r3 = CardGenerator.troop(TroopColors.RED, 3) flag.add_stack(PLAYER_A, c_r3) assert len(flag.get_stacked_cards(PLAYER_A)) == 1 assert flag.remove_stack_troops(PLAYER_A, TroopColors.RED, 3) == c_r3
def test_flag_deepcopy(): # noqa flag = Flag() c_r3 = CardGenerator.troop(TroopColors.RED, 3) flag.add_stack(PLAYER_A, c_r3) c_ld = CardGenerator.tactic(Tactics.LEADER_DARIUS) flag.add_stack(PLAYER_B, c_ld)