def testGetPlaneCells(self): p = Plane((2, 0), 'left') goodCells = [(2, 0), (0, 1), (1, 1), (2, 1), (3, 1), (4, 1), (2, 2), (1, 3), (2, 3), (3, 3)] pCells = p.getPlaneCells() self.assertEqual(len(pCells), 10) for c in goodCells: if c not in pCells: assert False
def addPlayerPlane(self, cabinPos, orientation): """ Method used to add a human player's plane to his board. :param cabinPos: tuple with 2 int values - the coordinates of the plane cabin in the matrix :param orientation: str - up/down/left/right: the plane orientation """ plane = Plane(cabinPos, orientation) PlaneValidator.validate(plane, self.__playerBoard) planeCells = plane.getPlaneCells() for cell in planeCells: self.__playerBoard[cell[0]][cell[1]] = '#' self.__playerPlanes.append(plane)
def addComputerPlanes(self): """ Method that adds 2 random and valid planes to the computer's board. """ addedPlanes = 0 while addedPlanes < 2: try: cabPos = (random.randint(0, 7), random.randint(0, 7)) orientation = random.choice(["up", "down", "left", "right"]) plane = Plane(cabPos, orientation) PlaneValidator.validate(plane, self.__computerBoard) planeCells = plane.getPlaneCells() for cell in planeCells: self.__computerBoard[cell[0]][cell[1]] = '#' self.__computerPlanes.append(plane) addedPlanes += 1 except PlaneError: pass