Compare commits

...

2 Commits

Author SHA1 Message Date
dtookey
fdb4eb3d57 Orchestrator has been documented 2023-08-06 19:29:38 -04:00
dtookey
7bda420a5d HelperFunctions.kt has some documentation 2023-08-06 19:25:48 -04:00
2 changed files with 44 additions and 14 deletions

View File

@ -1,3 +1,6 @@
/**
* A collection of helper functions for common utility tasks.
*/
object HelperFunctions { object HelperFunctions {
/** /**
* Computes the total number of steps needed to process the given total volume. * Computes the total number of steps needed to process the given total volume.

View File

@ -1,9 +1,27 @@
import java.awt.Point import java.awt.Point
/**
* Interface for orchestrating automated interactions with the game.
*
* Implementations of this interface handle executing workflows and routines to automate
* gameplay through an [Automaton] instance.
*/
interface Orchestrator { interface Orchestrator {
/**
* The [Automaton] instance used by this orchestrator to interact with the game.
*/
val automaton: Automaton val automaton: Automaton
/**
* Scrolls out to the specified height by repeating scroll in/out operations.
*
* This handles scrolling out by the given height through a series of repeated scroll in and
* scroll out operations using the [doLoop] method.
*
* @param height The height in game coordinates to scroll out to.
* @param scrollWaitAndVariance The number of milliseconds to wait between scroll actions.
*/
fun scrollOutToHeight(height: Int, scrollWaitAndVariance: Long = 10L) { fun scrollOutToHeight(height: Int, scrollWaitAndVariance: Long = 10L) {
automaton.sleep(1000) automaton.sleep(1000)
doLoop(height * 2, 1) { doLoop(height * 2, 1) {
@ -17,19 +35,19 @@ interface Orchestrator {
/** /**
* Performs a loop to repeatedly execute a task for automated steps. * Performs a repetitive task multiple times.
* *
* @param totalVolume The total number of units to process across all steps. * This handles iterating over the loop, tracking progress, and calling the provided task function each iteration.
* @param volumePerStep The number of units to process per step.
* @param task The task function to execute on each step. It receives the Agent.
* *
* This method handles iterating through the steps, reporting progress, * @param totalVolume The total number of units that need to be processed.
* timing the overall execution, and calling the task on each iteration. * @param volumePerStep The number of units to process per iteration.
* * @param task The function to call each iteration, passing the Orchestrator as argument.
* It uses computeTotalSteps to calculate how many iterations needed based on total
* and per step volumes. The task typically simulates some action like banking.
*/ */
fun doLoop(totalVolume: Int, volumePerStep: Int, task: (Orchestrator) -> Unit) { fun doLoop(
totalVolume: Int,
volumePerStep: Int,
task: (Orchestrator) -> Unit
) {
require(totalVolume > 0) { require(totalVolume > 0) {
"You must make at least 1 thing in total" "You must make at least 1 thing in total"
} }
@ -45,14 +63,23 @@ interface Orchestrator {
HelperFunctions.report(i + 1, totalSteps, System.currentTimeMillis() - start) HelperFunctions.report(i + 1, totalSteps, System.currentTimeMillis() - start)
task(this) task(this)
} }
println() print("\r ")
val finish = System.currentTimeMillis() val finish = System.currentTimeMillis()
println("Finished everything in ${HelperFunctions.prettyTimeString(finish - start)}") println("Finished everything in ${HelperFunctions.prettyTimeString(finish - start)}")
} }
/**
* Prompts the user to input a point and returns the point.
*
* @param prompt The message to display to the user asking for a point input.
* @return The Point object based on the user's input.
*/
fun promptUserForPoint(prompt: String): Point fun promptUserForPoint(prompt: String): Point
/**
* Draws a star shape at the specified point on the screen.
*
* @param p The center point of the star to draw.
*/
fun drawStar(p: Point) fun drawStar(p: Point)
} }