mirror of
https://github.com/davpapp/PowerMiner
synced 2024-12-21 23:48:49 -05:00
HashMap working but Integer causes faulty key comparison
This commit is contained in:
parent
6635ed33c1
commit
dce51e5538
BIN
bin/Mouse.class
BIN
bin/Mouse.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
bin/main.class
BIN
bin/main.class
Binary file not shown.
@ -8,35 +8,76 @@ import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class Mouse {
|
||||
|
||||
private ArrayList<MousePath> mousePaths;
|
||||
private HashMap<Integer[], ArrayList<MousePath>> gridMap;
|
||||
//private ArrayList<MousePath> mousePaths;
|
||||
PointerInfo pointer;
|
||||
|
||||
public Mouse(String path) {
|
||||
// TODO: Is there another way to get the pointer location??
|
||||
pointer = MouseInfo.getPointerInfo();
|
||||
mousePaths = new ArrayList<MousePath>();
|
||||
readFile(path);
|
||||
gridMap = new HashMap<Integer[], ArrayList<MousePath>>();
|
||||
ArrayList<MousePath> mousePaths = readFile(path);
|
||||
assignPathsToGrid(mousePaths);
|
||||
}
|
||||
|
||||
public void moveMouse(int xGoal, int yGoal) {
|
||||
public void moveMouse(int endingX, int endingY) {
|
||||
int[] mouseLoc = getMouseLocation();
|
||||
int deltaX = endingX - mouseLoc[0];
|
||||
int deltaY = endingY - mouseLoc[1];
|
||||
Integer[] gridKey = getGridMapKey(deltaX, deltaY);
|
||||
|
||||
// Fetch from map
|
||||
}
|
||||
|
||||
|
||||
public int[] getMouseLocation() {
|
||||
Point startingPoint = pointer.getLocation();
|
||||
int x = (int) startingPoint.getX();
|
||||
int y = (int) startingPoint.getY();
|
||||
|
||||
for (MousePath mousePath : mousePaths) {
|
||||
MousePoint pathStartingPoint = mousePath.getStartingPoint();
|
||||
if (pathStartingPoint.distance(startingPoint) < 20.0) {
|
||||
System.out.println("Found possible path!");
|
||||
mousePath.display();
|
||||
}
|
||||
}
|
||||
int loc[] = {x, y};
|
||||
return loc;
|
||||
}
|
||||
|
||||
public void readFile(String path) {
|
||||
|
||||
public Integer[] getGridMapKey(int deltaX, int deltaY) {
|
||||
Integer[] gridKey = {deltaX / 100, deltaY / 100};
|
||||
return gridKey;
|
||||
}
|
||||
|
||||
public void assignPathsToGrid(ArrayList<MousePath> mousePaths) {
|
||||
Integer[] key1 = getGridMapKey(0, 0);
|
||||
Integer[] key2 = getGridMapKey(0, 0);
|
||||
gridMap.put(key1, new ArrayList<MousePath>());
|
||||
if (gridMap.containsKey(key2)) {
|
||||
System.out.println("same key!");
|
||||
}
|
||||
if (gridMap.containsKey(key1)) {
|
||||
System.out.println("Same key2!");
|
||||
}
|
||||
/*for (MousePath mousePath : mousePaths) {
|
||||
int deltaX = mousePath.getDeltaX();
|
||||
int deltaY = mousePath.getDeltaY();
|
||||
Integer[] gridKey = getGridMapKey(deltaX, deltaY);
|
||||
|
||||
if (gridMap.containsKey(gridKey)) {
|
||||
System.out.println("Same category!");
|
||||
gridMap.get(gridKey).add(mousePath);
|
||||
}
|
||||
else {
|
||||
ArrayList<MousePath> newPath = new ArrayList<MousePath>();
|
||||
newPath.add(mousePath);
|
||||
gridMap.put(gridKey, newPath);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
public ArrayList<MousePath> readFile(String path) {
|
||||
ArrayList<MousePath> mousePaths = new ArrayList<MousePath>();
|
||||
try {
|
||||
File file = new File(path);
|
||||
FileReader fileReader = new FileReader(file);
|
||||
@ -81,6 +122,7 @@ public class Mouse {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return mousePaths;
|
||||
}
|
||||
|
||||
private boolean isLineValid(String line, Pattern linePattern) {
|
||||
@ -97,23 +139,19 @@ public class Mouse {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// ---------------------- Getters ----------------------------------------
|
||||
|
||||
|
||||
public int getNumberOfPaths() {
|
||||
return mousePaths.size();
|
||||
}
|
||||
|
||||
public ArrayList<MousePath> getMousePaths() {
|
||||
return mousePaths;
|
||||
}
|
||||
|
||||
public void displayPaths() {
|
||||
for (MousePath path : mousePaths) {
|
||||
path.display();
|
||||
System.out.println("----------------------------------------------------------");
|
||||
System.out.println("Displaying paths in HashMap...");
|
||||
for (HashMap.Entry<Integer[], ArrayList<MousePath>> entry : gridMap.entrySet()) {
|
||||
Integer[] gridKey = entry.getKey();
|
||||
System.out.println("Key is: (" + gridKey[0] + ", " + gridKey[1] + ")");
|
||||
|
||||
ArrayList<MousePath> mousePaths = entry.getValue();
|
||||
System.out.println("There are " + mousePaths.size() + " paths with these deltas.");
|
||||
for (MousePath path : mousePaths) {
|
||||
//path.display();
|
||||
System.out.println("----------------------------------------------------------");
|
||||
}
|
||||
System.out.println("Size of HashMap: " + gridMap.size());
|
||||
}
|
||||
System.out.println("There are " + mousePaths.size() + " paths.");
|
||||
}
|
||||
}
|
@ -36,11 +36,15 @@ public class MousePath {
|
||||
}
|
||||
numPoints = path.size();
|
||||
MousePoint startingPoint = path.get(0);
|
||||
MousePoint endingPoint = path.get(numPoints - 1);
|
||||
boundUp = maxY - startingPoint.getY();
|
||||
boundDown = startingPoint.getY() - minY;
|
||||
boundLeft = startingPoint.getX() - minX;
|
||||
boundRight = maxX - startingPoint.getX();
|
||||
|
||||
deltaX = endingPoint.getX() - startingPoint.getX();
|
||||
deltaY = endingPoint.getY() - startingPoint.getY();
|
||||
|
||||
timespan = path.get(numPoints - 1).getTime() - startingPoint.getTime();
|
||||
}
|
||||
|
||||
|
@ -4,13 +4,11 @@ public class main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
//Mouse mouse = new Mouse("/home/dpapp/GhostMouse/coordinates.txt");
|
||||
//URL url = main.class.getClassLoader().getResource("testfiles/mouse_path_test1.txt");
|
||||
//System.out.println(url.getPath());
|
||||
//getResource("testfiles/mouse_path_test1.txt");
|
||||
|
||||
System.out.println("Starting mouse script...");
|
||||
System.out.println("Fetching mouse paths from script...");
|
||||
Mouse mouse = new Mouse("/home/dpapp/GhostMouse/coordinates.txt");
|
||||
//mouse.displayPaths();
|
||||
mouse.moveMouse(743, 414);
|
||||
mouse.displayPaths();
|
||||
System.out.println("Finished...");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user