Bug - Fixed Hedge maze solver fails

psly4mne

Member
The hedge maze solver occasionally fails to get the key and spends extra turns. I'm sorry I can't be more detailed, because if I'm paying attention I generally do the maze by hand. I think what happens is this: mafia solves the path to the key, but the puzzle gets stolen on the last turn. Then mafia adventures in the maze, thinking it's getting the key but actually fighting a golem. Then it solves the path to the tower without having picked up the key, and gets into a weird state. I could be wrong about what is happening, but something is definitely going wrong.
 

Veracity

Developer
Staff member
What do you mean by "the hedge maze solver"?

Here is what I do:

- I adventure in the Hedge Maze and fight a golem
- I click on the "maze" link of the puzzle
- I click on the Solve button
- If the puzzle gets stolen, go back to step one
- Otherwise, I am done

That works every time with the minimal number of turns required.

Obviously, you are doing something different. I assume you are using Hedge Rotation in the Quests menu, or, perhaps, the "hedge" or "maze" command in the gCLI. Do you start by farming up multiple puzzles? What exactly do you do?
 

Winterbay

Active member
The one time this has happened to me (one time only so never bothered reporting it) was with BCA which gets one puzzle-piece calls "maze" on it and goes on like that until the tower is open. It is very possible that in my case it was BCA not having enough sanity checking on what it was doing and that a situation like the one proposed above occurred.
 

psly4mne

Member
What do you mean by "the hedge maze solver"?

Here is what I do:

- I adventure in the Hedge Maze and fight a golem
- I click on the "maze" link of the puzzle
- I click on the Solve button
- If the puzzle gets stolen, go back to step one
- Otherwise, I am done

That works every time with the minimal number of turns required.

Obviously, you are doing something different. I assume you are using Hedge Rotation in the Quests menu, or, perhaps, the "hedge" or "maze" command in the gCLI. Do you start by farming up multiple puzzles? What exactly do you do?
That is exactly what I do, and it usually works perfectly. It is possible I farmed two hedge puzzles before clicking Solve this time.
 
In very loose sense, I can "confirm" the initial report. Loose, since it would happen too frequently so I just started doing the maze manually a while back. And yes, for me at least, it was happening when using hedge rotation from the quest menu, after arriving at the courtyard, and with no initial farming of puzzles.

I didn't spend much time trying to determine the conditions under which this occurred, and once it seemed to get into that state, re-selecting the menu item again just repeated the same thing. And yet, sometimes it worked. I was frustrated with losing turns so I just said screw it, and moved on.

Edit: I could try digging through old logs. Was several months back last time I ran into this.
 

Crowther

Active member
I normally use the CLI and type "adv 1 hedge;hedgemaze", then I repeat that until I get they key. I've never had it get into a weird state.

EDIT: I don't let BCA handle that section.
 

Bale

Minion
I've come to a conclusion about this "bug." It does exist however I'm not convinced it is a mafia bug. My long lack of comment on this issue is that I have coped with it by simply doing the maze manually when I cared about turncount.

I believe it is caused (somehow) by relay_Guide polling KoLmafia's state. I almost always have Guide open in my relay browser and the bug usually happens to me. Twice now, I did not have Guide open (this is RARE) and on both occasions Mafia's solver for this worked perfectly. Obviously this is far from conclusive.

Someone needs to turn on debug logging while Guide is active and wait for this to happen.
 

Theraze

Active member
I had it happen once ~2 years ago, before ever using Guide.

I had it happen last week, since starting to use Guide a month or so ago.

But it's not a common bug. It just seems like something is messing up mafia's awareness of how it's supposed to turn the maze. I believe in both cases it happened after mafia timed out due to bad wifi during the maze solver. Some sort of checking on the current maze state would probably be good, or a way to tell mafia that its version of the maze is apparently wrong.
 

Nappa

Member
I just had it happen as well (relay browser). Never ran into any problems with the solver before. Also running the guide script since a week or so.
 

Bale

Minion
I tried to capture a debug log on my last trip through the Hedge maze, but it didn't fail at all for me. :(
 

Magus_Prime

Well-known member
This morning, with r14664, I tried to use the solver, via the Hedge Rotation choice under the Quests menu in the GUI, and the following happened:

Code:
Retrieving maze status...
Computing maze solution...
Retrieving hedge key...
Rotate the Upper-Left tile of the hedge maze puzzle
Rotate the Lower-Left tile of the hedge maze puzzle
Rotate the Lower-Left tile of the hedge maze puzzle
Rotate the Lower-Middle tile of the hedge maze puzzle
Rotate the Upper-Right tile of the hedge maze puzzle

[1072] Sorceress' Hedge Maze
You acquire an item: hedge maze key
Retrieving maze status...
Computing maze solution...
Executing final rotations...
Rotate the Upper-Middle tile of the hedge maze puzzle
Rotate the Lower-Middle tile of the hedge maze puzzle
Rotate the Lower-Middle tile of the hedge maze puzzle
Rotate the Lower-Middle tile of the hedge maze puzzle
Ran out of puzzle pieces.

[1073] Sorceress' Hedge Maze
Encounter: topiary golem
Round 0: Arbos wins initiative!
Hedge maze quest complete.
KoLmafia thinks it is round 2 but KoL thinks it is round 1

This hasn't happened in a long time so I didn't have debug running.
 
Last edited:

Bale

Minion
Without a debug log it seems pointless to post about it. I've tried to catch it to no avail.
 

Magus_Prime

Well-known member
I know. The only reason I posted is because of something I hadn't seen before: that the solver seems to "think" it completed the puzzle mid-combat.
 

Nappa

Member
My current run was reaching its conclusion so I decided to attempt to catch the behavior in a log, and yes, the solver failed. Maybe someone can use this info to analyze this further?

Running r14684, active 'Guide' script, Firefox 32.0.2.

What I did (I bracketed the approximate line numbers according to the debug.txt).

[88] First I manually adventured (in relay browser) at the hedge maze and acquired 1 puzzle. After the fight [371] I clicked the 'maze' link to open the maze page, and subsequently [432] clicked the 'Solve' button to fire the hedge maze solver. After a few seconds it stopped and loaded a fight (with a topiary golem) into the relay browser.

From what I can gather, it ran out of puzzle pieces in line 474. But it seems it attempted to adventure in the maze again [507], leading to a fight with a golem and failing the solver [623].

If I remember correctly, the solver would (should?) halt upon running out of puzzle pieces, at least previously I always had to manually fight another golem to retrieve a new puzzle.
 

Attachments

  • DEBUG_20140922.txt
    450.8 KB · Views: 23

Veracity

Developer
Staff member
Interesting DEBUG log. Here is the "processResults" method for HedgePuzzleRequest.

Code:
	public void processResults()
	{
		HedgePuzzleRequest.parseResponse( this.getURLString(), this.responseText );
		if ( HedgePuzzleRequest.PUZZLE_PIECE.getCount( KoLConstants.inventory ) == 0 )
		{
			KoLmafia.updateDisplay( MafiaState.ERROR, "Ran out of puzzle pieces." );
			return;
		}
	}
In other words, after every puzzle rotation, it checks to see if you have a puzzle piece in inventory. If not, it prints a message and goes into an ERROR state.

The whole hedge script is full of this kind of check:

Code:
		if ( !KoLmafia.permitsContinue() )
		{
			return;
		}
In other words, if KoLmafia does not "permit continue" - is in an ERROR state - it bails.

Now lets look at what your log said when you lost that puzzle:

Code:
Processing result: hedge maze puzzle (-1)
Ran out of puzzle pieces.
We noticed you lost the puzzle and had none left, so at this point, we were in an ERROR state. Next:

Code:
class net.sourceforge.kolmafia.request.ApiRequest
Connecting to api.php...

Requesting: http://www.kingdomofloathing.com/api.php?what=status&for=KoLmafia
3 request properties
Field: Cookie = [appserver=www8; PHPSESSID=hc9k8ejt4k6mejeqsgehnt3822]
Field: User-Agent = [KoLmafia v16.4]
Field: Content-Type = [application/x-www-form-urlencoded]

Retrieving server reply...
Starting relay script: relay_Guide.ash
Finished relay script: relay_Guide.ash
Ooh, look at that. We executed a relay script. Since scripts don't/can't run in an ERROR state, we clear it.

And so, Guide finishes, we are no longer in an ERROR state, and the script continues merrily along, "knowing" that it is still working on the puzzle since, after all, we'd be in an ERROR state if you didn't have a puzzle any more.

I only saw Guide start/finish 187 times in your DEBUG log.

I am not surprised in the slightest that the Hedge solver fails for people using an asynchronous relay script. In order to fix it, it would need to maintain its own state variable, rather than depending on KoLmafia's ERROR state.

All of the built-in Sorceress Lair scripts are chock full of "KoLmafia.permitsContinue()" checks and will almost certainly not detect failures correctly for people running Guide.
 

Veracity

Developer
Staff member
Revision 14689 Guide-proofs the volcano maze solver - yes, not the hedge maze solver, but it was an easier proof of concept. :)

Previously, we had

Code:
		VolcanoMazeManager.discoverMaps();
		if ( !KoLmafia.permitsContinue() )
 		{
 			return;
 		}
and now we have:

Code:
		if ( !VolcanoMazeManager.discoverMaps() )
 		{
 			return;
 		}
where discoverMaps() returns true if it succeeded and false in exactly the places that it also sets the state to ERROR (which it still does, since that makes the GUI red, which was part of the point...)

It would be a bigger job to do the equivalent for the Hedge Maze solver, but it would Guide-proof it and hopefully fix this issue.
 

Nappa

Member
Ooh, look at that. We executed a relay script. Since scripts don't/can't run in an ERROR state, we clear it.

And so, Guide finishes, we are no longer in an ERROR state, and the script continues merrily along, "knowing" that it is still working on the puzzle since, after all, we'd be in an ERROR state if you didn't have a puzzle any more.

[..]

I am not surprised in the slightest that the Hedge solver fails for people using an asynchronous relay script. In order to fix it, it would need to maintain its own state variable, rather than depending on KoLmafia's ERROR state.
Nice catch!

Sounds like it could have been a case of divergence over time (but I'm speculating here). Where, at the time of writing the solver code, this would not have been possible, but in the course of years the error state/feature has evolved or changed, or other code was introduced that infuenced its behaviour. The hedge maze has been around ever since NS11 iirc, so I guess the script has been around for a long time as well.
 

Veracity

Developer
Staff member
What changed was the invention of Relay Scripts.

Originally, there was nothing but the GUI, and everything was sequential and the "continuation state" never changed out from under you.

Then, we added the Relay Browser, and asynchrony became possible: the browser can initiate requests as the same time as things are running in the GUI. We took care (I believe) to make sure that code executed in response to RelayRequests did not modify the continuation state; the run() and processResult() methods of internal request classes would set that, but requests from the browser were executed in RelayRequests and were external.

Then we added Relay Scripts and suddenly we had ASH making internal requests in response to browser events and everything changed: the GUI and a Relay Script could be operating simultaneously in different threads and both could modify the continuation simultaneously in different threads. I recall adding the code to force the continuation state to CONTINUE before executing a relay script, since otherwise the script was not guaranteed to execute correctly.

Nothing, however, was done to make the GUI rely less on the continuation state; all over the place, we still rely on it being set to the result of the last operation we executed. And we've gotten along pretty well; when the browser calls something in KoLmafia - like the "Solve" button on the hedge maze, for example - the browser is not doing anything else.

Guide takes things to a whole new level. It executes asynchronously - hundreds of times a minute, apparently. I would expect that starting Guide in the middle of any of number of built-in things which currently depend on the continuation state to detect errors will cause problems. Hedge puzzle, the "buy" command (KoLmafia.makePurchases has a loop in which "KoLmafia.permitsContinue()" is one of the continue conditions ... ) and on and on.

I'll fix the hedge puzzle solver and will look at the other sorceress lair scripts, but Guide-proofing the rest of KoLmafia will be a big project, I think.
 

Veracity

Developer
Staff member
I think a new thread - is it s Bug or simply a Discussion? - with the last few responses copied into it would be a good idea.

roippi edit: done

Regarding the hedge maze solver, I have modified it to not depend on the continuationState, but I figured I should at least try it once, so testing & submitting will have to wait until tomorrow. I'll use the Solve button in the relay browser. (I suppose trying it again via the script from the menu after farming up several hedge puzzles would also be good, just to make sure we can still do that correctly, but that will have to wait until next run.)
 
Last edited by a moderator:

Veracity

Developer
Staff member
Revision 14694 Guide-proofs the hedge maze solver. I tried it by farming up 2 puzzles, executing the script from the menu bar - and it correctly stopped when the second topiary golem stole the second puzzle - then farming up two more puzzles and doing the same thing. Unexpectedly, only one more topiary golem appeared, so it completed the quest and unlocked the gate to the tower.

I confirmed that the script still works, but I don't run Guide, so I didn't actually test that the script is no longer disrupted by that script. I'll leave that for you-all to test. :)
 
Top