-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8d77d75
Showing
10 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Project exclude paths | ||
/out/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
</component> | ||
</module> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import interfaces.Activity; | ||
import services.Process; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package interfaces; | ||
|
||
public interface Activity { | ||
|
||
//void turnLeft(); | ||
|
||
void turnRight(); | ||
|
||
void cleanTheSpot(); | ||
|
||
boolean move(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package services; | ||
|
||
import interfaces.Activity; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class Process { | ||
|
||
private Activity activity; | ||
private Set<int[]> visited = new HashSet<>(); | ||
|
||
public void moveBack() { | ||
activity.turnRight(); | ||
activity.turnRight(); | ||
activity.move(); | ||
activity.turnRight(); | ||
activity.turnRight(); | ||
} | ||
|
||
public void backtracking(int x, int y, int direction) { | ||
visited.add(new int[]{x, y}); | ||
activity.cleanTheSpot(); | ||
|
||
int newX = x; | ||
int newY = y; | ||
|
||
|
||
for (int i = 0; i < 4; i++) { | ||
int newDirection = (direction + i) % 4; | ||
if (newDirection == 0) { | ||
newX -= 1; | ||
} else if (newDirection == 1){ | ||
newY += 1; | ||
} else if (newDirection == 2) { | ||
newX += 1; | ||
} else if (newDirection == 3) { | ||
newY -= 1; | ||
} | ||
|
||
if (!visited.contains(new int[]{newX, newY}) && activity.move()) { | ||
backtracking(newX,newY,newDirection); | ||
moveBack(); | ||
} | ||
activity.turnRight(); | ||
} | ||
} | ||
|
||
|
||
public void cleanTheRoom(Activity activity) { | ||
this.activity = activity; | ||
backtracking(0,0,0); | ||
} | ||
} |