Began work on tracking mining success rate

This commit is contained in:
davpapp 2018-03-14 04:18:07 -04:00
parent d4ea5ec01c
commit 104882c542
12 changed files with 87 additions and 10 deletions

View File

@ -22,11 +22,11 @@ public class DropperThread implements Runnable {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("~~~~~~~~~~~~~ dropperThread finished!");
//System.out.println("~~~~~~~~~~~~~ dropperThread finished!");
}
public void start() {
System.out.println("dropperThread started");
//System.out.println("dropperThread started");
if (dropperThread == null) {
dropperThread = new Thread(this, "dropperThread");
dropperThread.start();

View File

@ -44,14 +44,26 @@ public class Inventory {
updateAllInventorySlots(image);
}
public int getNumberOfItemsOfTypeInInventory(String itemType) throws IOException {
int numberOfItemsOfType = 0;
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++) {
inventorySlots[row][column].updateInventorySlot(image);
if (inventorySlots[row][column].getItemNameInInventorySlot(items).equals(itemType)) {
numberOfItemsOfType++;
}
}
}
return numberOfItemsOfType++;
}
public int getFirstIronOreInInventory() throws IOException {
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++) {
inventorySlots[row][column].updateInventorySlot(image);
if (!inventorySlots[row][column].isInventorySlotEmpty(items)) {
//System.out.println("Not empty!");
System.out.println("Returning " + (row * 7 + column));
return (row * 7 + column);
}
}

View File

@ -35,6 +35,7 @@ public class IronMiner {
CameraCalibrator cameraCalibrator;
RandomDetector randomDetector;
WorldHopper worldHopper;
MiningSuccessHistory miningSuccessHistory;
ObjectDetectionHistory objectDetectionHistory;
public IronMiner() throws AWTException, IOException
@ -49,6 +50,7 @@ public class IronMiner {
randomDetector = new RandomDetector();
worldHopper = new WorldHopper();
cameraCalibrator = new CameraCalibrator(targetNumberOfDetectedOres);
miningSuccessHistory = new MiningSuccessHistory();
objectDetectionHistory = new ObjectDetectionHistory(targetNumberOfDetectedOres);
}
@ -56,9 +58,8 @@ public class IronMiner {
long startTime = System.currentTimeMillis();
int count = 0;
while (((System.currentTimeMillis() - startTime) / 1000.0 / 75) < 85) {
while (((System.currentTimeMillis() - startTime) / 1000.0 / 60) < 85) {
BufferedImage screenCapture = objectDetector.captureScreenshotGameWindow();
ArrayList<DetectedObject> detectedObjects = objectDetector.getObjectsInImage(screenCapture, 0.30);
ArrayList<DetectedObject> ironOres = objectDetector.getIronOres(detectedObjects);
@ -70,6 +71,8 @@ public class IronMiner {
cursor.moveAndLeftClickAtCoordinatesWithRandomness(closestIronOre.getCenterForClicking(), 10, 10);
int ironOreInInventory = inventory.getFirstIronOreInInventory();
int numberOfOresInInventoryBefore = inventory.getNumberOfItemsOfTypeInInventory("ironOre");
int numberOfOresInInventoryAfter = 0;
if (ironOreInInventory > -1) {
int ironOreInInventoryColumn = ironOreInInventory % 7;
@ -86,16 +89,27 @@ public class IronMiner {
trackerThread.waitTillDone();
dropperThread.waitTillDone();
Point rightClickLocation = cursor.getCurrentCursorPoint();
cursorTask.leftClickDropOption(cursor, rightClickLocation, 0);
numberOfOresInInventoryAfter = inventory.getNumberOfItemsOfTypeInInventory("ironOre") + 1;
}
else {
TrackerThread trackerThread = new TrackerThread(screenCapture, closestIronOre, objectDetector);
trackerThread.start();
trackerThread.waitTillDone();
numberOfOresInInventoryAfter = inventory.getNumberOfItemsOfTypeInInventory("ironOre");
}
count++;
//System.out.println(count + ", time: " + ((System.currentTimeMillis() - startTime) / 1000 / 60));
boolean miningSuccess = (numberOfOresInInventoryAfter > numberOfOresInInventoryBefore);
//System.out.println("Ores in inventory: " + numberOfOresInInventoryBefore + ". Mining success? " + miningSuccess);
hopWorldsIfMiningSuccessRateIsLow(miningSuccess);
System.out.println(count + ", time: " + ((System.currentTimeMillis() - startTime) / 1000 / 60));
}
humanBehavior.randomlyCheckMiningXP(cursor);
randomDetector.dealWithRandoms(screenCapture, cursor);
@ -103,6 +117,13 @@ public class IronMiner {
}
}
private void hopWorldsIfMiningSuccessRateIsLow(boolean miningSuccess) {
boolean hopWorld = miningSuccessHistory.updateHistory(miningSuccess);
if (hopWorld) {
//System.out.println("Hopping worlds (Theoretically)");
miningSuccessHistory.resetQueue();
}
}
private void readjustCameraIfObjectsAreNotBeingDetected(int detectedObjectsSize) throws Exception {
boolean readjustCamera = objectDetectionHistory.updateHistory(detectedObjectsSize);
@ -110,7 +131,6 @@ public class IronMiner {
cameraCalibrator.rotateUntilObjectFound(objectDetector, "ironOre");
objectDetectionHistory.resetQueue();
}
}
private void dropInventoryIfFull() throws Exception {

View File

@ -0,0 +1,46 @@
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
public class MiningSuccessHistory {
int queueSize;
int numberOfTruesInQueue;
Queue<Boolean> miningSuccessHistory;
public MiningSuccessHistory() {
queueSize = 30;
this.numberOfTruesInQueue = queueSize;
miningSuccessHistory = new LinkedList<Boolean>();
for (int i = 0; i < queueSize; i++) {
miningSuccessHistory.add(true);
}
}
public boolean updateHistory(boolean success) {
miningSuccessHistory.add(success);
if (success) {
numberOfTruesInQueue++;
}
if (miningSuccessHistory.poll()) {
numberOfTruesInQueue--;
}
return isMiningRateSufficient();
}
private boolean isMiningRateSufficient() {
return numberOfTruesInQueue < (queueSize * 0.6);
}
public void resetQueue() {
this.numberOfTruesInQueue = queueSize;
miningSuccessHistory.clear();
for (int i = 0; i < queueSize; i++) {
miningSuccessHistory.add(true);
}
}
public void displayStats() {
System.out.println("Mining success rate: " + (numberOfTruesInQueue * 1.0 / queueSize));
}
}

View File

@ -25,7 +25,6 @@ public class ObjectDetectionHistory {
}
public void updateHistory(boolean success) {
System.out.println("Increasing? " + success);
numberOfDetectedObjectsHistory.add(success);
if (success) {
numberOfTruesInQueue++;

View File

@ -65,7 +65,7 @@ public class TrackerThread implements Runnable {
}
public void start() {
System.out.println("TrackerThread started");
//System.out.println("TrackerThread started");
if (trackerThread == null) {
trackerThread = new Thread(this, "trackerThread");
trackerThread.start();

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.