Skip to content

Commit

Permalink
test: scenario test: maguu kenki 1 burst 3 defeat
Browse files Browse the repository at this point in the history
  • Loading branch information
zyr17 committed Sep 7, 2023
1 parent 507b41c commit f4261cd
Showing 1 changed file with 289 additions and 0 deletions.
289 changes: 289 additions & 0 deletions tests/server/scenario/test_maguu_kenki_10_10_10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,289 @@
from agents.interaction_agent import InteractionAgent
from server.match import Match, MatchState
from server.deck import Deck
from tests.utils_for_test import (
check_hp, get_random_state, get_test_id_from_command, make_respond,
set_16_omni
)


def test_maguu_kenki_10_10_10():
cmd_records = [
[
"sw_card",
"choose 2",
"skill 1 0 1 2",
"skill 1 0 1 2",
"skill 1 0 1 2",
"skill 1 0 1 2",
"end",
"skill 1 0 1 2",
"skill 1 0 1 2",
"sw_char 0 0",
"sw_char 1 0",
"sw_char 0 0",
"card 0 0 0",
"end",
"sw_char 2 0",
"end",
"skill 1 0 1 2",
"sw_char 0 0",
"skill 1 0 1 2",
"sw_char 2",
"skill 1 0 1 2",
"sw_char 0",
"sw_char 1 0",
"skill 1 0 1 2",
"card 0 0 0",
"end",
"card 0 0 0",
"card 0 0 0",
"skill 1 0 1 2"
],
[
"sw_card",
"choose 2",
"skill 0 0 1 2",
"skill 0 0 1 2",
"skill 0 0 1 2",
"sw_char 0 0",
"skill 2 0 1 2 3 4",
"end",
"skill 0 0 1 2",
"sw_char 1 0",
"skill 2 0 1 2",
"sw_char 0 0",
"end",
"end",
"sw_char 1 0",
"skill 0 0 1 2",
"sw_char 0 0",
"skill 3 0 1 2",
"sw_char 1 0",
"skill 1 0 1 2",
"sw_char 2 0",
"skill 2 0 1 2",
"end",
"card 0 0 0 1 2",
"sw_char 1 0",
"TEST 1 10 10 10 6 6 4",
"skill 3 0 1 2"
]
]
agent_0 = InteractionAgent(
player_idx = 0,
verbose_level = 0,
commands = cmd_records[0],
only_use_command = True
)
agent_1 = InteractionAgent(
player_idx = 1,
verbose_level = 0,
commands = cmd_records[1],
only_use_command = True
)
# initialize match. It is recommended to use default random state to make
# replay unchanged.
match = Match(random_state = get_random_state())
# deck information
deck1 = Deck.from_str(
'''
charactor:Venti
charactor:Xingqiu
charactor:Noelle
Mondstadt Hash Brown*30
'''
)
deck2 = Deck.from_str(
'''
charactor:Nahida
charactor:Maguu Kenki
charactor:Yoimiya
A Thousand Floating Dreams*30
'''
)
match.set_deck([deck1, deck2])
match.config.max_same_card_number = None
match.config.charactor_number = None
match.config.card_number = None
# check whether random_first_player is enabled.
match.config.random_first_player = False
# check whether in rich mode (16 omni each round)
set_16_omni(match)
match.start()
match.step()

while True:
if match.need_respond(0):
agent = agent_0
elif match.need_respond(1):
agent = agent_1
else:
raise AssertionError('No need respond.')
# do tests
while True:
cmd = agent.commands[0]
test_id = get_test_id_from_command(agent)
if test_id == 0:
# id 0 means current command is not a test command.
break
elif test_id == 1:
# a sample of HP check based on the command string.
hps = cmd.strip().split(' ')[2:]
hps = [int(x) for x in hps]
hps = [hps[:3], hps[3:]]
check_hp(match, hps)
else:
raise AssertionError(f'Unknown test id {test_id}')
# respond
make_respond(agent, match)
if len(agent_1.commands) == 0 and len(agent_0.commands) == 0:
break

# simulate ends, check final state
assert match.state == MatchState.ENDED


def test_maguu_kenki_10_10_10_2():
cmd_records = [
[
"sw_card",
"choose 2",
"skill 1 0 1 2",
"skill 1 0 1 2",
"skill 1 0 1 2",
"skill 1 0 1 2",
"end",
"skill 1 0 1 2",
"skill 1 0 1 2",
"sw_char 0 0",
"sw_char 1 0",
"sw_char 0 0",
"card 0 0 0",
"end",
"sw_char 2 0",
"end",
"skill 1 0 1 2",
"sw_char 0 0",
"skill 1 0 1 2",
"sw_char 2",
"skill 1 0 1 2",
"sw_char 0",
"sw_char 1 0",
"skill 1 0 1 2",
"card 0 0 0",
"end",
"card 0 0 0",
"card 0 0 0",
"skill 1 0 1 2",
"TEST 1 10 10 10 6 6 4",
"end"
],
[
"sw_card",
"choose 2",
"skill 0 0 1 2",
"skill 0 0 1 2",
"skill 0 0 1 2",
"sw_char 0 0",
"skill 2 0 1 2 3 4",
"end",
"skill 0 0 1 2",
"sw_char 1 0",
"skill 2 0 1 2",
"sw_char 0 0",
"end",
"end",
"sw_char 1 0",
"skill 0 0 1 2",
"sw_char 0 0",
"skill 3 0 1 2",
"sw_char 1 0",
"skill 1 0 1 2",
"sw_char 2 0",
"skill 2 0 1 2",
"end",
"card 0 0 0 1 2",
"sw_char 1 0",
"TEST 1 20 20 20 6 6 4",
"skill 3 0 1 2"
]
]
agent_0 = InteractionAgent(
player_idx = 0,
verbose_level = 0,
commands = cmd_records[0],
only_use_command = True
)
agent_1 = InteractionAgent(
player_idx = 1,
verbose_level = 0,
commands = cmd_records[1],
only_use_command = True
)
# initialize match. It is recommended to use default random state to make
# replay unchanged.
match = Match(random_state = get_random_state())
# deck information
deck1 = Deck.from_str(
'''
charactor:Venti
charactor:Xingqiu
charactor:Noelle
Mondstadt Hash Brown*30
'''
)
for c in deck1.charactors:
c.hp = c.max_hp = 20
deck2 = Deck.from_str(
'''
charactor:Nahida
charactor:Maguu Kenki
charactor:Yoimiya
A Thousand Floating Dreams*30
'''
)
match.set_deck([deck1, deck2])
match.config.max_same_card_number = None
match.config.charactor_number = None
match.config.card_number = None
# check whether random_first_player is enabled.
match.config.random_first_player = False
# check whether in rich mode (16 omni each round)
set_16_omni(match)
match.start()
match.step()

while True:
if match.need_respond(0):
agent = agent_0
elif match.need_respond(1):
agent = agent_1
else:
raise AssertionError('No need respond.')
# do tests
while True:
cmd = agent.commands[0]
test_id = get_test_id_from_command(agent)
if test_id == 0:
# id 0 means current command is not a test command.
break
elif test_id == 1:
# a sample of HP check based on the command string.
hps = cmd.strip().split(' ')[2:]
hps = [int(x) for x in hps]
hps = [hps[:3], hps[3:]]
check_hp(match, hps)
else:
raise AssertionError(f'Unknown test id {test_id}')
# respond
make_respond(agent, match)
if len(agent_1.commands) == 0 and len(agent_0.commands) == 0:
break

# simulate ends, check final state
assert match.state != MatchState.ERROR


if __name__ == '__main__':
test_maguu_kenki_10_10_10_2()

0 comments on commit f4261cd

Please sign in to comment.