mirror of
https://github.com/davpapp/PowerMiner
synced 2025-01-08 12:28:06 -05:00
Small refinements
This commit is contained in:
parent
381ff01b53
commit
864b2a089a
1102
hs_err_pid11338.log
Normal file
1102
hs_err_pid11338.log
Normal file
File diff suppressed because it is too large
Load Diff
@ -35,4 +35,12 @@ public class CameraCalibrator {
|
||||
robot.keyRelease(KeyEvent.VK_LEFT);
|
||||
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 {
|
||||
|
||||
private int minimumTimeTillXPCheck = 35;
|
||||
private int maximumTimeTillXPCheck = 75;
|
||||
private int minimumTimeTillXPCheck = 25;
|
||||
private int maximumTimeTillXPCheck = 73;
|
||||
private int minimumTimeTillCameraRotation = 32;
|
||||
private int maximumTimeTillCameraRotation = 61;
|
||||
|
||||
long nextTimeToCheckMiningXP;
|
||||
long nextTimeToRotateCamera;
|
||||
|
||||
public HumanBehavior() {
|
||||
nextTimeToCheckMiningXP = System.currentTimeMillis() + getNextTimeTillXPCheck();
|
||||
nextTimeToCheckMiningXP = System.currentTimeMillis() + getNextTimeTillMiningXPCheck();
|
||||
nextTimeToRotateCamera = System.currentTimeMillis() + getNextTimeTillCameraRotation();
|
||||
}
|
||||
|
||||
public void checkMiningXP(Cursor cursor) throws Exception {
|
||||
cursor.moveAndLeftClickInBoundingRectangle(Constants.getStatsIconRectangle());
|
||||
Thread.sleep(Randomizer.nextGaussianWithinRange(280, 420));
|
||||
cursor.moveInsideBoundingRectangle(Constants.getMiningXPRectangle());
|
||||
Thread.sleep(Randomizer.nextGaussianWithinRange(1750, 3420));
|
||||
cursor.moveAndLeftClickInBoundingRectangle(Constants.getInventoryIconRectangle());
|
||||
@ -21,11 +26,24 @@ public class HumanBehavior {
|
||||
public void randomlyCheckMiningXP(Cursor cursor) throws Exception {
|
||||
if (System.currentTimeMillis() > nextTimeToCheckMiningXP) {
|
||||
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);
|
||||
}
|
||||
|
||||
private int getNextTimeTillCameraRotation() {
|
||||
return Randomizer.nextGaussianWithinRange(1000 * 60 * minimumTimeTillCameraRotation, 1000 * 60 * maximumTimeTillCameraRotation);
|
||||
}
|
||||
}
|
||||
|
@ -85,6 +85,28 @@ public class Inventory {
|
||||
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 {
|
||||
BufferedImage image = robot.createScreenCapture(this.inventoryRectangleToCapture);
|
||||
updateLastInventorySlot(image);
|
||||
|
@ -24,7 +24,7 @@ import org.opencv.tracking.TrackerMOSSE;
|
||||
public class IronMiner {
|
||||
|
||||
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;
|
||||
CursorTask cursorTask;
|
||||
@ -38,7 +38,7 @@ public class IronMiner {
|
||||
|
||||
public IronMiner() throws AWTException, IOException
|
||||
{
|
||||
int targetNumberOfDetectedOres = 2;
|
||||
int targetNumberOfDetectedOres = 3;
|
||||
cursor = new Cursor();
|
||||
cursorTask = new CursorTask();
|
||||
inventory = new Inventory();
|
||||
@ -55,14 +55,16 @@ public class IronMiner {
|
||||
|
||||
int count = 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();
|
||||
ArrayList<DetectedObject> detectedObjects = objectDetector.getObjectsInImage(screenCapture, 0.30);
|
||||
ArrayList<DetectedObject> ironOres = objectDetector.getIronOres(detectedObjects);
|
||||
|
||||
readjustCameraIfObjectsAreNotBeingDetected(detectedObjects.size());
|
||||
humanBehavior.randomlyCheckMiningXP(cursor);
|
||||
humanBehavior.randomlyRotateCamera(cameraCalibrator);
|
||||
RandomDetector.dealWithRandoms(screenCapture, cursor);
|
||||
dropInventoryIfCloseToFull();
|
||||
|
||||
@ -72,7 +74,10 @@ public class IronMiner {
|
||||
//Thread.sleep(Randomizer.nextGaussianWithinRange(20, 40));
|
||||
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");
|
||||
boolean miningSuccess = false;
|
||||
@ -109,12 +114,15 @@ public class IronMiner {
|
||||
}
|
||||
count++;
|
||||
|
||||
System.out.println("Ores in inventory: " + numberOfOresInInventoryBefore + ". Mining success? " + miningSuccess);
|
||||
//System.out.println("Ores in inventory: " + numberOfOresInInventoryBefore + ". Mining success? " + miningSuccess);
|
||||
printMiningStats(count, startTime);
|
||||
|
||||
boolean worldHopped = hopWorldsIfMiningSuccessRateIsLow(miningSuccess);
|
||||
if (worldHopped) {
|
||||
worldHops++;
|
||||
/*if (worldHops > 30) {
|
||||
break;
|
||||
}*/
|
||||
}
|
||||
System.out.println("worldHops: " + worldHops);
|
||||
}
|
||||
@ -176,6 +184,10 @@ public class IronMiner {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*public isDetectedObjectInRange(int maxDistance) {
|
||||
if (getDistanceBetweenPoints()
|
||||
}*/
|
||||
|
||||
public int getDistanceBetweenPoints(Point startingPoint, Point goalPoint) {
|
||||
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
Block a user