Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
zsofa committed Feb 19, 2022
0 parents commit 8d77d75
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Project exclude paths
/out/
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Evosoft.iml
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 added akademia_feladat_online_interjura.pdf
Binary file not shown.
7 changes: 7 additions & 0 deletions src/Main.java
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) {
}
}
13 changes: 13 additions & 0 deletions src/interfaces/Activity.java
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();

}
54 changes: 54 additions & 0 deletions src/services/Process.java
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);
}
}

0 comments on commit 8d77d75

Please sign in to comment.