def test_large_board(self): player = Board(10, 10) cpu = Board(10, 10) self.assertIsInstance(player, Board) self.assertIsInstance(cpu, Board) self.assertEqual( player.render(), " 1 2 3 4 5 6 7 8 9 10 \nA . . . . . . . . . . \nB . . . . . . . . . . \nC . . . . . . . . . . \nD . . . . . . . . . . \nE . . . . . . . . . . \nF . . . . . . . . . . \nG . . . . . . . . . . \nH . . . . . . . . . . \nI . . . . . . . . . . \nJ . . . . . . . . . . " )
def test_render_boad(self): board = Board(4, 4) cruiser = Ship("Cruiser", 3) board.place(cruiser, ["A1", "A2", "A3"]) self.assertEqual( board.render(), " 1 2 3 4 \nA . . . . \nB . . . . \nC . . . . \nD . . . . ") self.assertEqual( board.render(True), " 1 2 3 4 \nA S S S . \nB . . . . \nC . . . . \nD . . . . ") board.cells['A1'].fire_upon() self.assertEqual( board.render(True), " 1 2 3 4 \nA H S S . \nB . . . . \nC . . . . \nD . . . . ") board.cells['A2'].fire_upon() board.cells['A3'].fire_upon() self.assertEqual( board.render(True), " 1 2 3 4 \nA X X X . \nB . . . . \nC . . . . \nD . . . . ")
print("Please enter a number greater than 4") else: break player = Board(int(width), int(height)) cpu = Board(int(width), int(height)) os.system('clear') pc_submarine = Ship("Submarine", 2) pc_cruiser = Ship("Cruiser", 3) npc_submarine = Ship("Submarine", 2) npc_cruiser = Ship("Cruiser", 3) while True: os.system('clear') print(player.render(True)) sub_coords = input("Pick two empty coordinates for your submarine, space separated ('A1 A2') \n") if player.isValidPlacement(pc_submarine, sub_coords.split(' ')) == False: os.system('clear') print(player.render(True)) print("Please pick empty coordinates that are consecutive and not diagonal") else: player.place(pc_submarine, sub_coords.split(' ')) break while True: os.system('clear') print(player.render(True)) cruiser_coords = input("Pick three empty coordinates, space separated ('A1 A2 A3') \n") if player.isValidPlacement(pc_cruiser, cruiser_coords.split(' ')) == False: os.system('clear')