@@ -19,9 +19,10 @@ private DFSMethods() {
1919 * remove this slice from startPositions and add all it's cells to pizza.
2020 * @param pizza given pizza
2121 * @param startPositions given slices in the pizza
22+ * @param output
2223 * @return available steps
2324 */
24- public static Map <Slice , List <Step >> getAvailableSteps (Pizza pizza , List <Slice > startPositions ) {
25+ public static Map <Slice , List <Step >> getAvailableSteps (Pizza pizza , List <Slice > startPositions , List < Slice > output ) {
2526 Map <Slice , List <Step >> groupedSteps = new HashMap <>();
2627 Iterator iter = startPositions .iterator ();
2728 while (iter .hasNext ()) {
@@ -43,7 +44,8 @@ public static Map<Slice, List<Step>> getAvailableSteps(Pizza pizza, List<Slice>
4344 if (startPosition .isValid (pizza )) {
4445 // if slice is valid and have'nt any steps -> cut it from
4546 // startPositions
46- groupedSteps .put (startPosition , steps );
47+ output .add (startPosition );
48+ iter .remove ();
4749 } else {
4850 // if slice isn't valid and have'nt any steps -> return all
4951 // it cells to pizza
@@ -66,20 +68,32 @@ public static Map<Slice, List<Step>> getAvailableSteps(Pizza pizza, List<Slice>
6668 *
6769 * @param pizza given pizza
6870 * @param step step to perform
69- * @return formed slice that includes an original slice and delta from a step
71+ * @param startPositions
72+ *@param output @return formed slice that includes an original slice and delta from a step
7073 */
71- public static Slice performStep (Pizza pizza , Step step ) {
74+ public static void performStep (Pizza pizza , Step step , List < Slice > startPositions , List < Slice > output ) {
7275 //1. Pick ups a steps list with minimal total cells number
7376 LOGGER .info ("STEP TO PERFORM " + step );
7477 //2. Cut all the step delta cells from pizza
7578 LOGGER .info ("pizza before step: " + pizza
7679 + "\n delta to remove from the pizza: " + step .delta );
7780 pizza .getCells ().removeAll (step .delta .cells );
81+
82+ //3. remove previous version start position from startPositions
83+ startPositions .remove (step .startPosition );
84+
85+ List <Cell > returnedList = step .startPosition .cells ;
86+ returnedList .addAll (step .delta .cells );
87+ Slice finalSlice = new Slice (returnedList );
88+
7889 LOGGER .info ("PIZZA AFTER STEP:" + pizza );
7990 //3. Add the step cells to an output slice
80- Slice slice = new Slice (step .delta .cells );
81- slice .cells .addAll (step .startPosition .cells );
82- return slice ;
91+
92+ if (finalSlice .cells .size () == pizza .getSliceInstruction ().getMaxNumberOfCellsPerSlice ()){
93+ output .add (finalSlice );
94+ } else {
95+ startPositions .add (finalSlice );
96+ }
8397 }
8498
8599 /**
0 commit comments