def test_checkWinConditions(): gc, ef = fresh_gc_ef() # Check that no one has initially won assert not gc.checkWinConditions() # Check that someone wins when a game is over gc.play() assert gc.checkWinConditions() # Check that hunters win when everyone else is dead gc, ef = fresh_gc_ef() for p in gc.players: if p.character.alleg == C.Alleg.Shadow: p.setDamage(14, p) assert [ p for p in gc.checkWinConditions() if p.character.alleg == C.Alleg.Hunter ] # Check that shadows win when everyone else is dead gc, ef = fresh_gc_ef() for p in gc.players: if p.character.alleg == C.Alleg.Hunter: p.setDamage(14, p) assert [ p for p in gc.checkWinConditions() if p.character.alleg == C.Alleg.Shadow ]
def test_attack(): # Setup rigged game context gc, ef = helpers.fresh_gc_ef() p1 = gc.players[0] p2 = gc.players[1] # Check that damage is dealt properly p1.attack(p2, 5) assert p2.damage == 5 # Check that equipment works p2.damage = 0 p1.equipment = [ helpers.get_card_by_title(ef, "Holy Robe"), helpers.get_card_by_title(ef, "Chainsaw"), helpers.get_card_by_title(ef, "Butcher Knife") ] p1.attack(p2, 5) assert p2.damage == 6 # Check that equipment doesn't work if attack is unsuccessful p2.damage = 0 p1.attack(p2, 0) assert p2.damage == 0
def test_advent(): for _ in range(100): # Setup rigged game context gc, ef = helpers.fresh_gc_ef(random.randint(5, 8)) h = helpers.get_a_hunter(gc) s = helpers.get_a_shadow(gc) n = helpers.get_a_neutral(gc) c = helpers.get_card_by_title(ef, "Advent") # Check that shadows do nothing s.damage = 3 c.use({'self': s, 'card': c}) assert s.state == 2 and s.damage == 3 # Check that neutrals do nothing n.damage = 3 c.use({'self': n, 'card': c}) assert n.state == 2 and n.damage == 3 # Hunter do nothing gc.ask_h = helpers.answer_sequence( ['Do nothing', 'Reveal and heal fully', 'Heal fully']) h.damage = 3 c.use({'self': h, 'card': c}) assert h.state == 2 and h.damage == 3 # Hunter reveal and full heal c.use({'self': h, 'card': c}) assert h.state == 1 and h.damage == 0 # Hunter full heal h.damage = 3 c.use({'self': h, 'card': c}) assert h.state == 1 and h.damage == 0
def test_banana_peel(): for _ in range(C.N_ELEMENT_TESTS): # Setup rigged game context gc, ef = H.fresh_gc_ef() p1 = gc.players[0] p2 = gc.players[1] gc.ask_h = H.answer_sequence([ "Receive 1 damage", "Give an equipment card", "Holy Robe", p2.user_id ]) c = H.get_card_by_title(ef, "Banana Peel") # Give p1 holy robe roly_hobe = H.get_card_by_title(ef, "Holy Robe") p1.equipment.append(roly_hobe) # Check take one damage assert p1.damage == 0 c.use({'self': p1, 'card': c}) assert p1.damage == 1 # Check give away equipment c.use({'self': p1, 'card': c}) assert p1.damage == 1 assert not p1.equipment assert p2.equipment == [roly_hobe]
def test_erstwhile_altar(): # Set up rigged game context gc, ef = H.fresh_gc_ef() area = H.get_area_by_name(gc, "Erstwhile Altar") target = H.get_a_shadow(gc) actor = H.get_a_hunter(gc) gc.ask_h = H.answer_sequence([ target.user_id, 'Holy Robe' # test pick an equipment to steal ]) # Check that nothing happens if no one has equipment area.action(gc, actor) assert all([len(p.equipment) == 0 for p in gc.players]) # Check that nothing happens if only current player has equipment chainsaw = H.get_card_by_title(ef, "Chainsaw") actor.equipment.append(chainsaw) area.action(gc, actor) assert all([len(p.equipment) == 0 for p in gc.players if p != actor]) assert actor.equipment == [chainsaw] # Check that selected equipment is stolen from selected player axe = H.get_card_by_title(ef, "Rusted Broad Axe") roly_hobe = H.get_card_by_title(ef, "Holy Robe") target.equipment.append(axe) target.equipment.append(roly_hobe) area.action(gc, actor) assert actor.equipment == [chainsaw, roly_hobe] assert target.equipment == [axe]
def test_diabolic_ritual(): for _ in range(C.N_ELEMENT_TESTS): # Setup rigged game context gc, ef = H.fresh_gc_ef(random.randint(5, 8)) h = H.get_a_hunter(gc) s = H.get_a_shadow(gc) n = H.get_a_neutral(gc) c = H.get_card_by_title(ef, "Diabolic Ritual") # Check that hunters do nothing h.damage = 3 c.use({'self': h, 'card': c}) assert h.state == C.PlayerState.Hidden and h.damage == 3 # Check that neutrals do nothing n.damage = 3 c.use({'self': n, 'card': c}) assert n.state == C.PlayerState.Hidden and n.damage == 3 # Shadow do nothing gc.ask_h = H.answer_sequence(['Do nothing', 'Reveal and heal fully']) s.damage = 3 c.use({'self': s, 'card': c}) assert s.state == C.PlayerState.Hidden and s.damage == 3 # Shadow reveal and full heal c.use({'self': s, 'card': c}) assert s.state == C.PlayerState.Revealed and s.damage == 0
def test_chocolate(): for _ in range(100): # Setup rigged game context gc, ef = helpers.fresh_gc_ef(n_players=7) weak = [ p for p in gc.players if p.character.name in ["Allie", "Ellen", "Ultra Soul"] ][0] strong = [ p for p in gc.players if p.character.name not in ["Allie", "Ellen", "Ultra Soul"] ][0] c = helpers.get_card_by_title(ef, "Chocolate") # Strong player do nothing strong.damage = 3 c.use({'self': strong, 'card': c}) assert strong.state == 2 and strong.damage == 3 # Weak player do nothing gc.ask_h = helpers.answer_sequence( ['Do nothing', 'Reveal and heal fully', 'Heal fully']) weak.damage = 3 c.use({'self': weak, 'card': c}) assert weak.state == 2 and weak.damage == 3 # Weak player reveal and full heal c.use({'self': weak, 'card': c}) assert weak.state == 1 and weak.damage == 0 # Weak player full heal weak.damage = 3 c.use({'self': weak, 'card': c}) assert weak.state == 1 and weak.damage == 0
def test_fields(): # Multiple runs to get many different shuffles for _ in range(C.N_ELEMENT_TESTS): # test initialization n_players = random.randint(4, 8) gc, ef = fresh_gc_ef(n_players) # test fields assert len(gc.players) == n_players assert gc.black_cards == ef.BLACK_DECK assert gc.white_cards == ef.WHITE_DECK assert gc.hermit_cards == ef.HERMIT_DECK assert not gc.modifiers assert gc.die4.n_sides == 4 assert gc.die6.n_sides == 6 for p in gc.players: assert p.gc == gc assert p.character is not None for a in ef.AREAS: assert a.zone is not None assert len(gc.zones) == 3 assert [len(z.areas) == 2 for z in gc.zones] # test dump public, private = gc.dump()
def test_getDeadPlayers(): gc, ef = fresh_gc_ef() # Check that no players are initially dead assert not gc.getDeadPlayers() # Check that dead players are properly included gc.players[0].setDamage(14, gc.players[1]) assert gc.getDeadPlayers() == [gc.players[0]]
def test_getLivePlayers(): gc, ef = fresh_gc_ef() # Check that all players are initially alive assert gc.getLivePlayers() == gc.players # Check that dead players are not included in alive players gc.players[0].setDamage(14, gc.players[1]) assert gc.getLivePlayers() == gc.players[1:]
def test_shadows_win(): # Check that shadows don't win until hunters are dead gc, ef = helpers.fresh_gc_ef() s = helpers.get_a_shadow(gc) assert not s.character.win_cond(gc, s) for p in gc.players: if p != s: p.setDamage(14, p) assert s.character.win_cond(gc, s) # Check that shadows win if three neutrals are dead gc, ef = helpers.fresh_gc_ef(7) s = helpers.get_a_shadow(gc) for p in gc.players: if p.character.alleg == 1: p.setDamage(14, p) assert s.character.win_cond(gc, s)
def test_choosePlayer(): # Setup rigged game context gc, ef = helpers.fresh_gc_ef() p1 = gc.players[0] # Check that chosen player is in gc and not self for _ in range(100): p2 = p1.choosePlayer() assert p2 in gc.players and p2 != p1
def test_move(): # Setup rigged game context gc, ef = helpers.fresh_gc_ef() p1 = gc.players[0] # Check that moving to a location updates player location a = helpers.get_area_by_name(gc, "Weird Woods") p1.move(a) assert p1.location == a
def test_defend(): # Setup rigged game context gc, ef = helpers.fresh_gc_ef() p1 = gc.players[0] p2 = gc.players[1] # Check that damage is dealt properly p1.defend(p2, 5) assert p1.damage == 5
def test_hunters_win(): # Check that hunters don't win until shadows are dead gc, ef = helpers.fresh_gc_ef() h = helpers.get_a_hunter(gc) assert not h.character.win_cond(gc, h) for p in gc.players: if p != h: p.setDamage(14, p) assert h.character.win_cond(gc, h)
def test_checkDeath(): p = helpers.fresh_gc_ef()[0].players[0] # Check that player is initially not dead p.checkDeath(p) assert p.state == 2 # Check that player dies when damage > max_damage p.damage = 20 p.checkDeath(p) assert p.state == 0
def setup_hermit(title, n_players=random.randint(5, 8)): """ Return a game context, element factory, a hunter, shadow and neutral from that game, and a card of a given title """ gc, ef = helpers.fresh_gc_ef(n_players) h = helpers.get_a_hunter(gc) s = helpers.get_a_shadow(gc) n = helpers.get_a_neutral(gc) c = helpers.get_card_by_title(ef, title) return (gc, ef, h, s, n, c)
def test_checkDeath(): p = H.fresh_gc_ef()[0].players[0] # Check that player is initially not dead p.checkDeath(p) assert p.state == C.PlayerState.Hidden # Check that player dies when damage > max_damage p.damage = 20 p.checkDeath(p) assert p.state == C.PlayerState.Dead
def test_holy_water(): for _ in range(100): # Setup rigged game context gc, ef = helpers.fresh_gc_ef() p1 = gc.players[0] c = helpers.get_card_by_title(ef, "Holy Water of Healing") # Check that holy water heals you by 2 p1.damage = 4 c.use({'self': p1, 'card': c}) assert p1.damage == 2
def test_first_aid(): for _ in range(100): # Setup rigged game context gc, ef = helpers.fresh_gc_ef() p1 = gc.players[0] c = helpers.get_card_by_title(ef, "First Aid") # Check that someone gets set to 7 by first aid and everyone else is # unaffected c.use({'self': p1, 'card': c}) damages = [p.damage for p in gc.players] assert len([d for d in damages if d == 7]) == 1 assert len([d for d in damages if d == 0]) == len(gc.players) - 1
def test_guardian_angel(): for _ in range(100): # Setup rigged game context gc, ef = helpers.fresh_gc_ef() p1 = gc.players[0] p2 = gc.players[1] c = helpers.get_card_by_title(ef, "Guardian Angel") # Check that p1 is immune to direct attacks c.use({'self': p1, 'card': c}) assert p1.modifiers['guardian_angel'] p2.attack(p1, 5) assert p1.damage == 0
def test_concealed_knowledge(): for _ in range(100): # Setup rigged game context gc, ef = helpers.fresh_gc_ef(8) position = random.randint(0, 7) p1 = gc.players[position] c = helpers.get_card_by_title(ef, "Concealed Knowledge") # Check that card inserts player in proper place c.use({'self': p1, 'card': c}) cur_turn = gc.turn_order[position] == p1 next_turn = gc.turn_order[position + 1] == p1 assert cur_turn and next_turn
def test_spiritual_doll(): for _ in range(C.N_ELEMENT_TESTS): # Setup rigged game context gc, ef = H.fresh_gc_ef() p1 = gc.players[0] p2 = gc.players[1] c = H.get_card_by_title(ef, "Spiritual Doll") gc.ask_h = H.answer_sequence( ["Use Spiritual Doll", p2.user_id, "Roll the 6-sided die!"]) # Check that someone gets hit c.use({'self': p1, 'card': c}) assert bool(p1.damage == 3) != bool(p2.damage == 3)
def test_moveDamage(): p = helpers.fresh_gc_ef()[0].players[0] # Check in-bounds movement p.moveDamage(-5, p) assert p.damage == 5 # Check ceiling of max_damage p.moveDamage(-50, p) assert p.damage == p.character.max_damage # Check floor of 0 p.moveDamage(100, p) assert p.damage == 0
def test_chooseEquipment(): # Setup rigged game context gc, ef = helpers.fresh_gc_ef() p1 = gc.players[0] p2 = gc.players[1] roly_hobe = helpers.get_card_by_title(ef, "Holy Robe") talisman = helpers.get_card_by_title(ef, "Talisman") p1.equipment = [roly_hobe, talisman] # Check that p2 always chooses an equipment from the options for _ in range(100): eq = p2.chooseEquipment(p1) assert eq == roly_hobe or eq == talisman
def test_vampire_bat(): for _ in range(C.N_ELEMENT_TESTS): # Setup rigged game context gc, ef = H.fresh_gc_ef() p1 = gc.players[0] c = H.get_card_by_title(ef, "Vampire Bat") # Check that user heals 1 damage and target takes 2 damage and everyone # else is unaffected p1.damage == 1 c.use({'self': p1, 'card': c}) damages = [p.damage for p in gc.players] assert len([d for d in damages if d == 2]) == 1 assert len([d for d in damages if d == 0]) == len(gc.players) - 1
def test_bloodthirsty_spider(): for _ in range(C.N_ELEMENT_TESTS): # Setup rigged game context gc, ef = H.fresh_gc_ef() p1 = gc.players[0] c = H.get_card_by_title(ef, "Bloodthirsty Spider") # Check that user and target take 2 damage and everyone else is # unaffected c.use({'self': p1, 'card': c}) damages = [p.damage for p in gc.players] assert p1.damage == 2 assert len([d for d in damages if d == 2]) == 2 assert len([d for d in damages if d == 0]) == len(gc.players) - 2
def test_flare_judgement(): for _ in range(100): # Setup rigged game context gc, ef = helpers.fresh_gc_ef() p1 = gc.players[0] c = helpers.get_card_by_title(ef, "Flare of Judgement") # Check that flare hits everyone for 2 except you c.use({'self': p1, 'card': c}) for p in gc.players: if p != p1: assert p.damage == 2 else: assert p.damage == 0
def test_underworld_gate(): # Set up rigged game context gc, ef = H.fresh_gc_ef() p1 = gc.players[0] area = H.get_area_by_name(gc, "Underworld Gate") whites = copy.copy(gc.white_cards.cards) blacks = copy.copy(gc.black_cards.cards) hermits = copy.copy(gc.hermit_cards.cards) # Make sure one of the card piles was taken from area.action(gc, p1) neq_whites = gc.white_cards.cards != whites neq_blacks = gc.black_cards.cards != blacks neq_hermits = gc.hermit_cards.cards != hermits assert neq_whites or neq_blacks or neq_hermits
def test_giveEquipment(): # Setup rigged game context gc, ef = helpers.fresh_gc_ef() p1 = gc.players[0] p2 = gc.players[1] roly_hobe = helpers.get_card_by_title(ef, "Holy Robe") p1.equipment.append(roly_hobe) # P1 gives holy robe to P2 p1.giveEquipment(p2, roly_hobe) # Check that P1 lost holy robe, check that P2 got it assert roly_hobe.holder == p2 assert not p1.equipment assert roly_hobe in p2.equipment