Small refinements
This commit is contained in:
parent
381ff01b53
commit
864b2a089a
File diff suppressed because it is too large
Load Diff
|
@ -35,4 +35,12 @@ public class CameraCalibrator {
|
||||||
robot.keyRelease(KeyEvent.VK_LEFT);
|
robot.keyRelease(KeyEvent.VK_LEFT);
|
||||||
Thread.sleep(Randomizer.nextGaussianWithinRange(80, 118));
|
Thread.sleep(Randomizer.nextGaussianWithinRange(80, 118));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void randomlyShiftView() throws InterruptedException {
|
||||||
|
int keyPressLength = Randomizer.nextGaussianWithinRange(50, 310);
|
||||||
|
robot.keyPress(KeyEvent.VK_LEFT);
|
||||||
|
Thread.sleep(keyPressLength);
|
||||||
|
robot.keyRelease(KeyEvent.VK_LEFT);
|
||||||
|
Thread.sleep(Randomizer.nextGaussianWithinRange(80, 118));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,17 +2,22 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
public class HumanBehavior {
|
public class HumanBehavior {
|
||||||
|
|
||||||
private int minimumTimeTillXPCheck = 35;
|
private int minimumTimeTillXPCheck = 25;
|
||||||
private int maximumTimeTillXPCheck = 75;
|
private int maximumTimeTillXPCheck = 73;
|
||||||
|
private int minimumTimeTillCameraRotation = 32;
|
||||||
|
private int maximumTimeTillCameraRotation = 61;
|
||||||
|
|
||||||
long nextTimeToCheckMiningXP;
|
long nextTimeToCheckMiningXP;
|
||||||
|
long nextTimeToRotateCamera;
|
||||||
|
|
||||||
public HumanBehavior() {
|
public HumanBehavior() {
|
||||||
nextTimeToCheckMiningXP = System.currentTimeMillis() + getNextTimeTillXPCheck();
|
nextTimeToCheckMiningXP = System.currentTimeMillis() + getNextTimeTillMiningXPCheck();
|
||||||
|
nextTimeToRotateCamera = System.currentTimeMillis() + getNextTimeTillCameraRotation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkMiningXP(Cursor cursor) throws Exception {
|
public void checkMiningXP(Cursor cursor) throws Exception {
|
||||||
cursor.moveAndLeftClickInBoundingRectangle(Constants.getStatsIconRectangle());
|
cursor.moveAndLeftClickInBoundingRectangle(Constants.getStatsIconRectangle());
|
||||||
|
Thread.sleep(Randomizer.nextGaussianWithinRange(280, 420));
|
||||||
cursor.moveInsideBoundingRectangle(Constants.getMiningXPRectangle());
|
cursor.moveInsideBoundingRectangle(Constants.getMiningXPRectangle());
|
||||||
Thread.sleep(Randomizer.nextGaussianWithinRange(1750, 3420));
|
Thread.sleep(Randomizer.nextGaussianWithinRange(1750, 3420));
|
||||||
cursor.moveAndLeftClickInBoundingRectangle(Constants.getInventoryIconRectangle());
|
cursor.moveAndLeftClickInBoundingRectangle(Constants.getInventoryIconRectangle());
|
||||||
|
@ -21,11 +26,24 @@ public class HumanBehavior {
|
||||||
public void randomlyCheckMiningXP(Cursor cursor) throws Exception {
|
public void randomlyCheckMiningXP(Cursor cursor) throws Exception {
|
||||||
if (System.currentTimeMillis() > nextTimeToCheckMiningXP) {
|
if (System.currentTimeMillis() > nextTimeToCheckMiningXP) {
|
||||||
checkMiningXP(cursor);
|
checkMiningXP(cursor);
|
||||||
nextTimeToCheckMiningXP = System.currentTimeMillis() + getNextTimeTillXPCheck();
|
System.out.println("Checking mining XP!");
|
||||||
|
nextTimeToCheckMiningXP = System.currentTimeMillis() + getNextTimeTillMiningXPCheck();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getNextTimeTillXPCheck() {
|
public void randomlyRotateCamera(CameraCalibrator cameraCalibrator) throws Exception {
|
||||||
|
if (System.currentTimeMillis() > nextTimeToRotateCamera) {
|
||||||
|
cameraCalibrator.randomlyShiftView();
|
||||||
|
System.out.println("Rotating camera!");
|
||||||
|
nextTimeToRotateCamera = System.currentTimeMillis() + getNextTimeTillCameraRotation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getNextTimeTillMiningXPCheck() {
|
||||||
return Randomizer.nextGaussianWithinRange(1000 * 60 * minimumTimeTillXPCheck, 1000 * 60 * maximumTimeTillXPCheck);
|
return Randomizer.nextGaussianWithinRange(1000 * 60 * minimumTimeTillXPCheck, 1000 * 60 * maximumTimeTillXPCheck);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getNextTimeTillCameraRotation() {
|
||||||
|
return Randomizer.nextGaussianWithinRange(1000 * 60 * minimumTimeTillCameraRotation, 1000 * 60 * maximumTimeTillCameraRotation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,6 +85,28 @@ public class Inventory {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getFirstIronOreInInventoryDifferentFromLast(int lastIronOreInInventory) throws IOException {
|
||||||
|
int ironOreInInventoryColumn = lastIronOreInInventory % 7;
|
||||||
|
int ironOreInInventoryRow = lastIronOreInInventory / 7;
|
||||||
|
if (lastIronOreInInventory < 0) {
|
||||||
|
ironOreInInventoryRow = -1;
|
||||||
|
ironOreInInventoryColumn = -1;
|
||||||
|
}
|
||||||
|
BufferedImage image = robot.createScreenCapture(this.inventoryRectangleToCapture);
|
||||||
|
for (int row = 0; row < Constants.INVENTORY_NUM_ROWS; row++) {
|
||||||
|
for (int column = 0; column < Constants.INVENTORY_NUM_COLUMNS; column++) {
|
||||||
|
if (row == ironOreInInventoryRow && column == ironOreInInventoryColumn) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
inventorySlots[row][column].updateInventorySlot(image);
|
||||||
|
if (!inventorySlots[row][column].isInventorySlotEmpty(items)) {
|
||||||
|
return (row * 7 + column);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
public void updateLastSlot() throws IOException {
|
public void updateLastSlot() throws IOException {
|
||||||
BufferedImage image = robot.createScreenCapture(this.inventoryRectangleToCapture);
|
BufferedImage image = robot.createScreenCapture(this.inventoryRectangleToCapture);
|
||||||
updateLastInventorySlot(image);
|
updateLastInventorySlot(image);
|
||||||
|
|
|
@ -24,7 +24,7 @@ import org.opencv.tracking.TrackerMOSSE;
|
||||||
public class IronMiner {
|
public class IronMiner {
|
||||||
|
|
||||||
public static final int IRON_ORE_MINING_TIME_MILLISECONDS = 1320;
|
public static final int IRON_ORE_MINING_TIME_MILLISECONDS = 1320;
|
||||||
public static final int MAXIMUM_DISTANCE_TO_WALK_TO_IRON_ORE = 400;
|
public static final int MAXIMUM_DISTANCE_TO_WALK_TO_IRON_ORE = 150;
|
||||||
|
|
||||||
Cursor cursor;
|
Cursor cursor;
|
||||||
CursorTask cursorTask;
|
CursorTask cursorTask;
|
||||||
|
@ -38,7 +38,7 @@ public class IronMiner {
|
||||||
|
|
||||||
public IronMiner() throws AWTException, IOException
|
public IronMiner() throws AWTException, IOException
|
||||||
{
|
{
|
||||||
int targetNumberOfDetectedOres = 2;
|
int targetNumberOfDetectedOres = 3;
|
||||||
cursor = new Cursor();
|
cursor = new Cursor();
|
||||||
cursorTask = new CursorTask();
|
cursorTask = new CursorTask();
|
||||||
inventory = new Inventory();
|
inventory = new Inventory();
|
||||||
|
@ -55,14 +55,16 @@ public class IronMiner {
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int worldHops = 0;
|
int worldHops = 0;
|
||||||
|
int lastIronOreInInventory = -1;
|
||||||
|
|
||||||
while (((System.currentTimeMillis() - startTime) / 1000.0 / 60) < 105) {
|
while (((System.currentTimeMillis() - startTime) / 1000.0 / 60) < 195) {
|
||||||
BufferedImage screenCapture = ImageCapturer.captureScreenshotGameWindow();
|
BufferedImage screenCapture = ImageCapturer.captureScreenshotGameWindow();
|
||||||
ArrayList<DetectedObject> detectedObjects = objectDetector.getObjectsInImage(screenCapture, 0.30);
|
ArrayList<DetectedObject> detectedObjects = objectDetector.getObjectsInImage(screenCapture, 0.30);
|
||||||
ArrayList<DetectedObject> ironOres = objectDetector.getIronOres(detectedObjects);
|
ArrayList<DetectedObject> ironOres = objectDetector.getIronOres(detectedObjects);
|
||||||
|
|
||||||
readjustCameraIfObjectsAreNotBeingDetected(detectedObjects.size());
|
readjustCameraIfObjectsAreNotBeingDetected(detectedObjects.size());
|
||||||
humanBehavior.randomlyCheckMiningXP(cursor);
|
humanBehavior.randomlyCheckMiningXP(cursor);
|
||||||
|
humanBehavior.randomlyRotateCamera(cameraCalibrator);
|
||||||
RandomDetector.dealWithRandoms(screenCapture, cursor);
|
RandomDetector.dealWithRandoms(screenCapture, cursor);
|
||||||
dropInventoryIfCloseToFull();
|
dropInventoryIfCloseToFull();
|
||||||
|
|
||||||
|
@ -72,7 +74,10 @@ public class IronMiner {
|
||||||
//Thread.sleep(Randomizer.nextGaussianWithinRange(20, 40));
|
//Thread.sleep(Randomizer.nextGaussianWithinRange(20, 40));
|
||||||
cursor.moveAndLeftClickAtCoordinatesWithRandomness(closestIronOre.getCenterForClicking(), 10, 10);
|
cursor.moveAndLeftClickAtCoordinatesWithRandomness(closestIronOre.getCenterForClicking(), 10, 10);
|
||||||
|
|
||||||
int ironOreInInventory = inventory.getFirstIronOreInInventory();
|
//System.out.println("Last iron ore: " + lastIronOreInInventory);
|
||||||
|
int ironOreInInventory = inventory.getFirstIronOreInInventoryDifferentFromLast(lastIronOreInInventory);
|
||||||
|
lastIronOreInInventory = ironOreInInventory;
|
||||||
|
//System.out.println("New iron ore: " + ironOreInInventory + "\n");
|
||||||
|
|
||||||
int numberOfOresInInventoryBefore = inventory.getNumberOfItemsOfTypeInInventory("ironOre");
|
int numberOfOresInInventoryBefore = inventory.getNumberOfItemsOfTypeInInventory("ironOre");
|
||||||
boolean miningSuccess = false;
|
boolean miningSuccess = false;
|
||||||
|
@ -109,12 +114,15 @@ public class IronMiner {
|
||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
System.out.println("Ores in inventory: " + numberOfOresInInventoryBefore + ". Mining success? " + miningSuccess);
|
//System.out.println("Ores in inventory: " + numberOfOresInInventoryBefore + ". Mining success? " + miningSuccess);
|
||||||
printMiningStats(count, startTime);
|
printMiningStats(count, startTime);
|
||||||
|
|
||||||
boolean worldHopped = hopWorldsIfMiningSuccessRateIsLow(miningSuccess);
|
boolean worldHopped = hopWorldsIfMiningSuccessRateIsLow(miningSuccess);
|
||||||
if (worldHopped) {
|
if (worldHopped) {
|
||||||
worldHops++;
|
worldHops++;
|
||||||
|
/*if (worldHops > 30) {
|
||||||
|
break;
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
System.out.println("worldHops: " + worldHops);
|
System.out.println("worldHops: " + worldHops);
|
||||||
}
|
}
|
||||||
|
@ -176,6 +184,10 @@ public class IronMiner {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*public isDetectedObjectInRange(int maxDistance) {
|
||||||
|
if (getDistanceBetweenPoints()
|
||||||
|
}*/
|
||||||
|
|
||||||
public int getDistanceBetweenPoints(Point startingPoint, Point goalPoint) {
|
public int getDistanceBetweenPoints(Point startingPoint, Point goalPoint) {
|
||||||
return (int) (Math.hypot(goalPoint.x - startingPoint.x, goalPoint.y - startingPoint.y));
|
return (int) (Math.hypot(goalPoint.x - startingPoint.x, goalPoint.y - startingPoint.y));
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue