Пример #1
0
def test_trapseed_does_not_become_venus_after_10_moves_on_top_of_only_hive():
    turn_num = 12345

    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=((Hive(9, 5), ), ),
                     flowers=((), ),
                     turn_num=turn_num,
                     game_length=sentinel.game_length)

    game.boards[0].inflight[sentinel.seed_1] = TrapSeed(
        9, 8, 0, mock_game_params.trap_seed_lifespan)

    for _ in range(DEFAULT_GAME_PARAMETERS.trap_seed_lifespan + 1):
        game.turn([None])

    assert {
        vid: volant
        for (vid, volant) in game.boards[0].inflight.items()
        if not isinstance(volant, Bee)
    } == {
        sentinel.seed_1: TrapSeed(9, 5, 0, -1)
    }
    assert game.boards[0].flowers == ()
    assert game.boards[0].hives == (Hive(9, 5), )
Пример #2
0
def test_can_set_position():
    trapSeed = TrapSeed(sentinel.x, sentinel.y, sentinel.h, sentinel.lifespan)
    assert trapSeed.set_position(sentinel.newx, sentinel.newy) == TrapSeed(
        sentinel.newx, sentinel.newy, sentinel.h, sentinel.lifespan)

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

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

    trapSeed = TrapSeed(column, 5, heading, 10)
    assert trapSeed.advance() == TrapSeed(column + expected_dx,
                                          5 + expected_dy, heading, 9)

    # Original instance is not actually changed
    assert trapSeed == TrapSeed(column, 5, heading, 10)
Пример #4
0
def test_trapseed_becomes_venus_after_10_moves_on_top_of_a_hive():
    turn_num = 12345

    game = GameState(game_params=DEFAULT_GAME_PARAMETERS,
                     game_id=sentinel.game_id,
                     boards=1,
                     board_width=10,
                     board_height=10,
                     hives=((
                         Hive(9, 5),
                         Hive(5, 5),
                     ), ),
                     flowers=((), ),
                     turn_num=turn_num,
                     game_length=sentinel.game_length)

    game.boards[0].inflight[sentinel.seed_1] = TrapSeed(
        9, 8, 0, mock_game_params.trap_seed_lifespan)

    for _ in range(DEFAULT_GAME_PARAMETERS.trap_seed_lifespan + 1):
        game.turn([None])

    assert not [(_, volant) for (_, volant) in game.boards[0].inflight.items()
                if isinstance(volant, TrapSeed)]
    assert game.boards[0].flowers == ((VenusBeeTrap(
        9,
        5,
        DEFAULT_GAME_PARAMETERS,
        expires=turn_num + DEFAULT_GAME_PARAMETERS.trap_seed_lifespan +
        DEFAULT_GAME_PARAMETERS.flower_lifespan)), )
    assert game.boards[0].hives == (Hive(5, 5), )
Пример #5
0
def test_apply_venus_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),
                               Flower(9, 9, DEFAULT_GAME_PARAMETERS,
                                      sentinel.potency, sentinel.visits)), ),
                     turn_num=12345,
                     game_length=sentinel.game_length)

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

    assert game.boards[0].inflight == {}
    assert sorted(map(str, game.boards[0].flowers)) == sorted(
        map(str, (VenusBeeTrap(
            0,
            0,
            DEFAULT_GAME_PARAMETERS,
            1,
            0,
            expires=12345 + DEFAULT_GAME_PARAMETERS.flower_lifespan),
                  Flower(9, 9, DEFAULT_GAME_PARAMETERS, sentinel.potency,
                         sentinel.visits))))
    assert game.boards[0].hives == (Hive(9, 9), )
Пример #6
0
def test_apply_venus_command_over_existing_single_hive():
    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] = TrapSeed(
        9, 9, 0, DEFAULT_GAME_PARAMETERS.trap_seed_lifespan)
    game.apply_commands([dict(entity=sentinel.seed_1, command="flower")])

    assert game.boards[0].inflight == {
        sentinel.seed_1:
        TrapSeed(9, 9, 0, DEFAULT_GAME_PARAMETERS.trap_seed_lifespan)
    }
    assert game.boards[0].flowers == (Flower(0, 0, DEFAULT_GAME_PARAMETERS), )
    assert game.boards[0].hives == (Hive(9, 9), )
Пример #7
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)
Пример #8
0
def test_apply_venus_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] = TrapSeed(
        4, 5, 0, DEFAULT_GAME_PARAMETERS.trap_seed_lifespan)
    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),
                                      VenusBeeTrap(4,
                                                   5,
                                                   DEFAULT_GAME_PARAMETERS,
                                                   expires=12645))
    assert game.boards[0].hives == (Hive(9, 9), )
Пример #9
0
def test_can_get_position_and_heading_from_a_TrapSeed():
    assert TrapSeed(sentinel.x, sentinel.y, sentinel.h,
                    sentinel.lifespan).xyh == (sentinel.x, sentinel.y,
                                               sentinel.h)
Пример #10
0
def test_str():
    assert str(
        TrapSeed(1337, 2000, 123456, mock_game_params.trap_seed_lifespan)
    ) == "TrapSeed(1337, 2000, 123456, {0})".format(
        mock_game_params.trap_seed_lifespan)
Пример #11
0
def test_can_read_TrapSeed_from_json():
    assert TrapSeed.from_json([
        sentinel.type, sentinel.x, sentinel.y, sentinel.h, mock_game_params
    ]) == TrapSeed(sentinel.x, sentinel.y, sentinel.h, mock_game_params)
Пример #12
0
def test_can_convert_TrapSeed_to_json():
    assert (TrapSeed(sentinel.x, sentinel.y, sentinel.h,
                     mock_game_params.trap_seed_lifespan).to_json() == [
                         "TrapSeed", sentinel.x, sentinel.y, sentinel.h,
                         mock_game_params.trap_seed_lifespan
                     ])
Пример #13
0
def test_TrapSeeds_equality(x1, y1, heading1, x2, y2, heading2, are_equal):
    h1 = TrapSeed(x1, y1, heading1, mock_game_params)
    h2 = TrapSeed(x2, y2, heading2, mock_game_params)
    assert (h1 == h2) == are_equal
    assert (h1 != h2) == (not are_equal)
Пример #14
0
def test_can_not_hash_a_trap_TrapSeed():
    h = TrapSeed(sentinel.x, sentinel.y, sentinel.h, mock_game_params)
    with pytest.raises(TypeError) as err:
        hash(h)
    assert str(err.value) == "unhashable type: 'TrapSeed'"
Пример #15
0
def test_can_reverse_a_TrapSeed_along_a_heading_and_loses_lifespan():
    trapSeed = TrapSeed(5, 5, 0, 10)
    assert trapSeed.advance(reverse=True) == TrapSeed(5, 4, 180, 9)

    # Original instance is not actually changed
    assert trapSeed == TrapSeed(5, 5, 0, 10)
Пример #16
0
 {
     "seeds": {
         0: Seed(5, 5, 0),
         1: Seed(5, 5, -120)
     }
 },
 {
     "seeds": {
         0: Seed(5, 5, 0),
         1: Seed(5, 5, -60)
     }
 },
 # TrapSeed/Seeds same cell same direction
 {
     "seeds": {
         0: TrapSeed(5, 5, 0, 5),
         1: Seed(5, 5, 0)
     }
 },
 {
     "seeds": {
         0: TrapSeed(5, 5, 0, 5),
         1: Seed(5, 5, 0),
         2: Seed(5, 5, 0)
     }
 },
 {
     "seeds": {
         0: TrapSeed(5, 5, 0, 5),
         1: Seed(5, 5, 0),
         2: Seed(6, 6, 0),