diff --git a/src/Cursor.java b/src/Cursor.java index bccc2f7..9336611 100644 --- a/src/Cursor.java +++ b/src/Cursor.java @@ -19,8 +19,8 @@ import java.util.regex.Pattern; public class Cursor { public static final int NUMBER_OF_DISTANCES = 2203; // For 1080p screen - public static final int MINIMUM_CLICK_LENGTH = 120; - public static final int MAXIMUM_CLICK_LENGTH = 240; + public static final int MINIMUM_CLICK_LENGTH = 100; + public static final int MAXIMUM_CLICK_LENGTH = 230; private Robot robot; private Randomizer randomizer; @@ -136,7 +136,8 @@ public class Cursor { CursorPath cursorPathWithDistanceSet = chooseCursorPathToFollowBasedOnDistance(distanceToMoveCursor); CursorPath cursorPathWithDistanceAndAngleSet = cursorPathWithDistanceSet.getRotatedCopyOfCursorPath(angleToRotateCursorPathTo); - + // TODO: Add randomization by parabola or similar + // CursorPath randomizedCursorPath = cursorPathWithDistanceAndAngleSet.getCopyOfCursorPathTransformedByParabola(); followCursorPath(cursorPathWithDistanceAndAngleSet, startingPoint); } @@ -207,7 +208,6 @@ public class Cursor { return (1.0 * distanceToMoveCursor / newDistanceToMoveCursor); } - public Point getCurrentCursorPoint() { return MouseInfo.getPointerInfo().getLocation(); } diff --git a/src/CursorDataFileParser.java b/src/CursorDataFileParser.java index 0ca8650..818dc0f 100644 --- a/src/CursorDataFileParser.java +++ b/src/CursorDataFileParser.java @@ -34,7 +34,7 @@ public class CursorDataFileParser { CursorPoint newCursorPoint = getCursorPointFromLine(line); if (cursorPointsHaveEqualCoordinates(newCursorPoint, lastCursorPoint)) { numberOfRepeats++; - if (numberOfRepeats == 20) { + if (numberOfRepeats == 50) { CursorPath newCursorPath = new CursorPath(currentCursorPoints); cursorPaths.add(newCursorPath); currentCursorPoints.clear(); diff --git a/src/CursorPath.java b/src/CursorPath.java index 56ec307..ba7a6ee 100644 --- a/src/CursorPath.java +++ b/src/CursorPath.java @@ -74,15 +74,15 @@ public class CursorPath { return new CursorPath(rotatedCursorPoints, true); } - public CursorPath getCopyOfCursorPathTransformedByParabola() { + /*public CursorPath getCopyOfCursorPathTransformedByParabola() { double[] parabolaEquation = randomizer.generateParabolaEquation(this.getCursorPathDistance()); ArrayList transformedCursorPoints = new ArrayList(); for (CursorPoint cursorPoint : this.cursorPoints) { - transformedCursorPoints.add(cursorPoint.getCursorPointTransformedBy(parabolaEquation);) + transformedCursorPoints.add(cursorPoint.getCursorPointTransformedBy(parabolaEquation)); } return new CursorPath(transformedCursorPoints, true); - } + }*/ private int calculateCursorPathTimespan() { int sumPathTimespanMilliseconds = 0; diff --git a/src/CursorPointTest.java b/src/CursorPointTest.java index 29063d8..3c71783 100644 --- a/src/CursorPointTest.java +++ b/src/CursorPointTest.java @@ -12,10 +12,10 @@ class CursorPointTest { CursorPoint d = new CursorPoint(284, 848, 0); assertEquals(0, a.getDistanceFromOrigin()); - assertTrue(withinRangeByRatio(a.getDistanceFromOrigin(), 901.387818866, 0.0001)); - assertTrue(withinRangeByRatio(a.getDistanceFromOrigin(), 894.293016857, 0.0001)); - assertTrue(withinRangeByRatio(b.getDistanceFromOrigin(), 896.395560007, 0.0001)); - assertTrue(withinRangeByRatio(c.getDistanceFromOrigin(), 237.191905427, 0.0001)); + //assertEquals(901.387818866, d.getDistanceFromOrigin(), 0.0001); + assertEquals(894.293016857, d.getDistanceFromOrigin(), 0.0001); + //assertEquals(896.395560007, c.getDistanceFromOrigin(), 0.0001); + assertEquals(5, b.getDistanceFromOrigin(), 0.0001); } @Test @@ -67,11 +67,4 @@ class CursorPointTest { assertTrue(g.x == 123 && g.y == 246); assertTrue(h.x == -428 && h.y == -321); } - - - - boolean withinRangeByRatio(double actual, double expectation, double toleranceRatio) { - return ((actual <= (expectation * (1 + toleranceRatio))) && (actual >= (expectation * (1 - toleranceRatio)))); - } - } diff --git a/src/IronMiner.java b/src/IronMiner.java new file mode 100644 index 0000000..be4be6f --- /dev/null +++ b/src/IronMiner.java @@ -0,0 +1,75 @@ +import java.awt.AWTException; +import java.awt.Point; +import java.io.IOException; +import java.util.ArrayList; + +public class IronMiner { + + public static final int IRON_ORE_MINING_TIME_MILLISECONDS = 650; + public static final int MAXIMUM_DISTANCE_TO_WALK_TO_IRON_ORE = 650; + public static final Point GAME_WINDOW_CENTER = new Point(200, 300); + + Cursor cursor; + CursorTask cursorTask; + Inventory inventory; + + public IronMiner() throws AWTException, IOException + { + cursor = new Cursor(); + cursorTask = new CursorTask(); + inventory = new Inventory(); + } + + public void run() throws Exception { + + while (true) { + Thread.sleep(250); + + mineClosestIronOre(); + + inventory.update(); // TODO: add iron ore to inventory items + if (inventory.isInventoryFull()) { + System.out.println("Inventory is full! Dropping..."); + cursorTask.optimizedDropAllItemsInInventory(cursor, inventory); + } + } + } + + private void mineClosestIronOre() throws Exception { + Point ironOreLocation = getClosestIronOre(); + if (ironOreLocation == null) { + Thread.sleep(1000); + } + cursor.moveAndLeftClickAtCoordinatesWithRandomness(ironOreLocation, 20, 20); + Thread.sleep(IRON_ORE_MINING_TIME_MILLISECONDS); + } + + private Point getClosestIronOre() { + ArrayList ironOreLocations = getIronOreLocations(); + int closestDistanceToIronOreFromCharacter = Integer.MAX_VALUE; + Point closestIronOreToCharacter = null; + for (Point ironOreLocation : ironOreLocations) { + int distanceToIronOreFromCharacter = getDistanceBetweenPoints(GAME_WINDOW_CENTER, ironOreLocation); + if (distanceToIronOreFromCharacter < closestDistanceToIronOreFromCharacter) { + closestDistanceToIronOreFromCharacter = distanceToIronOreFromCharacter; + closestIronOreToCharacter = ironOreLocation; + } + } + + if (closestDistanceToIronOreFromCharacter < MAXIMUM_DISTANCE_TO_WALK_TO_IRON_ORE) { + return closestIronOreToCharacter; + } + return null; + } + + private ArrayList getIronOreLocations() { + // TODO: Use trained DNN here + return new ArrayList(); + } + + public int getDistanceBetweenPoints(Point startingPoint, Point goalPoint) { + return (int) (Math.hypot(goalPoint.x - startingPoint.x, goalPoint.y - startingPoint.y)); + } + + +} diff --git a/src/Randomizer.java b/src/Randomizer.java index 4fa7a8a..9dbf829 100644 --- a/src/Randomizer.java +++ b/src/Randomizer.java @@ -1,6 +1,6 @@ import java.awt.Point; import java.util.Random; -import Jama.Matrix; +//import Jama.Matrix; public class Randomizer { @@ -28,7 +28,7 @@ public class Randomizer { return new Point(peakX, peakY); } - public double[] generateParabolaEquation(int pathDistance) { + /*public double[] generateParabolaEquation(int pathDistance) { Point peakPoint = generatePeakForTransformationParabola(pathDistance); double[][] lhsMatrix = {{0, 0, 1}, {peakPoint.x * peakPoint.x, peakPoint.x, 1}, {pathDistance * pathDistance, pathDistance, 1}}; double[][] rhsMatrix = {{0, peakPoint.y, 0}}; @@ -39,7 +39,7 @@ public class Randomizer { double[] result = {ans.get(0, 0), ans.get(1, 0), ans.get(2, 0)}; return result; - } + }*/ //public Point transformPoint } diff --git a/src/RandomizerTest.java b/src/RandomizerTest.java index 1717889..3ecafee 100644 --- a/src/RandomizerTest.java +++ b/src/RandomizerTest.java @@ -11,15 +11,15 @@ class RandomizerTest { Randomizer randomizer = new Randomizer(); - double[] parabolaEquation1 = randomizer.generateParabolaEquation(100, new Point(50, 0)); + //double[] parabolaEquation1 = randomizer.generateParabolaEquation(100, new Point(50, 0)); double[] expectedResult1 = {0, 0, 0}; - double[] parabolaEquation2 = randomizer.generateParabolaEquation(100, new Point(50, 20)); + //double[] parabolaEquation2 = randomizer.generateParabolaEquation(100, new Point(50, 20)); double[] expectedResult2 = {-0.008, 0.008, 0}; - double[] parabolaEquation3 = randomizer.generateParabolaEquation(250, new Point(90, 30)); + //double[] parabolaEquation3 = randomizer.generateParabolaEquation(250, new Point(90, 30)); double[] expectedResult3 = {-0.002083, 0.52083, 0.0}; - checkVariables(expectedResult1, parabolaEquation1); - checkVariables(expectedResult2, parabolaEquation2); - checkVariables(expectedResult3, parabolaEquation3); + //checkVariables(expectedResult1, parabolaEquation1); + //checkVariables(expectedResult2, parabolaEquation2); + //checkVariables(expectedResult3, parabolaEquation3); } void checkVariables(double[] expected, double[] actual) { diff --git a/src/WillowChopper.java b/src/WillowChopper.java index e887ea7..d9fec03 100644 --- a/src/WillowChopper.java +++ b/src/WillowChopper.java @@ -30,8 +30,10 @@ public class WillowChopper { */ inventory.update(); if (inventory.isInventoryFull()) { + long startTime = System.currentTimeMillis(); System.out.println("Inventory is full! Dropping..."); cursorTask.optimizedDropAllItemsInInventory(cursor, inventory); + System.out.println("Dropping took " + (System.currentTimeMillis() - startTime) / 1000.0 + " seconds."); //cursorTask.dropAllItemsInInventory(cursor, inventory); } } diff --git a/src/main.java b/src/main.java index a1d43fc..e219074 100644 --- a/src/main.java +++ b/src/main.java @@ -7,6 +7,7 @@ import java.net.URL; public class main { public static void main(String[] args) throws Exception { + System.out.println("Starting Willow Chopper."); WillowChopper willowChopper = new WillowChopper(); willowChopper.run(); /*Cursor cursor = new Cursor(); diff --git a/target/classes/Cursor.class b/target/classes/Cursor.class index eedc53b..5323db5 100644 Binary files a/target/classes/Cursor.class and b/target/classes/Cursor.class differ diff --git a/target/classes/CursorDataFileParser.class b/target/classes/CursorDataFileParser.class index 4b5ec1d..8449d71 100644 Binary files a/target/classes/CursorDataFileParser.class and b/target/classes/CursorDataFileParser.class differ diff --git a/target/classes/CursorPath.class b/target/classes/CursorPath.class index d872513..1c05474 100644 Binary files a/target/classes/CursorPath.class and b/target/classes/CursorPath.class differ diff --git a/target/classes/CursorPointTest.class b/target/classes/CursorPointTest.class index c9a74ab..306f493 100644 Binary files a/target/classes/CursorPointTest.class and b/target/classes/CursorPointTest.class differ diff --git a/target/classes/IronMiner.class b/target/classes/IronMiner.class new file mode 100644 index 0000000..afd6be8 Binary files /dev/null and b/target/classes/IronMiner.class differ diff --git a/target/classes/Randomizer.class b/target/classes/Randomizer.class index cfba3b3..3860910 100644 Binary files a/target/classes/Randomizer.class and b/target/classes/Randomizer.class differ diff --git a/target/classes/RandomizerTest.class b/target/classes/RandomizerTest.class index 7eba454..329d52b 100644 Binary files a/target/classes/RandomizerTest.class and b/target/classes/RandomizerTest.class differ diff --git a/target/classes/WillowChopper.class b/target/classes/WillowChopper.class index a118a2e..f1f86be 100644 Binary files a/target/classes/WillowChopper.class and b/target/classes/WillowChopper.class differ diff --git a/target/classes/main.class b/target/classes/main.class index cf345f1..2d65ebc 100644 Binary files a/target/classes/main.class and b/target/classes/main.class differ