Skip to content

Commit 3a9684d

Browse files
committed
Merge remote-tracking branch 'remotes/origin/DFSMethod_getAllAvailableSteps' into DFSmethods
2 parents 2793b04 + 1cd3766 commit 3a9684d

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

src/main/java/com/google/hashcode/entity/Slice.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ public String toString() {
6161
return cells.toString();
6262
}
6363

64+
65+
/**
66+
* check if slice valid for current pizza.
67+
* @param pizza
68+
* @return
69+
*/
6470
public boolean isValid(Pizza pizza) {
6571
//TODO check rectangularity
6672
int mushroomsNumber = this.cells.stream()

src/main/java/com/google/hashcode/entity/Step.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.google.hashcode.entity;
22

3+
import java.util.List;
4+
35
/**
46
* Step as an entity is a slice tha can be added to a particular slice inside a particular pizza, considering
57
* pizza's slice instructions
@@ -25,4 +27,13 @@ public String toString() {
2527
'}';
2628
}
2729

30+
public static boolean isValid(Pizza pizza, Slice startSlice, Slice checkedSlice){
31+
if( pizza.containsCells(checkedSlice) &&
32+
startSlice.cells.size() + checkedSlice.cells.size() <= pizza.getSliceInstruction().getMaxNumberOfCellsPerSlice()){
33+
return true;
34+
}
35+
36+
return false;
37+
}
38+
2839
}

src/main/java/com/google/hashcode/utils/DFSMethods.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,26 @@ private DFSMethods() {
2020
* For each slice find all available steps. We DON'T change the pizza on this stage
2121
*
2222
* @param pizza given pizza
23-
* @param output given slices in the pizza
23+
* @param startPos given slices in the pizza
2424
* @return available steps
2525
*/
26-
public static Map<Slice, List<Step>> getAvailableSteps(Pizza pizza, List<Slice> output) {
26+
public static Map<Slice, List<Step>> getAvailableSteps(Pizza pizza, List<Slice> startPos) {
2727
Map<Slice, List<Step>> groupedSteps = new HashMap<>();
28-
for (Slice slice : output) {
28+
for (Slice slice : startPos) {
2929
List<Step> steps = new ArrayList<>();
3030
Slice stepLeftDelta = slice.generateStepDeltaLeft();
3131
Slice stepRightDelta = slice.generateStepDeltaRight();
3232
Slice stepAboveDelta = slice.generateStepDeltaAbove();
3333
Slice stepBelowDelta = slice.generateStepDeltaBelow();
34-
if (pizza.containsCells(stepLeftDelta)) steps.add(new Step(slice, stepLeftDelta));
35-
if (pizza.containsCells(stepRightDelta)) steps.add(new Step(slice, stepRightDelta));
36-
if (pizza.containsCells(stepAboveDelta)) steps.add(new Step(slice, stepAboveDelta));
37-
if (pizza.containsCells(stepBelowDelta)) steps.add(new Step(slice, stepBelowDelta));
34+
if (Step.isValid(pizza, slice, stepLeftDelta)) steps.add(new Step(slice, stepLeftDelta));
35+
if (Step.isValid(pizza, slice, stepRightDelta)) steps.add(new Step(slice, stepRightDelta));
36+
if (Step.isValid(pizza, slice, stepAboveDelta)) steps.add(new Step(slice, stepAboveDelta));
37+
if (Step.isValid(pizza, slice, stepBelowDelta)) steps.add(new Step(slice, stepBelowDelta));
3838
groupedSteps.put(slice, steps);
3939
}
4040
LOGGER.info("available steps for" +
4141
"\npizza: " + pizza
42-
+ "\nslices: " + output
42+
+ "\nslices: " + startPos
4343
+ "\nsteps: " + groupedSteps);
4444
return groupedSteps;
4545
}

0 commit comments

Comments
 (0)