comments and renaming for easier to read code

This commit is contained in:
Louis Hong
2024-10-30 22:24:30 -07:00
parent 14130b3987
commit 9d7304a436
5 changed files with 34 additions and 24 deletions

View File

@@ -44,7 +44,7 @@ public class EasyGiantsFoundryState
@Setter
@Getter
private int lastKnownCrucibleScore = -1; // will be set when "Pour"ed
private int lastKnownCrucibleScore = -1; // will be set when "Pour"ed (because the crucible will be empty then)
private final List<Stage> stages = new ArrayList<>();
private double heatRangeRatio = 0;

View File

@@ -158,11 +158,11 @@ public class FoundryOverlay3D extends Overlay
if (state.heatingCoolingState.isCooling())
{
drawHeatingCoolingOverlay(graphics, waterfall);
drawHeatChangerOverlay(graphics, waterfall);
}
if (state.heatingCoolingState.isHeating())
{
drawHeatingCoolingOverlay(graphics, lavaPool);
drawHeatChangerOverlay(graphics, lavaPool);
}
@@ -195,7 +195,7 @@ public class FoundryOverlay3D extends Overlay
modelOutlineRenderer.drawOutline(stageObject, config.borderThickness(), _color, config.borderFeather());
}
private void drawHeatingCoolingOverlay(
private void drawHeatChangerOverlay(
Graphics2D graphics,
GameObject stageObject
)

View File

@@ -78,22 +78,30 @@ public class HeatActionSolver
{
/**
* <b>Warning:</b> this method prefers overshooting goal. For example, if goal is 957,
* it will return index that reaches >957.<br>
* This may be desirable if we're aiming to heat over range minimum,
* but undesirable when cooling below range maximum; make sure to -1 the index if so.
* <p><b>Warning:</b> this method prefers overshooting goal. For example, if goal is 957,
* it will return index that reaches >957.</p>
*
* <p>This may be desirable if we're aiming to heat just over range minimum;
* for example if the stage is heating (grind stone),</p>
*
* <p>but undesirable when heating to just below range maximum;
* for example if the stage is cooling (hammer.)</p>
*
* <p>
* Make sure to subtract 1 tick from duration, if so.
* </p>
*
*
*
* @param goal the desired heat destination
* @param init_dx1 initial speed of heating/cooling. currently 7 for heat/cool, 27 for dunk/quench.
* @param dx1_init initial speed of heating/cooling. currently 7 for heat/cool, 27 for dunk/quench.
* @param dx2_offset bonus acceleration. currently, 0 for heat/cool, 2 for dunk/quench.
* @return Index here refers to tick. So an index of 10 means the goal can be reached in 10 ticks.
*/
public static int findDx0Index(int goal, int init_dx1, int dx2_offset)
public static int findDuration(int goal, int dx1_init, int dx2_offset)
{
int dx0 = 0;
int dx1 = init_dx1;
int dx1 = dx1_init;
int count_index = 0;
for (int dx2 = 1; dx0 <= goal; dx2++)
{ // Start from 1 up to the count inclusive

View File

@@ -121,6 +121,7 @@ public class HeatActionStateMachine
Stage stage = State.getCurrentStage();
int actionsLeft = State.getActionsLeftInStage();
int actionsLeft_DeltaHeat = (actionsLeft+1) * stage.getHeatChange();
if (isHeating())
{
if (stage.isHeating())
@@ -128,14 +129,15 @@ public class HeatActionStateMachine
GoalHeat = Math.max(stageMin, stageMax - actionsLeft_DeltaHeat);
if (StartingHeat < GoalHeat)
{
int duration = HeatActionSolver.findDx0Index(
int duration = HeatActionSolver.findDuration(
GoalHeat - StartingHeat,
Velocity, AccelerationBonus
);
// compensate for heat decay during (1 heat every 2 ticks)
GoalHeat += duration / 2;
EstimatedDuration = HeatActionSolver.findDx0Index(
EstimatedDuration = HeatActionSolver.findDuration(
GoalHeat - StartingHeat,
Velocity, AccelerationBonus
);
@@ -151,14 +153,14 @@ public class HeatActionStateMachine
GoalHeat = Math.min(stageMax, stageMin - actionsLeft_DeltaHeat);
if (StartingHeat < GoalHeat)
{
int duration = HeatActionSolver.findDx0Index(
int duration = HeatActionSolver.findDuration(
GoalHeat - StartingHeat,
Velocity, AccelerationBonus
) - 1;
GoalHeat -= duration / 2;
EstimatedDuration = HeatActionSolver.findDx0Index(
EstimatedDuration = HeatActionSolver.findDuration(
GoalHeat - StartingHeat,
Velocity, AccelerationBonus
) - 1;
@@ -175,14 +177,14 @@ public class HeatActionStateMachine
GoalHeat = Math.max(stageMin, stageMax - actionsLeft_DeltaHeat);
if (StartingHeat > GoalHeat)
{
int duration = HeatActionSolver.findDx0Index(
int duration = HeatActionSolver.findDuration(
StartingHeat - GoalHeat,
Math.abs(Velocity), Math.abs(AccelerationBonus)
) - 1;
GoalHeat += duration / 2;
EstimatedDuration = HeatActionSolver.findDx0Index(
EstimatedDuration = HeatActionSolver.findDuration(
(StartingHeat - GoalHeat),
Math.abs(Velocity), Math.abs(AccelerationBonus)
) - 1;
@@ -197,14 +199,14 @@ public class HeatActionStateMachine
GoalHeat = Math.max(stageMax, stageMin + actionsLeft_DeltaHeat);
if (StartingHeat > GoalHeat) // too hot
{
int duration = HeatActionSolver.findDx0Index(
int duration = HeatActionSolver.findDuration(
StartingHeat - GoalHeat,
Math.abs(Velocity), Math.abs(AccelerationBonus)
);
GoalHeat -= duration / 2;
EstimatedDuration = HeatActionSolver.findDx0Index(
EstimatedDuration = HeatActionSolver.findDuration(
StartingHeat - GoalHeat,
Math.abs(Velocity), Math.abs(AccelerationBonus)
);

View File

@@ -99,7 +99,7 @@ public class HeatSolverTest
{
for (int i = 0; i < 50; i++)
{
System.err.println("[" + (350 + i) + "]" + HeatActionSolver.findDx0Index(350 + i, 7, 0));
System.err.println("[" + (350 + i) + "]" + HeatActionSolver.findDuration(350 + i, 7, 0));
}
}
@@ -131,18 +131,18 @@ public class HeatSolverTest
// System.err.println(
// HeatSolver.findDx0IndexContinue(1000, 7, 0));
System.err.println(
HeatActionSolver.findDx0Index(957, 27, 2));
HeatActionSolver.findDuration(957, 27, 2));
// System.err.println(
// HeatActionSolver.findDx0Index(1000, 7, 1));
// HeatActionSolver.findDuration(1000, 7, 1));
}
public void TestHeatSolver_Dx0_Helper(int dx0, int constant, int answer_index)
{
System.err.print(dx0 + "->" + HeatActionSolver.findDx0Index(dx0, constant, 0) + ",");
System.err.print(dx0 + "->" + HeatActionSolver.findDuration(dx0, constant, 0) + ",");
// test calcDx0Index
assertEquals("Asserting dx0 for index " + answer_index,
answer_index, HeatActionSolver.findDx0Index(dx0, constant, 0));
answer_index, HeatActionSolver.findDuration(dx0, constant, 0));
}
@Test