Browse Source

Small refinements

master
davpapp 4 years ago
parent
commit
864b2a089a
9 changed files with 1172 additions and 10 deletions
  1. +1102
    -0
      hs_err_pid11338.log
  2. +8
    -0
      src/CameraCalibrator.java
  3. +23
    -5
      src/HumanBehavior.java
  4. +22
    -0
      src/Inventory.java
  5. +17
    -5
      src/IronMiner.java
  6. BIN
      target/classes/CameraCalibrator.class
  7. BIN
      target/classes/HumanBehavior.class
  8. BIN
      target/classes/Inventory.class
  9. BIN
      target/classes/IronMiner.class

+ 1102
- 0
hs_err_pid11338.log
File diff suppressed because it is too large
View File


+ 8
- 0
src/CameraCalibrator.java View File

@ -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));
}
}

+ 23
- 5
src/HumanBehavior.java View File

@ -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);
}
}

+ 22
- 0
src/Inventory.java View File

@ -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);


+ 17
- 5
src/IronMiner.java View File

@ -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));
}


BIN
target/classes/CameraCalibrator.class View File


BIN
target/classes/HumanBehavior.class View File


BIN
target/classes/Inventory.class View File


BIN
target/classes/IronMiner.class View File


Loading…
Cancel
Save