Merge pull request #6106 from devLotto/issue-5325
puzzlesolver: wait a duration before recomputing the solution
This commit is contained in:
@@ -332,7 +332,8 @@ public class PuzzleSolverOverlay extends Overlay
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Solve the puzzle if we don't have an up to date solution
|
// Solve the puzzle if we don't have an up to date solution
|
||||||
if (solver == null || cachedItems == null || (!shouldCache && !Arrays.equals(cachedItems, itemIds)))
|
if (solver == null || cachedItems == null
|
||||||
|
|| (!shouldCache && solver.hasExceededWaitDuration() && !Arrays.equals(cachedItems, itemIds)))
|
||||||
{
|
{
|
||||||
solve(itemIds);
|
solve(itemIds);
|
||||||
shouldCache = true;
|
shouldCache = true;
|
||||||
|
|||||||
@@ -25,6 +25,8 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.client.plugins.puzzlesolver.solver;
|
package net.runelite.client.plugins.puzzlesolver.solver;
|
||||||
|
|
||||||
|
import com.google.common.base.Stopwatch;
|
||||||
|
import java.time.Duration;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.runelite.client.plugins.puzzlesolver.solver.pathfinding.Pathfinder;
|
import net.runelite.client.plugins.puzzlesolver.solver.pathfinding.Pathfinder;
|
||||||
|
|
||||||
@@ -33,11 +35,14 @@ public class PuzzleSolver implements Runnable
|
|||||||
public static final int DIMENSION = 5;
|
public static final int DIMENSION = 5;
|
||||||
public static final int BLANK_TILE_VALUE = -1;
|
public static final int BLANK_TILE_VALUE = -1;
|
||||||
|
|
||||||
|
private static final Duration MAX_WAIT_DURATION = Duration.ofMillis(1500);
|
||||||
|
|
||||||
private Pathfinder pathfinder;
|
private Pathfinder pathfinder;
|
||||||
private PuzzleState startState;
|
private PuzzleState startState;
|
||||||
|
|
||||||
private List<PuzzleState> solution;
|
private List<PuzzleState> solution;
|
||||||
private int position;
|
private int position;
|
||||||
|
private Stopwatch stopwatch;
|
||||||
private boolean failed = false;
|
private boolean failed = false;
|
||||||
|
|
||||||
public PuzzleSolver(Pathfinder pathfinder, PuzzleState startState)
|
public PuzzleSolver(Pathfinder pathfinder, PuzzleState startState)
|
||||||
@@ -71,6 +76,11 @@ public class PuzzleSolver implements Runnable
|
|||||||
this.position = position;
|
this.position = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasExceededWaitDuration()
|
||||||
|
{
|
||||||
|
return stopwatch.elapsed().compareTo(MAX_WAIT_DURATION) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasFailed()
|
public boolean hasFailed()
|
||||||
{
|
{
|
||||||
return failed;
|
return failed;
|
||||||
@@ -79,6 +89,7 @@ public class PuzzleSolver implements Runnable
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
|
stopwatch = Stopwatch.createStarted();
|
||||||
solution = pathfinder.computePath(startState);
|
solution = pathfinder.computePath(startState);
|
||||||
failed = solution == null;
|
failed = solution == null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user