Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# 2#
########
""",
"""
########
#0 .. 3#
#2 1#
########
"""
]
def move(bot, state):
if not bot.is_blue and bot.turn == 1 and bot.round == 1:
return (6, 1)
return bot.position
layouts = [layout.parse_layout(l) for l in cascade]
state = setup_game([move, move], max_rounds=5, layout_dict=layout.parse_layout(cascade[0]))
assert state['bots'] == layouts[0]['bots']
state = game.play_turn(state) # Bot 0 stands
assert state['bots'] == layouts[0]['bots']
state = game.play_turn(state) # Bot 1 stands
state = game.play_turn(state) # Bot 2 stands
state = game.play_turn(state) # Bot 3 moves, kills 0. Bot 0 and 1 are on same spot
assert state['bots'] == layouts[1]['bots']
state = game.play_turn(state) # Bot 0 stands, kills 1. Bot 1 and 2 are on same spot
assert state['bots'] == layouts[2]['bots']
state = game.play_turn(state) # Bot 1 stands, kills 2.
assert state['bots'] == layouts[3]['bots']
#0#. . # . #
#2##### #####3#
# . # . .#1#
################## """
# remove bot x when bots_hidden[x] is True
for x in range(4):
if bots_hidden[x]:
test_layout = test_layout.replace(str(x), ' ')
parsed_layout = layout.parse_layout(test_layout)
# dummy player
stopping = lambda bot, s: (bot.position, s)
if list(bots_hidden) == [False] * 4:
# no bots are hidden. it should succeed
setup_game([stopping, stopping], layout_dict=parsed_layout, max_rounds=10)
else:
with pytest.raises(ValueError):
setup_game([stopping, stopping], layout_dict=parsed_layout, max_rounds=10)
def test_setup_game_with_different_number_of_bots(self, bots):
layout = """
######
# . #
# .# #
######
"""
bot_pos, should_succeed = bots
parsed = parse_layout(layout)
parsed['bots'] = bot_pos
if should_succeed:
state = setup_game([stopping_player] * 2, layout_dict=parsed, max_rounds=5)
assert state['bots'] == bot_pos
state = run_game([stopping_player] * 2, layout_dict=parsed, max_rounds=5)
assert state['fatal_errors'] == [[], []]
assert state['errors'] == [{}, {}]
else:
with pytest.raises(ValueError):
setup_game([stopping_player] * 2, layout_dict=parsed, max_rounds=300)
# 2#
########
""",
"""
########
#0 .. 3#
#2 1#
########
"""
]
def move(bot, state):
if bot.is_blue and bot.turn == 0 and bot.round == 1:
return (6, 1)
return bot.position
layouts = [layout.parse_layout(l) for l in cascade]
state = setup_game([move, move], max_rounds=5, layout_dict=layout.parse_layout(cascade[0]))
assert state['bots'] == layouts[0]['bots']
state = game.play_turn(state) # Bot 0 moves onto 3. Gets killed. Bot 0 and 1 are on same spot.
assert state['bots'] == layouts[1]['bots']
state = game.play_turn(state) # Bot 1 moves, gets killed. Bot 1 and 2 are on same spot
assert state['bots'] == layouts[2]['bots']
state = game.play_turn(state) # Bot 2 moves, gets killed.
assert state['bots'] == layouts[3]['bots']
#2 #
########
""",
"""
########
#0 .. 3#
#2 1#
########
"""
]
def move(bot, state):
if bot.is_blue and bot.turn == 0 and bot.round == 1:
return (1, 1)
return bot.position
layouts = [layout.parse_layout(l) for l in cascade]
state = setup_game([move, move], max_rounds=5, layout_dict=layout.parse_layout(cascade[0]))
assert state['bots'] == layouts[0]['bots']
state = game.play_turn(state) # Bot 0 moves, kills 3. Bot 2 and 3 are on same spot
assert state['bots'] == layouts[1]['bots']
state = game.play_turn(state) # Bot 1 stands. Bot 2 and 3 are on same spot
assert state['bots'] == layouts[1]['bots']
state = game.play_turn(state) # Bot 2 stands, gets killed. Bot 1 and 2 are on same spot
assert state['bots'] == layouts[2]['bots']
state = game.play_turn(state) # Bot 3 stands. Bot 1 and 2 are on same spot
assert state['bots'] == layouts[2]['bots']
state = game.play_turn(state) # Bot 0 stands. Bot 1 and 2 are on same spot
assert state['bots'] == layouts[2]['bots']
state = game.play_turn(state) # Bot 1 stands, kills 2.
assert state['bots'] == layouts[3]['bots']
def setup_random_basic_gamestate(*, round=1, turn=0):
"""helper function for testing play turn"""
l = layout.get_layout_by_name("small_100")
parsed_l = layout.parse_layout(l)
stopping = lambda bot, s: (bot.position, s)
game_state = setup_game([stopping, stopping], layout_dict=parsed_l)
game_state['round'] = round
game_state['turn'] = turn
return game_state
def test_too_few_registered_teams(self):
test_layout_4 = (
""" ##################
#0#. . # . #
#2##### #####1#
# . # . .#3#
################## """)
team_1 = stopping_player
with pytest.raises(ValueError):
setup_game([team_1], layout_dict=parse_layout(test_layout_4), max_rounds=300)
"""helper function for testing play turn"""
l = """
##################
#. ... .##. 3#
# # # . .### #1#
# # ##. . #
# . .## # #
#0# ###. . # # #
#2 .##. ... .#
##################
"""
parsed_l = layout.parse_layout(l)
stopping = lambda bot, s: (bot.position, s)
game_state = setup_game([stopping, stopping], layout_dict=parsed_l)
game_state['round'] = round
game_state['turn'] = turn
return game_state
def test_stepping_players(self):
test_layout = (
""" ############
#a . . x#
#b y#
############ """)
movements_0 = [east, east]
movements_1 = [west, west]
teams = [
stepping_player(movements_0, movements_0),
stepping_player(movements_1, movements_1)
]
state = setup_game(teams, layout_dict=parse_layout(test_layout), max_rounds=2)
assert state['bots'] == [(1, 1), (10, 1), (1, 2), (10, 2)]
state = run_game(teams, layout_dict=parse_layout(test_layout), max_rounds=2)
assert state['bots'] == [(3, 1), (8, 1), (3, 2), (8, 2)]