def main(fileName): pizza = Pizza(fileName) shape = pizzaShape(pizza) dimension_list = determineCutPoints((pizza.rows, pizza.cols), shape) slices = perform_actual_cutting(dimension_list) validSlices = [] for slice in slices: # print("Cut out this: ", pizza.cut(slice), "\n") # print("From this pizza: ") # slice.display(pizza) # print("\n") # print("valid Slice? ", is_validate_slice(pizza, slice)) if is_validate_slice(pizza, slice): validSlices.append(slice) input() print_file(validSlices) return str( len(validSlices) * shape[0] * shape[1] / (pizza.rows * pizza.cols) * 100) + " %"
print("***********\n") for slice in slicePath: print(" ".join([ str(slice.startRow), str(slice.startCol), str(slice.endRow), str(slice.endCol) ])) slice.display(localPizza) print("***********\n") self.allValidSlicePaths.append(localSlicePath) if __name__ == "__main__": pizza = Pizza("inputFiles/a_example.in") pizzaManager = PizzaManager(pizza) pizzaManager.getAllPossibleValidSlicePaths() print("len ", len(pizzaManager.allValidSlicePaths)) i = 1 for slicePath in pizzaManager.allValidSlicePaths: print("Current Slice Path: ", i) for slice in slicePath: print(" ".join([ str(slice.startRow), str(slice.startCol), str(slice.endRow), str(slice.endCol) ])) i += 1
from pizzaStructure import Pizza from sliceStructure import Slice def is_validate_slice(pizza, a_slice): number_of_tomato = 0 for i in range(a_slice.startRow, a_slice.endRow + 1): for j in range(a_slice.startCol, a_slice.endCol + 1): cell = pizza.pizzaArray[i][j] number_of_tomato += cell number_of_cells = get_slice_size(a_slice) number_of_mushroom = number_of_cells - number_of_tomato print(number_of_mushroom) return (number_of_tomato >= pizza.L) and (number_of_mushroom >= pizza.L) def get_slice_size(slice): return (slice.endRow - slice.startRow + 1) * (slice.endCol - slice.startCol + 1) if __name__ == '__main__': pizza = Pizza("inputFiles/a_example.in") slice = Slice(0, 0, 2, 2) slice.display(pizza) print("************") print(pizza.cut(slice)) print(is_validate_slice(pizza, slice))
def testCols(self): pizza = Pizza("inputFiles/a_example.in") self.assertTrue(pizza.cols >= 1 and pizza.cols <= 1000)
def testRows(self): pizza = Pizza("inputFiles/a_example.in") self.assertTrue(pizza.rows >= 1 and pizza.rows <= 1000)
def testPizzaArray(self): pizza = Pizza("inputFiles/a_example.in") self.assertEqual(pizza.pizzaArray.shape, (pizza.rows, pizza.cols))
def testH(self): pizza = Pizza("inputFiles/a_example.in") self.assertTrue(pizza.H >= 1 and pizza.H <= 1000)