From 9f23ffc75f5e4f1cf1a07be6ebb02deb70d4b9e4 Mon Sep 17 00:00:00 2001
From: cxn-wr7-u1 <enes.herguel@stud.hs-hannover.de>
Date: Thu, 22 Apr 2021 03:21:18 +0200
Subject: [PATCH] Maze-ready!

---
 .idea/misc.xml                        |   6 ++
 .idea/modules.xml                     |   8 ++
 .idea/paralleleprogrammierung.iml     |  12 +++
 .idea/uiDesigner.xml                  | 124 ++++++++++++++++++++++++++
 .idea/vcs.xml                         |   6 ++
 src/algorithm/Explorer.java           |  56 +++++++-----
 src/algorithm/ParallelPathfinder.java |  33 +++----
 src/algorithm/WorkingExplorers.java   |  23 ++---
 src/parallel/EagerWorkingThread.java  |  28 +++---
 src/parallel/MapLoader.java           |   2 +-
 src/parallel/SharedRessources.java    |  71 ++++++++-------
 src/window/Game.java                  |  16 +++-
 src/window/MainWindow.java            |   9 +-
 13 files changed, 284 insertions(+), 110 deletions(-)
 create mode 100644 .idea/misc.xml
 create mode 100644 .idea/modules.xml
 create mode 100644 .idea/paralleleprogrammierung.iml
 create mode 100644 .idea/uiDesigner.xml
 create mode 100644 .idea/vcs.xml

diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..91063aa
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_15" default="true" project-jdk-name="15" project-jdk-type="JavaSDK">
+    <output url="file://$PROJECT_DIR$/out" />
+  </component>
+</project>
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..484d391
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/paralleleprogrammierung.iml" filepath="$PROJECT_DIR$/.idea/paralleleprogrammierung.iml" />
+    </modules>
+  </component>
+</project>
\ No newline at end of file
diff --git a/.idea/paralleleprogrammierung.iml b/.idea/paralleleprogrammierung.iml
new file mode 100644
index 0000000..5ea232f
--- /dev/null
+++ b/.idea/paralleleprogrammierung.iml
@@ -0,0 +1,12 @@
+<?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$/Semester/src" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 0000000..e96534f
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="Palette2">
+    <group name="Swing">
+      <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
+      </item>
+      <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
+      </item>
+      <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
+      </item>
+      <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
+        <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
+      </item>
+      <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
+        <initial-values>
+          <property name="text" value="Button" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
+        <initial-values>
+          <property name="text" value="RadioButton" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
+        <initial-values>
+          <property name="text" value="CheckBox" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
+        <initial-values>
+          <property name="text" value="Label" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+          <preferred-size width="150" height="-1" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+          <preferred-size width="150" height="-1" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+          <preferred-size width="150" height="-1" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
+      </item>
+      <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
+          <preferred-size width="200" height="200" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
+          <preferred-size width="200" height="200" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
+      </item>
+      <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
+      </item>
+      <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
+      </item>
+      <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
+      </item>
+      <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
+          <preferred-size width="-1" height="20" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
+      </item>
+      <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
+      </item>
+    </group>
+  </component>
+</project>
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="" vcs="Git" />
+  </component>
+</project>
\ No newline at end of file
diff --git a/src/algorithm/Explorer.java b/src/algorithm/Explorer.java
index 720407b..eee1875 100644
--- a/src/algorithm/Explorer.java
+++ b/src/algorithm/Explorer.java
@@ -20,6 +20,11 @@ public class Explorer {
 
     private Direction direction;
 
+
+    public int getSteps() {
+        return steps;
+    }
+
     public Explorer(int x, int y, int steps, Direction direction) {
         this.x = x;
         this.y = y;
@@ -28,18 +33,21 @@ public class Explorer {
     }
 
     public void explore() {
-
+        int index = x + y * SharedRessources.getInstance().getWidth();
         int currentStepsOnField
                 =
-                (int) SharedRessources.getInstance().getVisitMatrix()[x + y * SharedRessources.getInstance().getWidth()]
+                (int) SharedRessources.getInstance().getVisitMatrix()[index]
                         .getZ();
 
-        if(currentStepsOnField < steps)
+        if (currentStepsOnField <= steps + SharedRessources.getInstance().getEpsilon()) {
             return;
+        }
+
+
 
 
         boolean wall =
-                SharedRessources.getInstance().getWallMatrix()[x + y * SharedRessources.getInstance().getWidth()];
+                SharedRessources.getInstance().getWallMatrix()[index];
         if (wall)
             return;
 
@@ -49,22 +57,22 @@ public class Explorer {
         switch (direction) {
 
             case North:
-                if (steps < currentStepsOnField) {
-                    SharedRessources
-                            .getInstance().getVisitMatrix()[x + y * SharedRessources.getInstance().getWidth()]
-                            = new Vec3(0, +1, steps);
-                }
+
+                SharedRessources
+                        .getInstance().getVisitMatrix()[index]
+                        = new Vec3(0, +1, steps);
+
                 recursiveNext
                         = new Explorer(x, y - 1, steps++, direction);
                 addLeftRight();
                 break;
 
             case East:
-                if (steps < currentStepsOnField) {
-                    SharedRessources
-                            .getInstance().getVisitMatrix()[x + y * SharedRessources.getInstance().getWidth()]
-                            = new Vec3(-1, 0, steps);
-                }
+
+                SharedRessources
+                        .getInstance().getVisitMatrix()[index]
+                        = new Vec3(-1, 0, steps);
+
                 recursiveNext
                         = new Explorer(x + 1, y, steps++, direction);
 
@@ -72,22 +80,22 @@ public class Explorer {
                 break;
 
             case South:
-                if (steps < currentStepsOnField) {
-                    SharedRessources
-                            .getInstance().getVisitMatrix()[x + y * SharedRessources.getInstance().getWidth()]
-                            = new Vec3(0, -1, steps);
-                }
+
+                SharedRessources
+                        .getInstance().getVisitMatrix()[index]
+                        = new Vec3(0, -1, steps);
+
                 recursiveNext
                         = new Explorer(x, y + 1, steps++, direction);
                 addLeftRight();
                 break;
 
             case West:
-                if (steps < currentStepsOnField) {
-                    SharedRessources
-                            .getInstance().getVisitMatrix()[x + y * SharedRessources.getInstance().getWidth()]
-                            = new Vec3(+1, 0, steps);
-                }
+
+                SharedRessources
+                        .getInstance().getVisitMatrix()[index]
+                        = new Vec3(+1, 0, steps);
+
                 recursiveNext
                         = new Explorer(x - 1, y, steps++, direction);
                 addUpDown();
diff --git a/src/algorithm/ParallelPathfinder.java b/src/algorithm/ParallelPathfinder.java
index d0b20c7..e98b076 100644
--- a/src/algorithm/ParallelPathfinder.java
+++ b/src/algorithm/ParallelPathfinder.java
@@ -18,7 +18,16 @@ public class ParallelPathfinder {
         SharedRessources
                 .getInstance().add(new Explorer(destX, destY + 1, 1, Explorer.Direction.South));
 
-        while (!SharedRessources.getInstance().done());
+
+        synchronized (SharedRessources.getInstance().getSignalingObject()) {
+            while (!SharedRessources.getInstance().done()) {
+                try {
+                    SharedRessources.getInstance().getSignalingObject().wait();
+                } catch (InterruptedException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
     }
 
     public ArrayList<Point> calculatePath(int startX, int startY, int destX, int destY) {
@@ -41,7 +50,7 @@ public class ParallelPathfinder {
             int dx = (int) currentDir.getX();
             int dy = (int) currentDir.getY();
 
-            if(dx == 0 && dy == 0)
+            if (dx == 0 && dy == 0)
                 return null;
 
             x += dx;
@@ -57,26 +66,10 @@ public class ParallelPathfinder {
             for (int i = 0; i < SharedRessources.getInstance().getWidth(); i++) {
                 boolean b =
                         SharedRessources.getInstance().getWallMatrix()[i + j * SharedRessources.getInstance().getWidth()];
-                if (b)
+                if (b) {
                     g.setColor(Color.blue);
-                else {
-                    Vec3 currentVec
-                            =
-                            SharedRessources.getInstance().getVisitMatrix()[i + j * SharedRessources.getInstance().getWidth()];
-                    if (currentVec.getX() == 0 && currentVec.getY() == 0)
-                        g.setColor(Color.black);
-                    else {
-                        int green = (int)currentVec.getZ();
-
-                        Color color
-                                = new Color(0, green, 0);
-
-                        g.setColor(color);
-
-                    }
+                    g.fillRect(i * 1, j * 1, 1, 1);
                 }
-
-                g.fillRect(i * 10, j * 10, 10, 10);
             }
         }
     }
diff --git a/src/algorithm/WorkingExplorers.java b/src/algorithm/WorkingExplorers.java
index 4307730..3c9d2eb 100644
--- a/src/algorithm/WorkingExplorers.java
+++ b/src/algorithm/WorkingExplorers.java
@@ -3,23 +3,21 @@ package algorithm;
 import parallel.EagerWorkingThread;
 import parallel.SharedRessources;
 
-import java.util.ArrayList;
-import java.util.PriorityQueue;
-import java.util.Queue;
-import java.util.Stack;
+import java.util.*;
+import java.util.concurrent.ConcurrentLinkedDeque;
+import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.LinkedBlockingQueue;
 
 public class WorkingExplorers extends EagerWorkingThread {
 
     public WorkingExplorers() {
         super();
-        this.setAllowRunning(true);
-
+        this.startListen();
         System.out.println("[*] Thread initialized @" + this.getName());
 
     }
 
-    private Stack<Explorer> currentWaitingExplorers = new Stack<>();
+    private ConcurrentLinkedQueue<Explorer> currentWaitingExplorers = new ConcurrentLinkedQueue<Explorer>();
 
     @Override
     public void onBegin() {
@@ -28,15 +26,20 @@ public class WorkingExplorers extends EagerWorkingThread {
     @Override
     public void onTrigger() {
         if (!currentWaitingExplorers.isEmpty())
-            currentWaitingExplorers.pop().explore();
+            currentWaitingExplorers
+                    .poll()
+                    .explore();
     }
 
     @Override
     public void onEnd() {
+        synchronized (SharedRessources.getInstance().getSignalingObject()){
+            SharedRessources.getInstance().getSignalingObject().notifyAll();
+        }
     }
 
-    public void add(Explorer explorer) throws InterruptedException {
-        this.currentWaitingExplorers.push(explorer);
+    public void add(Explorer explorer) {
+        this.currentWaitingExplorers.offer(explorer);
         this.trigger();
     }
 
diff --git a/src/parallel/EagerWorkingThread.java b/src/parallel/EagerWorkingThread.java
index 6965128..cb1bba6 100644
--- a/src/parallel/EagerWorkingThread.java
+++ b/src/parallel/EagerWorkingThread.java
@@ -1,27 +1,22 @@
 package parallel;
 
 public abstract class EagerWorkingThread extends Thread {
-    private static volatile boolean RUN_THREADS = true;
-
-    public static void stopAllThreads() {
-        RUN_THREADS = false;
-    }
 
     private volatile int triggerCount;
     private volatile boolean isTriggered;
-    private volatile boolean allowRunning;
+    private volatile boolean listen;
 
-    public void setAllowRunning(boolean allowRunning) {
-        this.allowRunning = allowRunning;
+    public void startListen() {
+        listen = true;
     }
 
-    public boolean isAllowedRunning() {
-        return allowRunning;
+    public void stopListen() {
+        listen = false;
     }
 
     @Override
     public void run() {
-        while (RUN_THREADS && allowRunning) {
+        while (listen) {
             synchronized (this) {
                 while (!isTriggered) {
                     try {
@@ -31,28 +26,27 @@ public abstract class EagerWorkingThread extends Thread {
                     }
                 }
             }
-
             onBegin();
             for (int i = 0; i < triggerCount; i++)
                 onTrigger();
             onEnd();
 
-
             triggerCount = 0;
             isTriggered = false;
 
-
         }
     }
 
-    public synchronized boolean trigger() {
+    public boolean trigger() {
         triggerCount++;
         isTriggered = true;
-        this.notifyAll();
+        synchronized (this) {
+            this.notify();
+        }
         return true;
     }
 
-    public synchronized boolean isReady(){
+    public boolean isReady() {
         return this.triggerCount == 0;
     }
 
diff --git a/src/parallel/MapLoader.java b/src/parallel/MapLoader.java
index 52d1aee..d0721ba 100644
--- a/src/parallel/MapLoader.java
+++ b/src/parallel/MapLoader.java
@@ -33,7 +33,7 @@ public class MapLoader {
         SharedRessources.getInstance().setWallMatrix(new boolean[width * height]);
 
         for (int i = 0; i < SharedRessources.getInstance().getVisitMatrix().length; i++)
-            SharedRessources.getInstance().getVisitMatrix()[i] = new Vec3(0, 0, 10000);
+            SharedRessources.getInstance().getVisitMatrix()[i] = new Vec3(0, 0, Integer.MAX_VALUE);
 
 
         // https://stackoverflow.com/a/9470843/14727115
diff --git a/src/parallel/SharedRessources.java b/src/parallel/SharedRessources.java
index a2616e8..40c8f56 100644
--- a/src/parallel/SharedRessources.java
+++ b/src/parallel/SharedRessources.java
@@ -4,6 +4,8 @@ import algorithm.Explorer;
 import algorithm.WorkingExplorers;
 import structs.Vec3;
 
+import java.util.Stack;
+
 public class SharedRessources {
     private static int USING_CORES;
 
@@ -12,33 +14,63 @@ public class SharedRessources {
      * @param cores
      */
     public static void setMaximumCores(int cores) {
+        if (cores >= Runtime.getRuntime().availableProcessors())
+            cores = Runtime.getRuntime().availableProcessors();
         USING_CORES = cores;
     }
 
     private static SharedRessources sharedRessources;
 
-    public static synchronized SharedRessources getInstance() {
+    public static SharedRessources getInstance() {
         if (sharedRessources == null)
             sharedRessources = new SharedRessources(USING_CORES);
         return sharedRessources;
     }
 
+    private SharedRessources(int cores) {
+        maxCores = cores;
+        System.out.println("[*] Using " + maxCores + " cores.");
+
+        signalingObject = new Object();
+
+        workingThreads = new WorkingExplorers[maxCores];
+        for (int i = 0; i < maxCores; i++) {
+            workingThreads[i] = new WorkingExplorers();
+            workingThreads[i].start();
+        }
+
+        currentCore = 0;
+    }
+
+    private int width;
+    private int height;
+
+    private boolean[] wallMatrix;
+    private Vec3[] visitMatrix;
+
     private int maxCores;
     private int currentCore;
 
     private WorkingExplorers[] workingThreads;
 
-    public void start() {
-        for (int i = 0; i < maxCores; i++)
-            this.workingThreads[i].start();
+    private Object signalingObject;
+
+    private int epsilon;
+
+    public void setEpsilon(int epsilon) {
+        this.epsilon = epsilon;
+    }
+
+    public int getEpsilon() {
+        return epsilon;
+    }
+
+    public Object getSignalingObject() {
+        return signalingObject;
     }
 
     public void add(Explorer explorer) {
-        try {
-            this.workingThreads[(currentCore++) % maxCores].add(explorer);
-        } catch (InterruptedException e) {
-            e.printStackTrace();
-        }
+        this.workingThreads[(currentCore++) % maxCores].add(explorer);
     }
 
     public boolean done() {
@@ -48,27 +80,6 @@ public class SharedRessources {
         return true;
     }
 
-    private SharedRessources(int cores) {
-        if (cores >= Runtime.getRuntime().availableProcessors())
-            maxCores = Runtime.getRuntime().availableProcessors();
-        else maxCores = cores;
-
-        System.out.println("[*] Using " + maxCores + " cores.");
-
-        workingThreads = new WorkingExplorers[maxCores];
-        for (int i = 0; i < maxCores; i++)
-            workingThreads[i] = new WorkingExplorers();
-
-        start();
-        currentCore = 0;
-    }
-
-    private int width;
-    private int height;
-
-    private boolean[] wallMatrix;
-    private Vec3[] visitMatrix;
-
     public Vec3[] getVisitMatrix() {
         return visitMatrix;
     }
diff --git a/src/window/Game.java b/src/window/Game.java
index 297efd2..6a328a3 100644
--- a/src/window/Game.java
+++ b/src/window/Game.java
@@ -12,13 +12,13 @@ public abstract class Game extends JFrame {
 
     private boolean running;
 
-    protected boolean[] keys;
+    private boolean[] pressedKeyMap;
 
     public Game(String title, int w, int h) {
         super(title);
         this.setSize(w, h);
 
-        keys = new boolean[1024];
+        pressedKeyMap = new boolean[1024];
 
         this.windowThread = new Thread(() -> {
             loadGame();
@@ -46,14 +46,14 @@ public abstract class Game extends JFrame {
             public void keyPressed(KeyEvent e) {
                 super.keyPressed(e);
 
-                keys[e.getKeyCode()] = true;
+                pressedKeyMap[e.getKeyCode()] = true;
             }
 
             @Override
             public void keyReleased(KeyEvent e) {
                 super.keyReleased(e);
 
-                keys[e.getKeyCode()] = false;
+                pressedKeyMap[e.getKeyCode()] = false;
             }
         });
 
@@ -62,6 +62,14 @@ public abstract class Game extends JFrame {
 
     }
 
+    public boolean isKeyDown(int key) {
+        return pressedKeyMap[key];
+    }
+
+    public boolean isKeyUp(int key) {
+        return !isKeyDown(key);
+    }
+
     public final void run() {
         this.setVisible(true);
         this.running = true;
diff --git a/src/window/MainWindow.java b/src/window/MainWindow.java
index 5ff08b5..eb666b0 100644
--- a/src/window/MainWindow.java
+++ b/src/window/MainWindow.java
@@ -23,8 +23,9 @@ public class MainWindow extends Game {
     @Override
     public void loadGame() {
         SharedRessources.setMaximumCores(Integer.MAX_VALUE);
+        SharedRessources.getInstance().setEpsilon(0);
         try {
-            MapLoader.getDefault().load(ImageIO.read(new File("c:/users/enesh/desktop/tests/debug.png")));
+            MapLoader.getDefault().load(ImageIO.read(new File("c:/users/enesh/desktop/tests/maze2.png")));
         } catch (IOException e) {
             e.printStackTrace();
         }
@@ -36,8 +37,8 @@ public class MainWindow extends Game {
     @Override
     public void updateGame() {
 
-        if (keys[KeyEvent.VK_ENTER])
-            pts = parallelPathfinder.calculatePath(10, 114, 33, 30);
+        if (isKeyDown(KeyEvent.VK_ENTER))
+            pts = parallelPathfinder.calculatePath(8, 5, 1590, 800);
 
     }
 
@@ -55,7 +56,7 @@ public class MainWindow extends Game {
 
         g.setColor(Color.red);
         for (var pt : pts) {
-            g.fillRect(pt.x * 10, pt.y * 10, 10, 10);
+            g.fillRect(pt.x * 1, pt.y * 1, 1, 1);
         }
     }
 
-- 
GitLab