Bug - Fixed lastTrainsetConfiguration incorrectly reset during initialization

In unrestricted aftercore (after a grey you run), I configured my trainset at 623, ran 34 combats so that
Code:
trainsetPosition
was at 657, then my script aborted, I killed Java and then restarted mafia. Upon initialization of the session, mafia unhelpfully set
Code:
lastTrainsetConfiguration
from 623 to 617, making my script think that it could reconfigure, but reconfiguration was not available.

Did mafia look at the workshed while refreshing and incorrectly decide that its own tracking was off, and that the trainset was in fact ready to reconfigure or something?
 
I may be too literal but "killed Java" concerns me. Is it possible that you corrupted a preference file and it was reloaded from a backup or killing Java somehow prevented the disk file from being updated?
 
I don't think so. I have a script that kills Java many hours after my script runs. But it's possible that this is a part of the problem.

But I feel like I regularly see this kind of behaviour, where KoLmafia changes the lastTrainsetPosition preference to 40 less than trainsetPosition when it is not yet available. My script checks if reconfiguration is available every adventure, but it only seems to get out of sync when a refresh is done.
 
I automatically kill KoLmafia with a script before rollover. I use "kill -HUP" instead of just "kill" and that lets mafia save its preference file before quitting.
 
As the author of the trainset code, I feel like this is intentional.

Unfortunately I am on my phone and apparently I wasn't speaking plain English in the description.

Perhaps if you can prove that a test is wrong? It might just be that there's some weird behavior with trainset that wasn't known at the time. Or kol changed something.

To be clear, I am not saying that this isn't a bug. I think I might have noticed this myself. I just can't remember if it was known at the time and why it would be doing this. That a junit test would be ideal.
 
Alright, looked into this briefly and I think its because a free fight can move the trainset, but its free which we didn't take into account.

In my head, it goes
1. You reconfigure, mafia tracks that
2. You do a free fight, trainset moves. Mafia tracks that.
3. You visit the workshed, trainset can be configured.. Mafia tracks th- Mafia blinks. It shouldn't be configurable. It doesn't know how to track that.

I think I have the following questions
1. Is the configuration locked when we move the trainset position, or when we spend a turn
2. If we move the position without locking the configuration, does it contribute to the cooldown or do we need to spend a turn first
3. This should be true, but does free fights change any of the expected behavior after configuration is locked in
 
I think the problem is just that if you do a `refresh all` while your trainset is on its last lap before it's available again, mafia erroneously concludes that it's actually available, and updates the lastTrainsetConfiguration preference to be 40 less than the trainsetPosition preference. It's probably just missing the regex for the page text of the last lap.
 
Here's an excerpt from a debug log showing the behaviour when I run `refresh all` when the trainset is installed, and when it's on the last lap before it can be reconfigured. Note that `refresh camp` doesn't seem to exhibit the same behaviour.

The error is that kolmafia reads the workshed page which includes the message "Let the train finish this lap before rearranging it." and erroneously thinks that the trainset is ready to be adjusted, incorrectly setting `lastTrainsetConfiguration` to `trainsetPosition` - 40.
 

Attachments

It looks like the error is in trainsetManager.java, line 87:
Code:
private static final Pattern LAPS_BEFORE_RECONFIGURE =
Pattern.compile("Let the train finish (\\d) more laps before rearranging it.</p>");
and it is used on line 169:
Code:
      Matcher laps = LAPS_BEFORE_RECONFIGURE.matcher(html);

      // If we can configure the train
      if (!laps.find()) {
        // If the trainset has been configured this turn
        if (lastPosition == lastConfiguration) {
          return;
        }

        // If we expected train to be unconfigurable
        if (lastPosition < expectedTurnConfigurable) {
          // Set the last configuration to a value 40 turns behind
          Preferences.setInteger(
              "lastTrainsetConfiguration", lastPosition - TURNS_BETWEEN_CONFIGURE);
        }
      } else {
        // If we cannot reconfigure the train, we will be assuming worse case scenario of full laps

        // Get the expected laps remaining, and actual laps remaining
        int expectedLapsRemaining = (int) Math.ceil((expectedTurnConfigurable - lastPosition) / 8D);
        int actualLapsRemaining = Integer.parseInt(laps.group(1));

        // If the expected laps is different from the actual laps
        // Or if the configuration should've been older
        if (expectedLapsRemaining != actualLapsRemaining || lastConfiguration == lastPosition) {
          // Set the last configuration to laps x 8 behind.
          // So 5 laps remaining will set the last position to -39 if lastPosition is 0
          // We don't set it to -40 as it would indicate a full 5 laps has elapsed
          Preferences.setInteger(
              "lastTrainsetConfiguration", lastPosition - (((5 - actualLapsRemaining) * 8) + 1));
        }
      }
 
Back
Top