Beispiel #1
0
def test_PLACE_SHIPS_looks_reasonable_VERTICAL(n=1000):
    w = 10
    h = 10
    env = BattleshipEnv(width=w, height=h)

    for _ in range(n):
        env.reset(vert_probability=1)
        seen_in_previous_rows = []
        for col in range(w):
            newly_seen = []
            for row in range(h):
                element = env.state[row][col]
                if element != 0:
                    if element in seen_in_previous_rows:
                        print(
                            "\nBAD!!! Saw a %s in multiple cols. Showing the offending board:" % element)
                        show_ships(env.state)
                        raise Exception(
                            "BAD!!! Saw a %s in multiple col." % element)
                    else:
                        newly_seen.append(element)
            seen_in_previous_rows += newly_seen

    print("\nVERTICAL")
    show_ships(env.state)
Beispiel #2
0
def test_PLACE_SHIPS_looks_reasonable_TOP_RIGHT(n=1000):
    w = 10
    h = 10
    cumulative_ships = np.zeros((h, w), dtype=np.int32)
    env = BattleshipEnv(width=w, height=h)

    for _ in range(n):
        env.reset(favor_top=100, favor_right=100)
        cumulative_ships += env.state > 0

    print("\nTOP RIGHT")
    show_ships(cumulative_ships)
Beispiel #3
0
def test_PLACE_SHIPS_looks_reasonable_NO_FAVORS(n=1000):
    w = 10
    h = 10
    cumulative_ships = np.zeros((h, w), dtype=np.int32)
    env = BattleshipEnv(width=w, height=h)

    for _ in range(n):
        env.reset()
        cumulative_ships += env.state > 0

    print("\nNO FAVORS")
    show_ships(cumulative_ships)
Beispiel #4
0
def test_PLACE_SHIPS_looks_reasonable_TOP_and_BOTTOM_with_STEEP_GRADIENT(n=1000):
    w = 10
    h = 10
    cumulative_ships = np.zeros((h, w), dtype=np.int32)
    env = BattleshipEnv(width=w, height=h)

    for _ in range(n):
        env.reset(favor_top=1, favor_bottom=1, gradient_coef=lambda x: x**10)
        cumulative_ships += env.state > 0

    print("\nTOP and BOTTOM with STEEP GRADIENT")
    show_ships(cumulative_ships)
Beispiel #5
0
def test_PLACE_SHIPS_looks_reasonable_LEFT_with_UNSTEEP_GRADIENT(n=1000):
    w = 10
    h = 10
    cumulative_ships = np.zeros((h, w), dtype=np.int32)
    env = BattleshipEnv(width=w, height=h)

    for _ in range(n):
        env.reset(favor_left=10, gradient_coef=lambda x: x**(1/2))
        cumulative_ships += env.state > 0

    print("\nLEFT with UNSTEEP GRADIENT")
    show_ships(cumulative_ships)
Beispiel #6
0
def test_PLACE_SHIPS_looks_reasonable_CENTER_with_STEEP_GRADIENT(n=1000):
    """
    Note: To get a really defined center, the gradient coeff needs to be something that grows slowly like lambda x: x**(1/10)
    """
    w = 10
    h = 10
    cumulative_ships = np.zeros((h, w), dtype=np.int32)
    env = BattleshipEnv(width=w, height=h)

    for _ in range(n):
        env.reset(favor_top=-100000, favor_right=-100000, favor_left=-
                  100000, favor_bottom=-100000, gradient_coef=lambda x: x**(1/1000))
        cumulative_ships += env.state > 0

    print("\nCENTER with STEEP GRADIENT")
    show_ships(cumulative_ships)