Beispiel #1
0
    async def player_1():
        b = Battleship()
        await b.connect(nick="foo")
        check_states_empty(b)

        set_layout(b, get_basic_layout_1())
        b._salt = "invalid_salt"
        await b.start()

        check_states_empty(b)
        await shoot_layout(b, get_basic_layout_1())
        check_abort(b)
Beispiel #2
0
    async def player_2():
        b = Battleship()
        await b.connect(nick="bar")
        check_states_empty(b)

        set_layout(b, get_basic_layout_1())
        await asyncio.sleep(0.1)
        b._ship_layout = get_basic_layout_2()
        b._salt = "invalid_salt"
        await b.join("foo")

        check_states_empty(b)
        for i in range(17):
            await b.round(9, 9)
        check_abort(b)

        b.restart()
        check_states_empty(b)
        set_layout(b, get_basic_layout_2())
        b._ship_layout = get_basic_layout_1()
        b._salt = "invalid_salt"
        await b.auto()

        await shoot_layout(b, get_basic_layout_2())
        check_abort(b)
Beispiel #3
0
    async def player_1():
        b = Battleship()
        await b.connect(nick="foo")
        check_states_empty(b)

        set_layout(b, get_basic_layout_1())
        await b.start()
Beispiel #4
0
    async def waiter():
        b = Battleship()

        await b.connect(nick="infiniteLister")
        set_layout(b, get_basic_layout_1())

        lst = await b.list_games()
        assert False, f"listed {lst}, should not list anything and wait forever"
Beispiel #5
0
    async def player_2():
        b = Battleship()
        await b.connect(nick="bar")
        check_states_empty(b)

        set_layout(b, get_basic_layout_1())

        await asyncio.sleep(0.1)
        await b.start()
Beispiel #6
0
    async def waiter():
        b = Battleship()

        await b.connect(nick="infiniteLister")
        set_layout(b, get_basic_layout_1())

        for i in range(1, 11):
            print("listing games")
            lst = await b.list_games()
            assert len(lst) == i, f"expected lenght {i} got {lst}"
Beispiel #7
0
    async def join_active_games():
        for i in range(10):
            b2 = Battleship()
            await b2.connect(nick=f"joiner{i}")

            set_layout(b2, get_basic_layout_1())
            await b2.join(f"host{i}")
            check_states_empty(b2)
            print(f"game {i} joined")
            await asyncio.sleep(0.1)
Beispiel #8
0
    async def player_2():
        b = Battleship()
        await b.connect(nick="bar")
        check_states_empty(b)

        set_layout(b, get_basic_layout_1())
        await b.auto()

        check_states_empty(b)
        await shoot_layout(b, get_basic_layout_1())
        check_draw(b)

        b.restart()
        check_states_empty(b)
        set_layout(b, get_basic_layout_2())
        await b.start()

        await shoot_layout(b, get_basic_layout_2())
        check_draw(b)
Beispiel #9
0
    async def add_additional_active_games():
        for i in range(10):
            b = Battleship()
            await b.connect(nick=f"additional{i}")

            set_layout(b, get_basic_layout_1())
            await b.start()
            print(f"additional game {i} started")
            check_states_empty(b)
            await asyncio.sleep(0.1)
Beispiel #10
0
    async def waiter():
        await asyncio.sleep(0.1)
        b = Battleship()

        await b.connect(nick="infiniteLister")
        set_layout(b, get_basic_layout_1())

        # await TestList_ActiveGames_TwoPlayers.sem.acquire()
        lst = await b.list_games()
        assert False, f"listed {lst}, should not list anything and wait forever"
Beispiel #11
0
    async def player_2():
        b = Battleship()
        await b.connect(nick="bar")
        check_states_empty(b)

        set_layout(b, get_basic_layout_1())
        await b.auto()

        check_states_empty(b)
        for _ in range(17):
            await b.round(9, 9)
        check_lost(b)

        b.restart()
        check_states_empty(b)
        set_layout(b, get_basic_layout_2())
        await b.start()

        await shoot_layout(b, get_basic_layout_2())
        check_win(b)
Beispiel #12
0
    async def player_1():
        b = Battleship()
        await b.connect(nick="foo")
        check_states_empty(b)

        lst = await b.list_games()
        assert len(lst) == 1
        assert lst[0] == "bar"

        set_layout(b, get_basic_layout_1())
        await b.join("bar")
Beispiel #13
0
    async def player_1():
        b = Battleship()

        await b.connect(nick="alice")

        b.put_ship(0, 0, 5, True)
        b.put_ship(1, 0, 4, True)
        b.put_ship(2, 0, 3, True)
        b.put_ship(3, 0, 3, True)
        b.put_ship(4, 0, 2, True)

        await b.start()
        check_states_empty(b)
Beispiel #14
0
    async def player_4():
        b = Battleship()
        await b.connect(nick="baaz")
        check_states_empty(b)

        set_layout(b, get_basic_layout_1())
        await asyncio.sleep(0.3)

        lst = await b.list_games()
        assert len(lst) == 1
        assert lst[0] == "baz"
        await b.join("baz")
Beispiel #15
0
    async def player_2():
        b = Battleship()
        await b.connect(nick="bar")
        check_states_empty(b)

        set_layout(b, get_basic_layout_1())
        await b.join("foo")

        check_states_empty(b)
        await shoot_layout(b, get_basic_layout_1())

        check_draw(b)
Beispiel #16
0
    async def player_2():
        b = Battleship()

        await b.connect(nick="rabbit")

        b.put_ship(0, 0, 5, True)
        b.put_ship(1, 0, 4, True)
        b.put_ship(2, 0, 3, True)
        b.put_ship(3, 0, 3, True)
        b.put_ship(4, 0, 2, True)

        # await b.join( "alice" )

        check_states_empty(b)
Beispiel #17
0
    async def player_1():
        b = Battleship()

        b.put_ship(0, 0, 5, True)
        b.put_ship(1, 0, 4, True)
        b.put_ship(2, 0, 3, True)
        b.put_ship(3, 0, 3, True)
        b.put_ship(4, 0, 2, True)

        await b.connect(nick="alice")

        await b.start()
        check_states_empty(b)

        while not b.finished():
            await b.round(0, 0)

        check_lost(b)
Beispiel #18
0
    async def player_2():
        b = Battleship()
        await b.connect(nick="bar")
        check_states_empty(b)

        set_layout(b, get_basic_layout_1())
        await asyncio.sleep(0.1)
        await b.join("foo")

        check_states_empty(b)
        for i in range(17):
            await b.round(9, 9)
        check_abort(b)
Beispiel #19
0
    async def player_1():
        b = Battleship()
        await b.connect(nick="foo")
        check_states_empty(b)

        set_layout(b, get_basic_layout_1())
        await b.auto()

        check_states_empty(b)
        for _ in range(17):
            await b.round(9, 9)

        check_lost(b)
Beispiel #20
0
    async def player_1():
        b = Battleship()
        await b.connect(nick="foo")
        check_states_empty(b)

        set_layout(b, get_basic_layout_1())
        await b.auto()

        check_states_empty(b)
        await shoot_layout(b, get_basic_layout_1())
        check_win(b)

        b.restart()
        check_states_empty(b)
        await check_list(b, "bar")
        set_layout(b, get_basic_layout_2())
        await asyncio.sleep(0.1)
        await b.join("bar")

        for _ in range(17):
            await b.round(9, 9)
        check_lost(b)
Beispiel #21
0
    async def player_2():
        b = Battleship()

        b.put_ship(0, 0, 5, True)
        b.put_ship(1, 0, 4, True)
        b.put_ship(2, 0, 3, True)
        b.put_ship(3, 0, 3, True)
        b.put_ship(4, 0, 2, True)

        await b.connect(nick="rabbit")
        await b.join("alice")
        check_states_empty(b)

        while not b.finished():
            await shoot_layout(b, [
                (0, 0, 5, True),
                (1, 0, 4, True),
                (2, 0, 3, True),
                (3, 0, 3, True),
                (4, 0, 2, True),
            ])

        check_win(b)
Beispiel #22
0
    async def add_active_games():
        ships = []
        for i in range(10):
            b = Battleship()
            ships.append(b)
            await b.connect(nick=f"host{i}")

            set_layout(b, get_basic_layout_1())
            await b.start()
            print(f"game {i} started")
            check_states_empty(b)
            await asyncio.sleep(0.1)
            # TestList_ActiveGames_TwoPlayers.queue.add(1)

        for s in ships:
            await shoot_layout(s, get_basic_layout_1())
            check_draw(s)
            await asyncio.sleep(0.1)
Beispiel #23
0
    async def join_active_games():
        ships = []
        for i in range(10):
            b2 = Battleship()
            ships.append(b2)
            await b2.connect(nick=f"joiner{i}")

            set_layout(b2, get_basic_layout_1())
            await b2.join(f"host{i}")
            check_states_empty(b2)
            print(f"game {i} joined")
            await asyncio.sleep(0.1)
            # await TestList_ActiveGames_TwoPlayers.queue.get()
            # sem.release()

        for s in ships:
            await shoot_layout(s, get_basic_layout_1())
            check_draw(s)
            await asyncio.sleep(0.1)

        # await asyncio.sleep(1)
        raise TimeoutError  #test ended
Beispiel #24
0
    async def player_1():
        b = Battleship()
        await b.connect(nick="foo")
        check_states_empty(b)

        set_layout(b, get_basic_layout_1())
        b._salt = "invalid_salt2"
        await b.start()

        check_states_empty(b)
        await shoot_layout(b, get_basic_layout_1())
        check_abort(b)

        b.restart()
        check_states_empty(b)
        await check_list(b, "bar")
        set_layout(b, get_basic_layout_2())
        await asyncio.sleep(0.1)
        b._server_salt = "invalid_hash"
        await b.auto()

        for _ in range(17):
            await b.round(9, 9)
        check_abort(b)
Beispiel #25
0
def check_abort(b: Battleship):
    assert b.finished()
    assert not b.won()
    assert not b.draw()
    assert b.aborted()
Beispiel #26
0
def set_layout(b: Battleship, layout):
    for x, y, size, vertical in layout:
        b.put_ship(x, y, size, vertical)