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)
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)
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)
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)
def set_layout(b: Battleship, layout): for x, y, size, vertical in layout: b.put_ship(x, y, size, vertical)