Skip to content

Commit

Permalink
test: The Bell
Browse files Browse the repository at this point in the history
  • Loading branch information
zyr17 committed Sep 3, 2023
1 parent 95bdd6a commit c124836
Showing 1 changed file with 105 additions and 0 deletions.
105 changes: 105 additions & 0 deletions tests/server/cards/test_weapons.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,110 @@ def test_vanilla_weapons():
assert match.state != MatchState.ERROR


def test_the_bell():
cmd_records = [
[
"sw_card",
"choose 0",
"card 0 1 0 1 2",
"skill 0 0 1 2",
"TEST 1 p1 status 1 usage 1",
"end",
"end",
"end",
"sw_char 1 0",
"TEST 1 p1 status 1 usage 2",
"skill 1 0 1 2",
"TEST 1 p1 status 1 usage 2",
"end"
],
[
"sw_card",
"choose 0",
"TEST 1 p0 status 0 usage 0",
"card 0 0 0 1 2",
"skill 0 0 1 2",
"skill 0 0 1 2",
"TEST 1 p1 status 1 usage 1",
"end",
"skill 1 0 1 2",
"TEST 1 p1 status 1 usage 2",
"end",
"end",
"skill 1 0 1 2",
"card 0 0 0 1 2",
"skill 1 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
deck = Deck.from_str(
'''
charactor:Arataki Itto
charactor:Barbara
charactor:Noelle
The Bell*30
'''
)
match.set_deck([deck, deck])
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:
cmd = cmd.strip().split()
pid = int(cmd[2][1])
snum = int(cmd[4])
usage = int(cmd[6])
status = match.player_tables[pid].team_status
assert len(status) == snum
if snum:
assert status[0].usage == usage
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_vanilla_weapons()
test_the_bell()

0 comments on commit c124836

Please sign in to comment.