1
0
mirror of https://github.com/davpapp/PowerMiner synced 2024-12-21 23:48:49 -05:00

Beginnings of mouse path recording working

This commit is contained in:
davpapp 2018-01-23 21:50:06 -05:00
commit 6ea01289e9
11 changed files with 200 additions and 0 deletions

10
.classpath Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-9">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

17
.project Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>RunescapeAI</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -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

BIN
bin/Mouse.class Normal file

Binary file not shown.

BIN
bin/MousePath.class Normal file

Binary file not shown.

BIN
bin/Point.class Normal file

Binary file not shown.

BIN
bin/main.class Normal file

Binary file not shown.

89
src/Mouse.java Normal file
View File

@ -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<MousePath> mousePaths;
public Mouse(String path) {
mousePaths = new ArrayList<MousePath>();
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<Point> currentPath = new ArrayList<Point>();
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("----------------------------------------------------------");
}
}
}

36
src/MousePath.java Normal file
View File

@ -0,0 +1,36 @@
import java.util.ArrayList;
public class MousePath {
private ArrayList<Point> path;
private int numPoints;
private Point startingPoint;
private Point endingPoint;
public MousePath(ArrayList<Point> _path)
{
path = new ArrayList<Point>(_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<Point> getPath() {
return path;
}
public int getNumPoints() {
return numPoints;
}
public void display() {
for (Point p : path) {
System.out.println("(" + p.getX() + ", " + p.getY() + "), " + p.getTime());
}
}
}

28
src/Point.java Normal file
View File

@ -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;
}
}

9
src/main.java Normal file
View File

@ -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();
}
}