Esempio n. 1
0
def test_corner_strategy(sample_snake, directions):
    strategy = CornerStrategy(
        TurnContext(0, 0, 0, [], sample_snake, [sample_snake], [])
    )
    direction = strategy.get_action()
    assert isinstance(direction, str)
    assert direction in directions
Esempio n. 2
0
def test_avoid_food_strategy(sample_snake, directions):
    snake = clone(sample_snake, health=41, body=sample_snake["body"] * 4)
    strategy = AvoidFoodStrategy(TurnContext(0, 0, 0, [], snake, [snake], []))
    direction = strategy.get_action()
    assert isinstance(direction, str)
    assert direction in directions
Esempio n. 3
0
def test_prefer_food_strategy(sample_snake, directions):
    snake = clone(sample_snake, health=40)
    strategy = PreferFoodStrategy(TurnContext(0, 0, 0, [], snake, [snake], []))
    direction = strategy.get_action()
    assert isinstance(direction, str)
    assert direction in directions
Esempio n. 4
0
def test_choose_strategy_avoid_food_strategy(sample_snake):
    snake = clone(sample_snake, health=41, body=sample_snake["body"] * 4)
    result = choose_strategy(TurnContext(0, 0, 0, [], snake, [snake], []))
    assert isinstance(result, AvoidFoodStrategy)
Esempio n. 5
0
def test_choose_strategy_prefer_food_strategy(sample_snake):
    snake = clone(sample_snake, health=40)
    result = choose_strategy(TurnContext(0, 0, 0, [], snake, [snake], []))
    assert isinstance(result, PreferFoodStrategy)
Esempio n. 6
0
def test_choose_strategy_corner_strategy(sample_snake):
    result = choose_strategy(TurnContext(0, 0, 0, [], sample_snake, [sample_snake], []))
    assert isinstance(result, CornerStrategy)
Esempio n. 7
0
def test_choose_strategy_force_strategy(sample_snake):
    result = choose_strategy(
        TurnContext(0, 0, 0, [], sample_snake, [sample_snake], []),
        {"FORCE_STRATEGY": "RANDOM"},
    )
    assert isinstance(result, RandomStrategy)