commit 6ea01289e9d44716c5b4c1cb2163601a5e6c1023 Author: davpapp Date: Tue Jan 23 21:50:06 2018 -0500 Beginnings of mouse path recording working diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..6ee61f2 --- /dev/null +++ b/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..cbeb660 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + RunescapeAI + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..7e5c907 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=9 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=9 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=9 diff --git a/bin/Mouse.class b/bin/Mouse.class new file mode 100644 index 0000000..2470a2e Binary files /dev/null and b/bin/Mouse.class differ diff --git a/bin/MousePath.class b/bin/MousePath.class new file mode 100644 index 0000000..1668378 Binary files /dev/null and b/bin/MousePath.class differ diff --git a/bin/Point.class b/bin/Point.class new file mode 100644 index 0000000..b32fe88 Binary files /dev/null and b/bin/Point.class differ diff --git a/bin/main.class b/bin/main.class new file mode 100644 index 0000000..bd8e31b Binary files /dev/null and b/bin/main.class differ diff --git a/src/Mouse.java b/src/Mouse.java new file mode 100644 index 0000000..c0d6b99 --- /dev/null +++ b/src/Mouse.java @@ -0,0 +1,89 @@ + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class Mouse { + + private ArrayList mousePaths; + + public Mouse(String path) { + mousePaths = new ArrayList(); + readFile(path); + } + + public void readFile(String path) { + try { + File file = new File(path); + FileReader fileReader = new FileReader(file); + BufferedReader bufferedReader = new BufferedReader(fileReader); + Pattern linePattern = Pattern.compile("x:[0-9]* y:[0-9]* [0-9]*"); + + String line; + Point lastPoint = new Point(0, 0, 0); + int numberOfRepeats = 0; + ArrayList currentPath = new ArrayList(); + currentPath.add(lastPoint); + + //int count = 0; + while ((line = bufferedReader.readLine()) != null) { + if (!isLineValid(line, linePattern)) { + System.out.println(line + " does not match regex -- SKIPPING"); + continue; + } + //count += 1; + //if (count > 1000) break; + Point point = getPointFromLine(line); + + if (point.getX() == lastPoint.getX() && point.getY() == lastPoint.getY()) { + numberOfRepeats += 1; + //System.out.println("Mouse at same point..."); + if (numberOfRepeats == 20) { + //System.out.println("Creating new path!"); + //System.out.println("Current path length:" + currentPath.size()); + MousePath newPath = new MousePath(currentPath); + mousePaths.add(newPath); + currentPath.clear(); + } + } + else { + numberOfRepeats = 0; + currentPath.add(point); + } + lastPoint = point; + } + + fileReader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private boolean isLineValid(String line, Pattern linePattern) { + Matcher matcher = linePattern.matcher(line); + if (matcher.find()) { + return true; + } + return false; + } + + private Point getPointFromLine(String line) { + String[] parts = line.split(Pattern.quote(":")); + /*System.out.println(line); + System.out.println(parts[0]); + System.out.println(parts[1]); + System.out.println(parts[2]);*/ + return new Point(0, 0, 0); + } + + public void displayPaths() { + for (MousePath path : mousePaths) { + path.display(); + System.out.println("----------------------------------------------------------"); + } + } +} \ No newline at end of file diff --git a/src/MousePath.java b/src/MousePath.java new file mode 100644 index 0000000..3cbfe8a --- /dev/null +++ b/src/MousePath.java @@ -0,0 +1,36 @@ +import java.util.ArrayList; + +public class MousePath { + + private ArrayList path; + private int numPoints; + private Point startingPoint; + private Point endingPoint; + + public MousePath(ArrayList _path) + { + path = new ArrayList(_path.size()); + for (Point point : _path) { + Point pointCopy = new Point(point.getX(), point.getY(), point.getTime()); + path.add(pointCopy); + } + numPoints = path.size(); + System.out.println("Created copy with size: " + path.size()); + //startingPoint = path.get(0); + //endingPoint = path.get(numPoints - 1); + } + + public ArrayList getPath() { + return path; + } + + public int getNumPoints() { + return numPoints; + } + + public void display() { + for (Point p : path) { + System.out.println("(" + p.getX() + ", " + p.getY() + "), " + p.getTime()); + } + } +} \ No newline at end of file diff --git a/src/Point.java b/src/Point.java new file mode 100644 index 0000000..b6280a9 --- /dev/null +++ b/src/Point.java @@ -0,0 +1,28 @@ +public class Point { + + private int x; + private int y; + private int time; + + public Point(int _x, int _y, int _time) + { + x = _x; + y = _y; + time = _time; + } + + public int getX() + { + return x; + } + + public int getY() + { + return y; + } + + public int getTime() + { + return time; + } +} \ No newline at end of file diff --git a/src/main.java b/src/main.java new file mode 100644 index 0000000..77c092e --- /dev/null +++ b/src/main.java @@ -0,0 +1,9 @@ + +public class main { + + public static void main(String[] args) { + // TODO Auto-generated method stub + Mouse mouseReader = new Mouse("/home/dpapp/GhostMouse/coordinates.txt"); + mouseReader.displayPaths(); + } +}