Bug - Fixed turn spent getting boring binder clip not counted when it is turned into file on obtention

turns_spent is not incremented in The Hidden Office Building when McClusky file (complete) immediately assembled on obtention of boring binder clip, this means when the 5 pages are already in possession when taking the clip in at Working Holiday which is the 6th turn spent.

turns_spent is correctly incremented if the 5 pages are not in possession when taking the boring binder clip. I do not know what it has to do with turns_spent but observed the value in 6 ascensions, 3 correctly incremented and 3 did not and this was the difference.

[542] The Hidden Office Building Encounter: pygmy witch accountant
first turn in the zone
[543] The Hidden Office Building Encounter: pygmy witch accountant
[544] The Hidden Office Building Encounter: pygmy witch accountant
[545] The Hidden Office Building Encounter: pygmy witch lawyer
[546] The Hidden Office Building Encounter: pygmy witch accountant
mafia correctly thinks 5 turns have been spent
[547] The Hidden Office Building Encounter: Working Holiday Submitting option 2 for choice 786 You acquire an item: boring binder clip
mafia automatically turns it into complete file right away because it has 5 files
mafia still thinks 5 turns have been spent, should be 6
[548] The Hidden Office Building Encounter: pygmy headhunter
$location[the hidden office].turns_spent is 6, should be 7

without ever using the non combat encounter choice that leads to combat. in other zones (haunted bedroom, penultimate fantasy ship) turns_spent is too high perhaps because of chained non combat and combat not being counted as 1, there is one such chain in The Hidden Office Building but I never took that choice testing this
 

lostcalpolydude

Developer
Staff member
I haven't looked at the code for this in a long time, but I do remember that it was kind of a mess trying to handle all the weird cases. Eventually I gave up on fixing things I knew weren't working right, because I couldn't see a way of improving it.

If anyone actually wants to take a look at it, make sure to look at both relay browser adventuring and automated adventuring. KoLmafia relies on retrieving turncount from charpane/api to tell if a noncombat took a turn, and the order of loading charpane.php versus api.php, compared with processing whatever page is in the main pane, tends to vary.
 

Veracity

Developer
Staff member
turns_spent is not incremented in The Hidden Office Building when McClusky file (complete) immediately assembled on obtention of boring binder clip, this means when the 5 pages are already in possession when taking the clip in at Working Holiday which is the 6th turn spent.
What is "turns_spent"?

KoLmafia doesn't independently maintain/increment a turn counter.
It uses whatever charpane.php or api.php says.
If you are running a script, until that call is processed, turns_played() will not increment.

Code:
[542] The Hidden Office Building Encounter: pygmy witch accountant
[543] The Hidden Office Building Encounter: pygmy witch accountant
[544] The Hidden Office Building Encounter: pygmy witch accountant
[545] The Hidden Office Building Encounter: pygmy witch lawyer
[546] The Hidden Office Building Encounter: pygmy witch accountant
[547] The Hidden Office Building Encounter: Working Holiday
Submitting option 2 for choice 786
You acquire an item: boring binder clip
[548] The Hidden Office Building Encounter: pygmy headhunter
Looking at the turn counter, it obviously knows what turn it is.

Code:
$location[the hidden office].turns_spent is 6, should be 7
Ah. I have no idea how the code for that feature operates. I have never looked at it or used or written a script the depended on it.
 

Veracity

Developer
Staff member
I see what is happening.

We increment turns_spent immediately after a completed fight, but not after a choice.
This is because not all choices increment turns - and some choices can either take a turn or not.

For a choice, we do AdventureSpentDatabase.setNonCombatEncountered(true).
We do this only if the response text requests a charpane refresh.
Which is to say, KoL itself thinks something has changed.

Next time we get a charpane.php or api.php response, we will update turns_spent if a turn has actually passed since AdventureSpentDatabase has registered a turn.

Then, whether or not a turn has passed, we clear that flag AND increment AdventureSpentDatabase.LastTurnUpdate.

In this situation.
- We do autoCrafting when processing a response that gives us an appropriate item. Like a boring binder clip.
- In particular, in postChoice2, choice 786/2 does this: ResultProcessor.autoCreate(ItemPool.MCCLUSKY_FILE);
- postChoice2 has already done this: ChoiceManager.handlingChoice = ChoiceManager.stillInChoice(text);
- Which is to say, we are no longer "still in a choice", so autoCreate will actually create the item.
---> And we will call api.php after that creation, which will clear/update the AdventureSpentDatabase variables previously mentioned.

AFTER we have done that, we setNonCombatEncountered and the NEXT charpane or api response will see that the turn has already been counted and will not update the data.

I think if we put the following:

Code:
    if (text.contains("charpane.php")) {
      // Since a charpane refresh was requested, a turn might have been spent
      AdventureSpentDatabase.setNoncombatEncountered(true);
    }

AFTER we set handlingChoice and BEFORE doing the per-choice handling, this will fix this.
The same issue presumably exists for autoCreating the Talisman if Shen gives you the second piece of it in the club.

(I originally had !handlingChoice there, but I think not. Some choice chains - like in the Spooky Forest - do not take a turn until the final choice is taken, but some - getting the beehive, opening the Hidden City - take a turn each step of the way.)

I'd like a DEBUG log so we can write a test for this, please.

Thanks.
 

Veracity

Developer
Staff member
in other zones (haunted bedroom, penultimate fantasy ship) turns_spent is too high perhaps because of chained non combat and combat not being counted as 1, there is one such chain in The Hidden Office Building but I never took that choice testing this
I'll try those out. You are referring to the "choice leads to a fight" cases, right?
 
I'll try those out. You are referring to the "choice leads to a fight" cases, right?
Yes though in haunted bedroom I noticed higher turns_spent than expected without ever using the choice that leads to a fight (879/3) so perhaps "fight leads to a choice" cases too. Will get debug log in next hidden city
 

Veracity

Developer
Staff member
I have tests - with saved HTML responses texts - for The Haunted Bedroom for both the "fight -> choice -> fight" case and for the "fight -> choice" case. The last one fails. Which means I can work on fixing it. :)

I also have a multi who does not have a beehive - so I can get DEBUG logging for getting one.
Getting DEBUG logs for other choice chains - Spooky Forest ending in spending a turn, as well as Spooky Forest ending in NOT spending a turn - should also be easy.

I think I'll start a draft PR to track this.
 

Veracity

Developer
Staff member
Looking at history, lost implemented this in 2014 in commit 14778:


I want to understand the current intent of this, considering the following:

- fights can be wins, losses, or runaways.
- any of the above can be free (0 turns), 1 turn (non sea or sea with Fishy or free in sea without fishy) or 2 turns (sea without Fishy).

I think all of the above add 1 to turns_spent. Auto-killing lianas with a machete still increment turns in the zone. We used to have code that depended on that.

What about NCs? Some are not choices - and we have no code to increment turns_spent.

Choices? We have code to increment turns_spent iff the choice takes a turn.

What if a choice doesn’t take a turn? Choice chains (like Spooky Forest) often take a single turn. Some, however, take a turn for each choice.

Do we want turns_spent to increment for each actual turn spent? Does a three turn choice chain burn 3 turns of delay?

How about a 0-turn choice chain? Spooky Forest has one path that provides that. Does that increment turns_spent?

How about The Gourd? That can be one really long sequence of mixed choices and fights. Last time I checked, we will automate the whole thing with a single visit. What should turns_spent be after doing that?

I can make tests using saved HTML response texts, but I need to understand expectations before writing the test assertions.
 
I think the intent is to reflect what KOL counts as turns spent for delay
- fights always count at least if they end in some way, not sure about rollover runaway
- choices count only if they took at least a turn, multi choice chains count every step that took at least a turn

In The Penultimate Fantasy Airship I noticed one instance of the choice->fight chain (Encounter: Random Lack of an Encounter Took choice 182/1: enter combat) incremented turns_spent by 2 instead of 1. Several other instances of this chain before that one only incremented turns_spent by 1, same ascension same location same choice.

In The Hidden Temple the chain of 3 choices (Encounter: At Least It's Not Full Of Trash + Encounter: Beginning at the Beginning of Beginning + Encounter: No Visible Means of Support) incremented turns_spent by 2 instead of 3 though accuracy there probably does not matter to anyone or any script since this location has no delay mechanics

Sending you hidden city debug log for the turn that autocrafts boring binder clip in scripted adventuring. Thanks!
 

Ryo_Sangnoir

Developer
Staff member
- fights always count at least if they end in some way, not sure about rollover runaway
Fights count if they end with you beating the monster, the monster beating you, or you running away.

Fights don't count if they end with you using the force with your Saber (unless that changed), using Macrometeorite (or other equivalent) to change the monster into a different monster, or I think by undying as Ed (i.e. a monster where you undied three times counts as 1, not 3).
 

Veracity

Developer
Staff member
In The Hidden Temple the chain of 3 choices (Encounter: At Least It's Not Full Of Trash + Encounter: Beginning at the Beginning of Beginning + Encounter: No Visible Means of Support) incremented turns_spent by 2 instead of 3 though accuracy there probably does not matter to anyone or any script since this location has no delay mechanics
I would guess this is because the second challenge is tiles.php, not a choice.
I'm sort of a stickler for wanting things to be "right", so I'd fix it if I had a DEBUG log for the whole chain of encounters, but, not critical.
 

Veracity

Developer
Staff member
I have a failing test for the 3-turn beehive choice chain; it does not increment turns each step along the way - even though charpane refreshes indicate turns are being spent - and only increments by one at the end of all three turns spent.
 

Veracity

Developer
Staff member
The following PR should fix these issues:

1) When autoCrafting kicks in at the end of a choice, that choice now counts up turns_spent
2) When a fight leads to a choice (in the Haunted Bedroom), turns_spent increments immediately after the fight and the choice does not count as a spent turn
3) When a choice chain takes multiple turns, turns_spent increments immediately after each such turn.

I was unable to find an issue in the Penultimate Fantasy Airship. That is a choice -> fight thing, which also works in the Haunted Bedroom in the fight -> choice -> fight case, which (correctly) takes two turns.

I didn't do anything for the Hidden Temple, but that is probably as simple as treating the "tiles.php" puzzle as a non-combat.
Could be a trivial fix, but I'd like to see a DEBUG log for the Hidden Temple, all the way from entering the choice where you choose the door to all the way through the 3-adventures you spent.

 
I could not reproduce with log in the Penultimate Fantasy Airship so far. Sending Hidden Temple

Fights don't count if they end with you using the force with your Saber (unless that changed), using Macrometeorite (or other equivalent) to change the monster into a different monster
if we call before and after changing monster A into monster B two different fights then the fight with monster A doesn't count for delay but finishing the fight with monster B does, at least when the change is Back-Up to your Last Enemy
 

Veracity

Developer
Staff member
I updated my PR with the 28 (!) requests involved in going through the Hidden Temple to open the Hidden City.
I fixed the issues and turns_spent now goes up by 3 when you do that.
 

Veracity

Developer
Staff member
Fights don't count if they end with you using the force with your Saber (unless that changed), using Macrometeorite (or other equivalent) to change the monster into a different monster, or I think by undying as Ed (i.e. a monster where you undied three times counts as 1, not 3).
I see this in AdventureSpentDatabase.addTurn:

Code:
  public static void addTurn(KoLAdventure adv) {
    if (FightRequest.edFightInProgress()) {
      return;
    }
    String name = adv.getAdventureName();
    AdventureSpentDatabase.addTurn(name);
  }

So, the Ed case should be covered.

"Use the Force" is done via choice adventure #1387. I would expect that to be handled by current choice adventure processing. I.e., if the response text requests a charpane reset, we'll set the flag saying to check if a turn has advanced.

Note that SaberRequest.parseForce says this:

Code:
    // Eventually try to reduce delay in the last adventured area, and remove the
    // last monster from the queue.  Not reducing delay when the fight didn't come
    // from a location will likely be non-trivial.

I'll try out the backup camera today and get a DEBUG log.

One way or another, I'll that to the AdventureSpentDatabaseTest suite.

Heck. I'll get a DEBUG log for Use the Force, too.
 

Veracity

Developer
Staff member
Code:
> ash $location[ The Orcish Frat House (Bombed Back to the Stone Age) ].turns_spent

Returned: 4

[28189] The Orcish Frat House (Bombed Back to the Stone Age)
Encounter: caveman frat boy
Round 0: Veracity wins initiative!
...
Round 3: Veracity wins the fight!

> ash $location[ The Orcish Frat House (Bombed Back to the Stone Age) ].turns_spent

Returned: 5

[28190] The Orcish Frat House (Bombed Back to the Stone Age)
Encounter: caveman sorority girl
Round 0: Veracity wins initiative!
Round 1: Veracity tries to steal an item!
Round 2: Veracity casts BACK-UP TO YOUR LAST ENEMY!
Round 3: your opponent becomes a caveman frat boy!

> ash $location[ The Orcish Frat House (Bombed Back to the Stone Age) ].turns_spent

Returned: 5
Round 3: Veracity attacks!
Round 4: caveman frat boy takes 4215 damage.
Round 4: Veracity wins the fight!

> ash $location[ The Orcish Frat House (Bombed Back to the Stone Age) ].turns_spent

Returned: 6

[28191] The Orcish Frat House (Bombed Back to the Stone Age)
Encounter: caveman frat pledge
Round 0: Veracity wins initiative!
Round 1: Veracity tries to steal an item!
Round 2: Veracity casts USE THE FORCE!
Encounter: Using the Force
You acquire an item: cup of primitive beer
You acquire an item: stone baseball cap
You acquire an item: ovoid leather thing
You acquire an item: chunk of rock salt

> ash $location[ The Orcish Frat House (Bombed Back to the Stone Age) ].turns_spent

Returned: 6
Changing an enemy to another monster is not "a different fight".

Here are all the requests submitted:

(Fight #1)
(turns_spent = 4)
Code:
adventure.php?snarfblat=150
redirect: fight.php?ireallymeanit=1653074727

charpane.php
var turnsplayed = 1884931;
var turnsthisrun = 28188;

fight.php?action=steal
fight.php?action=attack

charpane.php
var turnsplayed = 1884932;
var turnsthisrun = 28189;
(turns_spent=5)

(Fight #2)
Code:
adventure.php?snarfblat=150
redirect: fight.php?ireallymeanit=1653074806

charpane.php
var turnsplayed = 1884932;
var turnsthisrun = 28189;

fight.php?action=steal
fight.php?action=skill&whichskill=7381

charpane.php
var turnsplayed = 1884932;
var turnsthisrun = 28189;
Backup camera changed monster.
Middle of (same) fight:
(turns_spent=5)

Code:
fight.php?action=attack

charpane.php
var turnsplayed = 1884933;
var turnsthisrun = 28190;
(turns_spent=6)

(Fight #3)
Code:
adventure.php?snarfblat=150
redirect: fight.php?ireallymeanit=1653074910

charpane.php
var turnsplayed = 1884933;
var turnsthisrun = 28190;

fight.php?action=steal

charpane.php
var turnsplayed = 1884933;
var turnsthisrun = 28190;

fight.php?action=skill&whichskill=7311
redirect: choice.php?forceoption=0

charpane.php
var turnsplayed = 1884933;
var turnsthisrun = 28190;

choice.php?pwd&whichchoice=1387&option=3
Use the Force and NO charpane request.
(turns_spent=6)

I forced a refresh in the browser:

Code:
charpane.php

var turnsplayed = 1884933;
var turnsthisrun = 28190;
(turns spent=6)
 

Veracity

Developer
Staff member
As far as I can tell, this is fixed.

PFA choice -> fight is not reproducible. I was never able to see an error.
 
Top