mirror of
https://github.com/davpapp/PowerMiner
synced 2024-08-13 17:03:53 -04:00
Layed the framework for an IronMiner bot
This commit is contained in:
parent
19aa168a3c
commit
bd3d07d7ac
@ -19,8 +19,8 @@ import java.util.regex.Pattern;
|
|||||||
public class Cursor {
|
public class Cursor {
|
||||||
|
|
||||||
public static final int NUMBER_OF_DISTANCES = 2203; // For 1080p screen
|
public static final int NUMBER_OF_DISTANCES = 2203; // For 1080p screen
|
||||||
public static final int MINIMUM_CLICK_LENGTH = 120;
|
public static final int MINIMUM_CLICK_LENGTH = 100;
|
||||||
public static final int MAXIMUM_CLICK_LENGTH = 240;
|
public static final int MAXIMUM_CLICK_LENGTH = 230;
|
||||||
|
|
||||||
private Robot robot;
|
private Robot robot;
|
||||||
private Randomizer randomizer;
|
private Randomizer randomizer;
|
||||||
@ -136,7 +136,8 @@ public class Cursor {
|
|||||||
|
|
||||||
CursorPath cursorPathWithDistanceSet = chooseCursorPathToFollowBasedOnDistance(distanceToMoveCursor);
|
CursorPath cursorPathWithDistanceSet = chooseCursorPathToFollowBasedOnDistance(distanceToMoveCursor);
|
||||||
CursorPath cursorPathWithDistanceAndAngleSet = cursorPathWithDistanceSet.getRotatedCopyOfCursorPath(angleToRotateCursorPathTo);
|
CursorPath cursorPathWithDistanceAndAngleSet = cursorPathWithDistanceSet.getRotatedCopyOfCursorPath(angleToRotateCursorPathTo);
|
||||||
|
// TODO: Add randomization by parabola or similar
|
||||||
|
// CursorPath randomizedCursorPath = cursorPathWithDistanceAndAngleSet.getCopyOfCursorPathTransformedByParabola();
|
||||||
followCursorPath(cursorPathWithDistanceAndAngleSet, startingPoint);
|
followCursorPath(cursorPathWithDistanceAndAngleSet, startingPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,7 +208,6 @@ public class Cursor {
|
|||||||
return (1.0 * distanceToMoveCursor / newDistanceToMoveCursor);
|
return (1.0 * distanceToMoveCursor / newDistanceToMoveCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Point getCurrentCursorPoint() {
|
public Point getCurrentCursorPoint() {
|
||||||
return MouseInfo.getPointerInfo().getLocation();
|
return MouseInfo.getPointerInfo().getLocation();
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ public class CursorDataFileParser {
|
|||||||
CursorPoint newCursorPoint = getCursorPointFromLine(line);
|
CursorPoint newCursorPoint = getCursorPointFromLine(line);
|
||||||
if (cursorPointsHaveEqualCoordinates(newCursorPoint, lastCursorPoint)) {
|
if (cursorPointsHaveEqualCoordinates(newCursorPoint, lastCursorPoint)) {
|
||||||
numberOfRepeats++;
|
numberOfRepeats++;
|
||||||
if (numberOfRepeats == 20) {
|
if (numberOfRepeats == 50) {
|
||||||
CursorPath newCursorPath = new CursorPath(currentCursorPoints);
|
CursorPath newCursorPath = new CursorPath(currentCursorPoints);
|
||||||
cursorPaths.add(newCursorPath);
|
cursorPaths.add(newCursorPath);
|
||||||
currentCursorPoints.clear();
|
currentCursorPoints.clear();
|
||||||
|
@ -74,15 +74,15 @@ public class CursorPath {
|
|||||||
return new CursorPath(rotatedCursorPoints, true);
|
return new CursorPath(rotatedCursorPoints, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CursorPath getCopyOfCursorPathTransformedByParabola() {
|
/*public CursorPath getCopyOfCursorPathTransformedByParabola() {
|
||||||
double[] parabolaEquation = randomizer.generateParabolaEquation(this.getCursorPathDistance());
|
double[] parabolaEquation = randomizer.generateParabolaEquation(this.getCursorPathDistance());
|
||||||
ArrayList<CursorPoint> transformedCursorPoints = new ArrayList<CursorPoint>();
|
ArrayList<CursorPoint> transformedCursorPoints = new ArrayList<CursorPoint>();
|
||||||
for (CursorPoint cursorPoint : this.cursorPoints) {
|
for (CursorPoint cursorPoint : this.cursorPoints) {
|
||||||
transformedCursorPoints.add(cursorPoint.getCursorPointTransformedBy(parabolaEquation);)
|
transformedCursorPoints.add(cursorPoint.getCursorPointTransformedBy(parabolaEquation));
|
||||||
}
|
}
|
||||||
return new CursorPath(transformedCursorPoints, true);
|
return new CursorPath(transformedCursorPoints, true);
|
||||||
|
|
||||||
}
|
}*/
|
||||||
|
|
||||||
private int calculateCursorPathTimespan() {
|
private int calculateCursorPathTimespan() {
|
||||||
int sumPathTimespanMilliseconds = 0;
|
int sumPathTimespanMilliseconds = 0;
|
||||||
|
@ -12,10 +12,10 @@ class CursorPointTest {
|
|||||||
CursorPoint d = new CursorPoint(284, 848, 0);
|
CursorPoint d = new CursorPoint(284, 848, 0);
|
||||||
|
|
||||||
assertEquals(0, a.getDistanceFromOrigin());
|
assertEquals(0, a.getDistanceFromOrigin());
|
||||||
assertTrue(withinRangeByRatio(a.getDistanceFromOrigin(), 901.387818866, 0.0001));
|
//assertEquals(901.387818866, d.getDistanceFromOrigin(), 0.0001);
|
||||||
assertTrue(withinRangeByRatio(a.getDistanceFromOrigin(), 894.293016857, 0.0001));
|
assertEquals(894.293016857, d.getDistanceFromOrigin(), 0.0001);
|
||||||
assertTrue(withinRangeByRatio(b.getDistanceFromOrigin(), 896.395560007, 0.0001));
|
//assertEquals(896.395560007, c.getDistanceFromOrigin(), 0.0001);
|
||||||
assertTrue(withinRangeByRatio(c.getDistanceFromOrigin(), 237.191905427, 0.0001));
|
assertEquals(5, b.getDistanceFromOrigin(), 0.0001);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -67,11 +67,4 @@ class CursorPointTest {
|
|||||||
assertTrue(g.x == 123 && g.y == 246);
|
assertTrue(g.x == 123 && g.y == 246);
|
||||||
assertTrue(h.x == -428 && h.y == -321);
|
assertTrue(h.x == -428 && h.y == -321);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
boolean withinRangeByRatio(double actual, double expectation, double toleranceRatio) {
|
|
||||||
return ((actual <= (expectation * (1 + toleranceRatio))) && (actual >= (expectation * (1 - toleranceRatio))));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
75
src/IronMiner.java
Normal file
75
src/IronMiner.java
Normal file
@ -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<Point> 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<Point> getIronOreLocations() {
|
||||||
|
// TODO: Use trained DNN here
|
||||||
|
return new ArrayList<Point>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDistanceBetweenPoints(Point startingPoint, Point goalPoint) {
|
||||||
|
return (int) (Math.hypot(goalPoint.x - startingPoint.x, goalPoint.y - startingPoint.y));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import Jama.Matrix;
|
//import Jama.Matrix;
|
||||||
|
|
||||||
public class Randomizer {
|
public class Randomizer {
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ public class Randomizer {
|
|||||||
return new Point(peakX, peakY);
|
return new Point(peakX, peakY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double[] generateParabolaEquation(int pathDistance) {
|
/*public double[] generateParabolaEquation(int pathDistance) {
|
||||||
Point peakPoint = generatePeakForTransformationParabola(pathDistance);
|
Point peakPoint = generatePeakForTransformationParabola(pathDistance);
|
||||||
double[][] lhsMatrix = {{0, 0, 1}, {peakPoint.x * peakPoint.x, peakPoint.x, 1}, {pathDistance * pathDistance, pathDistance, 1}};
|
double[][] lhsMatrix = {{0, 0, 1}, {peakPoint.x * peakPoint.x, peakPoint.x, 1}, {pathDistance * pathDistance, pathDistance, 1}};
|
||||||
double[][] rhsMatrix = {{0, peakPoint.y, 0}};
|
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)};
|
double[] result = {ans.get(0, 0), ans.get(1, 0), ans.get(2, 0)};
|
||||||
return result;
|
return result;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
//public Point transformPoint
|
//public Point transformPoint
|
||||||
}
|
}
|
||||||
|
@ -11,15 +11,15 @@ class RandomizerTest {
|
|||||||
Randomizer randomizer = new Randomizer();
|
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[] 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[] 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};
|
double[] expectedResult3 = {-0.002083, 0.52083, 0.0};
|
||||||
checkVariables(expectedResult1, parabolaEquation1);
|
//checkVariables(expectedResult1, parabolaEquation1);
|
||||||
checkVariables(expectedResult2, parabolaEquation2);
|
//checkVariables(expectedResult2, parabolaEquation2);
|
||||||
checkVariables(expectedResult3, parabolaEquation3);
|
//checkVariables(expectedResult3, parabolaEquation3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkVariables(double[] expected, double[] actual) {
|
void checkVariables(double[] expected, double[] actual) {
|
||||||
|
@ -30,8 +30,10 @@ public class WillowChopper {
|
|||||||
*/
|
*/
|
||||||
inventory.update();
|
inventory.update();
|
||||||
if (inventory.isInventoryFull()) {
|
if (inventory.isInventoryFull()) {
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
System.out.println("Inventory is full! Dropping...");
|
System.out.println("Inventory is full! Dropping...");
|
||||||
cursorTask.optimizedDropAllItemsInInventory(cursor, inventory);
|
cursorTask.optimizedDropAllItemsInInventory(cursor, inventory);
|
||||||
|
System.out.println("Dropping took " + (System.currentTimeMillis() - startTime) / 1000.0 + " seconds.");
|
||||||
//cursorTask.dropAllItemsInInventory(cursor, inventory);
|
//cursorTask.dropAllItemsInInventory(cursor, inventory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import java.net.URL;
|
|||||||
public class main {
|
public class main {
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
System.out.println("Starting Willow Chopper.");
|
||||||
WillowChopper willowChopper = new WillowChopper();
|
WillowChopper willowChopper = new WillowChopper();
|
||||||
willowChopper.run();
|
willowChopper.run();
|
||||||
/*Cursor cursor = new Cursor();
|
/*Cursor cursor = new Cursor();
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
target/classes/IronMiner.class
Normal file
BIN
target/classes/IronMiner.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user