diff --git a/tests/server/test_elemental_reaction.py b/tests/server/test_elemental_reaction.py index bcb87bde..7af80eff 100644 --- a/tests/server/test_elemental_reaction.py +++ b/tests/server/test_elemental_reaction.py @@ -58,7 +58,6 @@ def test_crystallize(): random_after_no_command = True ) match = Match() - # match.enable_history = True deck = { 'name': 'Deck', 'charactors': [ @@ -149,7 +148,6 @@ def test_frozen(): random_after_no_command = True ) match = Match() - # match.enable_history = True deck = { 'name': 'Deck', 'charactors': [ @@ -177,7 +175,6 @@ def test_frozen(): match.match_config.max_same_card_number = 30 match.match_config.random_first_player = False set_16_omni(match) - match.enable_history = True assert match.start() match.step() @@ -219,5 +216,306 @@ def test_frozen(): assert match.match_state != MatchState.ERROR +def test_frozen_and_pyro(): + """ + agent 0 goes first, sw 2, 1 cryo to p1c2, sw 0, 1 hydro to p1c2, + 1 hydro to p1c2, sw 1, 1 pyro to p1c2, end, 1 pyro to p1c2, sw 2, + 1 cryo to p1c2, 1 cryo to p1c2, sw 0, 1 hydro to p1c2, sw 1, end, + 1 pyro to p1c2, end. + agent 1 end, end, end. + """ + agent_0 = InteractionAgent( + player_id = 0, + verbose_level = 0, + commands = [ + 'sw_card', + 'choose 2', + 'skill 0 omni omni omni', + 'sw_char 0 omni', + 'skill 0 omni omni omni', + 'skill 0 omni omni omni', + 'sw_char 1 omni', + 'skill 0 omni omni omni', + 'end', + 'skill 0 omni omni omni', + 'sw_char 2 omni', + 'skill 0 omni omni omni', + 'skill 0 omni omni omni', + 'sw_char 0 omni', + 'skill 0 omni omni omni', + 'sw_char 1 omni', + 'end', + 'skill 0 omni omni omni', + 'end', + ], + random_after_no_command = True + ) + agent_1 = InteractionAgent( + player_id = 1, + verbose_level = 0, + commands = [ + 'sw_card', + 'choose 2', + 'end', + 'end', + 'end', + ], + random_after_no_command = True + ) + match = Match() + deck = { + 'name': 'Deck', + 'charactors': [ + { + 'name': 'HydroMobMage', + 'element': 'HYDRO', + }, + { + 'name': 'PyroMobMage', + 'element': 'PYRO', + }, + { + 'name': 'CryoMobMage', + 'element': 'CRYO', + 'hp': 99, + 'max_hp': 99, + }, + ], + 'cards': [ + { + 'name': 'Strategize', + } + ] * 30, + } + deck = Deck(**deck) + match.set_deck([deck, deck]) + match.match_config.max_same_card_number = 30 + match.match_config.random_first_player = False + set_16_omni(match) + assert match.start() + match.step() + + while True: + if match.need_respond(0): + make_respond(agent_0, match) + elif match.need_respond(1): + make_respond(agent_1, match) + if len(agent_1.commands) == 0 and len(agent_0.commands) == 0: + break + + assert len(agent_0.commands) == 0 + assert len(agent_1.commands) == 0 + assert match.round_number == 4 + check_hp(match, [[10, 10, 99], [10, 10, 82]]) + assert match.player_tables[1].charactors[2].element_application == ['PYRO'] + + assert match.match_state != MatchState.ERROR + + +def test_burning_fire(): + """ + agent 0 goes first, sw 2, 1 pyro to p1c2, sw 0, 1 dendro to p1c2, end, + 1 dendro to p1c2, end, 1 dendro to p1c2, 1 dendro to p1c2, sw 2, + 1 pyro to p1c2, sw 0, 1 dendro to p1c2, end, 1 dendro to p1c2, + sw 2, 1 pyro to p1c2, end. + agent 1 sw2, end, end, end, end. + result: 18 damage and 2 burning fire. + """ + agent_0 = InteractionAgent( + player_id = 0, + verbose_level = 0, + commands = [ + 'sw_card', + 'choose 2', + 'skill 0 omni omni omni', + 'sw_char 0 omni', + 'skill 0 omni omni omni', + 'end', + 'skill 0 omni omni omni', + 'end', + 'skill 0 omni omni omni', + 'skill 0 omni omni omni', + 'sw_char 2 omni', + 'skill 0 omni omni omni', + 'sw_char 0 omni', + 'skill 0 omni omni omni', + 'end', + 'skill 0 omni omni omni', + 'sw_char 2 omni', + 'skill 0 omni omni omni', + 'end', + ], + random_after_no_command = True + ) + agent_1 = InteractionAgent( + player_id = 1, + verbose_level = 0, + commands = [ + 'sw_card', + 'choose 2', + 'end', + 'end', + 'end', + 'end', + ], + random_after_no_command = True + ) + match = Match() + deck = { + 'name': 'Deck', + 'charactors': [ + { + 'name': 'DendroMobMage', + 'element': 'DENDRO', + }, + { + 'name': 'DendroMobMage', + 'element': 'DENDRO', + }, + { + 'name': 'PyroMobMage', + 'element': 'PYRO', + 'hp': 99, + 'max_hp': 99, + }, + ], + 'cards': [ + { + 'name': 'Strategize', + } + ] * 30, + } + deck = Deck(**deck) + match.set_deck([deck, deck]) + match.match_config.max_same_card_number = 30 + match.match_config.random_first_player = False + set_16_omni(match) + assert match.start() + match.step() + + while True: + if match.need_respond(0): + make_respond(agent_0, match) + elif match.need_respond(1): + make_respond(agent_1, match) + if len(agent_1.commands) == 0 and len(agent_0.commands) == 0: + break + + assert len(agent_0.commands) == 0 + assert len(agent_1.commands) == 0 + assert match.round_number == 5 + assert len(match.player_tables[0].summons) == 1 + assert match.player_tables[0].summons[0].name == 'Burning Flame' + assert match.player_tables[0].summons[0].usage == 1 + check_hp(match, [[10, 10, 99], [10, 10, 80]]) + + assert match.match_state != MatchState.ERROR + + +def test_dendro_core_catalyzing_field(): + """ + agent 0 goes first, sw 2, 1 electro to p1c2, sw 0, 1 dendro to p1c2, + 1 dendro to p1c2, sw 1, 1 hydro to p1c2, sw 2, end, 1 electro to p1c2, + sw 1, 1 hydro to p1c2, 1 hydro to p1c2, sw 0, 1 dendro to p1c2, end, + 1 dendro to p1c2, sw 1, 1 hydro to p1c2, sw 2, 1 electro to p1c2, + 1 electro to p1c2, end. + agent 1 sw2, end, end, end. + tested catalyzing field and dendro core will not disappear at round end, + can trigger simultaneously, and max dendro core number is 1. + result: 22 damage and no status. + """ + agent_0 = InteractionAgent( + player_id = 0, + verbose_level = 0, + commands = [ + 'sw_card', + 'choose 2', + 'skill 0 omni omni omni', + 'sw_char 0 omni', + 'skill 0 omni omni omni', + 'skill 0 omni omni omni', + 'sw_char 1 omni', + 'skill 0 omni omni omni', + 'sw_char 2 omni', + 'end', + 'skill 0 omni omni omni', + 'sw_char 1 omni', + 'skill 0 omni omni omni', + 'skill 0 omni omni omni', + 'sw_char 0 omni', + 'skill 0 omni omni omni', + 'end', + 'skill 0 omni omni omni', + 'sw_char 1 omni', + 'skill 0 omni omni omni', + 'sw_char 2 omni', + 'skill 0 omni omni omni', + 'skill 0 omni omni omni', + 'end', + ], + random_after_no_command = True + ) + agent_1 = InteractionAgent( + player_id = 1, + verbose_level = 0, + commands = [ + 'sw_card', + 'choose 2', + 'end', + 'end', + 'end', + ], + random_after_no_command = True + ) + match = Match() + deck = { + 'name': 'Deck', + 'charactors': [ + { + 'name': 'DendroMobMage', + 'element': 'DENDRO', + }, + { + 'name': 'HydroMobMage', + 'element': 'HYDRO', + }, + { + 'name': 'ElectroMobMage', + 'element': 'ELECTRO', + 'hp': 99, + 'max_hp': 99, + }, + ], + 'cards': [ + { + 'name': 'Strategize', + } + ] * 30, + } + deck = Deck(**deck) + match.set_deck([deck, deck]) + match.match_config.max_same_card_number = 30 + match.match_config.random_first_player = False + set_16_omni(match) + assert match.start() + match.step() + + while True: + if match.need_respond(0): + make_respond(agent_0, match) + elif match.need_respond(1): + make_respond(agent_1, match) + if len(agent_1.commands) == 0 and len(agent_0.commands) == 0: + break + + assert len(agent_0.commands) == 0 + assert len(agent_1.commands) == 0 + assert match.round_number == 4 + assert len(match.player_tables[0].team_status) == 0 + check_hp(match, [[10, 10, 99], [9, 9, 76]]) + + assert match.match_state != MatchState.ERROR + + if __name__ == '__main__': - test_frozen() + test_frozen_and_pyro() diff --git a/tests/utils_for_test.py b/tests/utils_for_test.py index e8534431..e6aa241c 100644 --- a/tests/utils_for_test.py +++ b/tests/utils_for_test.py @@ -30,12 +30,8 @@ def check_hp(match: Match, hp: List[List[int]]): """ input hps for each player and check """ - assert len(match.player_tables) == len(hp) - for h, t in zip(hp, match.player_tables): - c = t.charactors - assert len(c) == len(h) - for onec, oneh in zip(c, h): - assert onec.hp == oneh + hps = [[x.hp for x in t.charactors] for t in match.player_tables] + assert hps == hp def check_name(name: str, lists: List[Any], exist: bool = True):