Пример #1
0
def test_seeds_do_not_land_in_hive():
    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=((Hive(5, 5), ), ),
                     flowers=((), ),
                     game_length=sentinel.game_length)

    assert all(
        board.calculate_score() == DEFAULT_GAME_PARAMETERS.hive_score_factor
        for board in game.boards)

    game.boards[0].inflight[sentinel.seed_1] = Seed(5, 5, 0)
    landed_bees = game.land_bees()

    for board in game.boards:
        assert sentinel.bee_1 not in board.inflight

    assert [board.calculate_score() for board in game.boards
            ] == [DEFAULT_GAME_PARAMETERS.hive_score_factor]
    assert landed_bees == [{}]
    assert game.boards[0].inflight == {sentinel.seed_1: Seed(5, 5, 0)}
    assert check_bee_nectar_eq_hive_nectar(landed_bees, game)
Пример #2
0
def test_can_set_position():
    seed = Seed(sentinel.x, sentinel.y, sentinel.h)
    assert seed.set_position(sentinel.newx,
                             sentinel.newy) == Seed(sentinel.newx,
                                                    sentinel.newy, sentinel.h)

    # Original instance is not actually changed
    assert seed == Seed(sentinel.x, sentinel.y, sentinel.h)
Пример #3
0
def test_can_advance_seed_along_a_heading(heading, column):
    # Rather than patch heading_to_delta in Seed.advance we just
    # assert that the effect of advancing the seed matches that
    # defined by heading_to_delta

    expected_dx, expected_dy = heading_to_delta(heading, is_even(column))

    seed = Seed(column, 5, heading)
    assert seed.advance() == Seed(column + expected_dx, 5 + expected_dy,
                                  heading)

    # Original instance is not actually changed
    assert seed == Seed(column, 5, heading)
Пример #4
0
def test_TrapSeed_not_equal_to_other_types():
    assert not (TrapSeed(sentinel.x, sentinel.y, sentinel.h, mock_game_params)
                == sentinel.TrapSeed)
    assert TrapSeed(sentinel.x, sentinel.y, sentinel.h,
                    mock_game_params) != sentinel.TrapSeed

    assert not (TrapSeed(sentinel.x, sentinel.y, sentinel.h, mock_game_params)
                == Seed(sentinel.x, sentinel.y, sentinel.h))
    assert TrapSeed(sentinel.x, sentinel.y,
                    sentinel.h, mock_game_params) != Seed(
                        sentinel.x, sentinel.y, sentinel.h)

    assert not (Seed(sentinel.x, sentinel.y, sentinel.h) == TrapSeed(
        sentinel.x, sentinel.y, sentinel.h, mock_game_params))
    assert Seed(sentinel.x, sentinel.y, sentinel.h) != TrapSeed(
        sentinel.x, sentinel.y, sentinel.h, mock_game_params)
Пример #5
0
def test_only_queenbees_can_create_hive():
    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=[[]],
                     flowers=[[Flower(1, 2, DEFAULT_GAME_PARAMETERS)]],
                     game_length=sentinel.game_length)

    queen_bee = QueenBee(4,
                         4,
                         0,
                         10,
                         DEFAULT_GAME_PARAMETERS,
                         nectar=sentinel.nectar)
    game.boards[0].inflight[sentinel.bee_1] = Bee(4, 5, 0, 10,
                                                  DEFAULT_GAME_PARAMETERS)
    game.boards[0].inflight[sentinel.queenbee_1] = queen_bee
    game.boards[0].inflight[sentinel.seed_1] = Seed(3, 3, 0)

    with pytest.raises(RuntimeError):
        game.apply_commands(
            [dict(entity=sentinel.bee_1, command="create_hive")])

    with pytest.raises(RuntimeError):
        game.apply_commands(
            [dict(entity=sentinel.seed_1, command="create_hive")])

    game.apply_commands(
        [dict(entity=sentinel.queenbee_1, command="create_hive")])
    assert game.boards[0].hives[0] == Hive(queen_bee.x, queen_bee.y,
                                           queen_bee.nectar)
    assert len(game.boards[0].inflight) == 2
Пример #6
0
def test_seed_does_not_visit_flower():
    game = GameState(
        game_params=DEFAULT_GAME_PARAMETERS,
        game_id=sentinel.game_id,
        boards=1,
        board_width=10,
        board_height=10,
        hives=(sentinel.hives, ),
        flowers=((Flower(
            5, 5, DEFAULT_GAME_PARAMETERS, 1,
            DEFAULT_GAME_PARAMETERS.flower_lifespan_visit_impact), ), ),
        game_length=sentinel.game_length)

    game.boards[0].inflight[sentinel.seed_1] = Seed(5, 5, 0)
    game.visit_flowers()

    assert game.boards[0].inflight == {sentinel.seed_1: Seed(5, 5, 0)}
Пример #7
0
def test_flowers_seeds_make_flowers_means_points():
    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=((Hive(9, 9), ), ),
                     flowers=((), ),
                     game_length=sentinel.game_length)

    assert all(
        board.calculate_score() == DEFAULT_GAME_PARAMETERS.hive_score_factor
        for board in game.boards)

    game.boards[0].inflight[sentinel.seed_1] = Seed(4, 5, 0)
    game.apply_commands([dict(entity=sentinel.seed_1, command="flower")])

    assert all(board.calculate_score() == (
        DEFAULT_GAME_PARAMETERS.hive_score_factor +
        DEFAULT_GAME_PARAMETERS.flower_score_factor) for board in game.boards)
Пример #8
0
def test_visiting_flower_creates_seed_every_ten_visits(_, visits):
    game = GameState(
        game_params=DEFAULT_GAME_PARAMETERS,
        game_id=sentinel.game_id,
        boards=1,
        board_width=10,
        board_height=10,
        hives=(sentinel.hives, ),
        flowers=((Flower(
            5, 5, DEFAULT_GAME_PARAMETERS, 3, visits - 1,
            DEFAULT_GAME_PARAMETERS.flower_lifespan_visit_impact), ), ),
        game_length=sentinel.game_length)

    game.boards[0].inflight[sentinel.bee_1] = Bee(5, 5, 0, 10,
                                                  DEFAULT_GAME_PARAMETERS)
    game.visit_flowers()

    assert game.boards[0].inflight == {
        sentinel.bee_1: Bee(5, 5, 0, 85, DEFAULT_GAME_PARAMETERS, 3),
        'sentinel.uuid': Seed(5, 5, ANY)
    }
Пример #9
0
def test_apply_flower_command_empty_tile():
    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=((Hive(9, 9), ), ),
                     flowers=((Flower(0, 0, DEFAULT_GAME_PARAMETERS), ), ),
                     turn_num=12345,
                     game_length=sentinel.game_length)

    game.boards[0].inflight[sentinel.seed_1] = Seed(4, 5, 0)
    game.apply_commands([dict(entity=sentinel.seed_1, command="flower")])

    assert game.boards[0].inflight == {}
    assert game.boards[0].flowers == (Flower(0, 0, DEFAULT_GAME_PARAMETERS),
                                      Flower(4,
                                             5,
                                             DEFAULT_GAME_PARAMETERS,
                                             expires=12645))
    assert game.boards[0].hives == (Hive(9, 9), )
Пример #10
0
def test_apply_flower_command_over_existing_flower():
    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=((Hive(9, 9), ), ),
                     flowers=((Flower(0, 0, DEFAULT_GAME_PARAMETERS,
                                      sentinel.potency, sentinel.visits), ), ),
                     turn_num=12345,
                     game_length=sentinel.game_length)

    game.boards[0].inflight[sentinel.seed_1] = Seed(0, 0, 0)
    game.apply_commands([dict(entity=sentinel.seed_1, command="flower")])

    assert game.boards[0].inflight == {}
    assert game.boards[0].flowers == (Flower(
        0,
        0,
        DEFAULT_GAME_PARAMETERS,
        1,
        0,
        expires=12345 + DEFAULT_GAME_PARAMETERS.flower_lifespan), )
    assert game.boards[0].hives == (Hive(9, 9), )
Пример #11
0
def test_seed_not_equal_to_other_types():
    assert not (Seed(sentinel.x, sentinel.y, sentinel.h) == sentinel.seed)
    assert Seed(sentinel.x, sentinel.y, sentinel.h) != sentinel.seed
Пример #12
0
def test_can_reverse_a_seed_along_a_heading():
    seed = Seed(5, 5, 0)
    assert seed.advance(reverse=True) == Seed(5, 4, 180)

    # Original instance is not actually changed
    assert seed == Seed(5, 5, 0)
Пример #13
0
                     hives=[sentinel.hives] * boards,
                     flowers=[sentinel.flowers] * boards,
                     game_length=sentinel.game_length)

    game.boards[0].inflight[sentinel.seed_1] = from_details
    game.move_volants()

    assert [
        i for i, board in enumerate(game.boards)
        if sentinel.seed_1 in board.inflight
    ] == [to_board]
    assert game.boards[to_board].inflight == {sentinel.seed_1: to_details}


@pytest.mark.parametrize(("from_details", "to_details"), [
    (Seed(4, 5, 0), Seed(4, 6, 0)),
    (Seed(4, 5, 180), Seed(4, 4, 180)),
    (Seed(4, 5, 60), Seed(5, 6, 60)),
    (Seed(4, 5, 120), Seed(5, 5, 120)),
    (Seed(4, 5, -60), Seed(3, 6, -60)),
    (Seed(4, 5, -120), Seed(3, 5, -120)),
    (Seed(5, 5, 0), Seed(5, 6, 0)),
    (Seed(5, 5, 180), Seed(5, 4, 180)),
    (Seed(5, 5, 60), Seed(6, 5, 60)),
    (Seed(5, 5, 120), Seed(6, 4, 120)),
    (Seed(5, 5, -60), Seed(4, 5, -60)),
    (Seed(5, 5, -120), Seed(4, 4, -120)),
])
def test_move_seeds_no_routing(from_details, to_details):
    move_seeds_test_impl(1, from_details, 0, to_details)
Пример #14
0
def test_can_not_hash_a_seed():
    h = Seed(sentinel.x, sentinel.y, sentinel.h)
    with pytest.raises(TypeError) as err:
        hash(h)
    assert str(err.value) == "unhashable type: 'Seed'"
Пример #15
0
 },
 {
     "collided": {
         0: (5, 5, 180, 10, 0),
         1: (6, 6, 0, 10, 0),
         2: (5, 5, 60, 10, 0),
         3: (6, 6, -120, 10, 0)
     },
     "exhausted": {
         4: (3, 3, 0, -1, 0)
     }
 },
 # Seeds same cell same direction
 {
     "seeds": {
         0: Seed(5, 5, 0),
         1: Seed(5, 5, 0)
     }
 },
 {
     "seeds": {
         0: Seed(5, 5, 0),
         1: Seed(5, 5, 0),
         2: Seed(5, 5, 0)
     }
 },
 {
     "seeds": {
         0: Seed(5, 5, 0),
         1: Seed(5, 5, 0),
         2: Seed(6, 6, 0),
Пример #16
0
def test_can_get_position_and_heading_from_a_seed():
    assert Seed(sentinel.x, sentinel.y,
                sentinel.h).xyh == (sentinel.x, sentinel.y, sentinel.h)
Пример #17
0
def test_str():
    assert str(Seed(1337, 2000, 123456)) == "Seed(1337, 2000, 123456)"
Пример #18
0
def test_repr():
    assert repr(Seed(1337, 2000, 123456)) == "Seed(1337, 2000, 123456)"
Пример #19
0
def test_can_read_seed_from_json():
    assert Seed.from_json([sentinel.type, sentinel.x, sentinel.y,
                           sentinel.h]) == Seed(sentinel.x, sentinel.y,
                                                sentinel.h)
Пример #20
0
def test_can_convert_seed_to_json():
    assert (Seed(sentinel.x, sentinel.y, sentinel.h).to_json() == [
        "Seed", sentinel.x, sentinel.y, sentinel.h
    ])
Пример #21
0
def test_seeds_equality(x1, y1, heading1, x2, y2, heading2, are_equal):
    h1 = Seed(x1, y1, heading1)
    h2 = Seed(x2, y2, heading2)
    assert (h1 == h2) == are_equal
    assert (h1 != h2) == (not are_equal)