Skip to content

Commit

Permalink
Examine the choice buttons of the Tomb of the Unknown Your Class Here do
Browse files Browse the repository at this point in the history
detrmine which is the correct answer to the riddle. Provide spoilers.


git-svn-id: http://svn.code.sf.net/p/kolmafia/code@15936 b29ace70-8910-0410-8dcc-aa2fc6433167
  • Loading branch information
Veracity0 committed Jun 13, 2015
1 parent 0f0a483 commit b2c6370
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 38 deletions.
79 changes: 79 additions & 0 deletions src/net/sourceforge/kolmafia/session/ChoiceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -4267,6 +4269,10 @@ private static final Object[][] dynamicChoiceSpoilers( final int choice )
case 988:
// The Containment Unit
return ChoiceManager.dynamicChoiceSpoilers( choice, "The Containment Unit" );

case 1049:
// Tomb of the Unknown Your Class Here
return ChoiceManager.dynamicChoiceSpoilers( choice, "Tomb of the Unknown Your Class Here" );
}

return null;
Expand Down Expand Up @@ -5899,6 +5905,33 @@ else if ( containment.charAt( progress ) == 'R' )
result[ 1 ] = "unknown";
}
return result;

case 1049:
{
// Tomb of the Unknown Your Class Here

String responseText = ChoiceManager.lastResponseText;
TreeMap<Integer,String> choices = ChoiceCommand.parseChoices( responseText );
int options = choices.size();
if ( options == 1 )
{
return null;
}

int decision = ChoiceManager.getDecision( choice, responseText );
if ( decision == 0 )
{
return null;
}

result = new String[ options ];
for ( int i = 0; i < options; ++i )
{
result[ i ] = ( i == decision - 1 ) ? "right answer" : "wrong answer";
}

return result;
}
}
return null;
}
Expand Down Expand Up @@ -10987,6 +11020,52 @@ private static final String specialChoiceDecision1( final int choice, String dec
}

return decision;

case 1049:
{
// Tomb of the Unknown Your Class Here

// This handles every choice in the "The Unknown Tomb"
// Many of them have a single option.
TreeMap<Integer,String> choices = ChoiceCommand.parseChoices( responseText );
if ( choices.size() == 1 )
{
return "1";
}

// The only one that has more than one option is the initial riddle.
// The option numbers are randomized each time, although the correct
// answer remains the same.
String myClass = KoLCharacter.getClassType();
String answer =
myClass == KoLCharacter.SEAL_CLUBBER ? "Boredom." :
myClass == KoLCharacter.TURTLE_TAMER ? "Friendship." :
myClass == KoLCharacter.PASTAMANCER ? "Binding pasta thralls." :
myClass == KoLCharacter.SAUCEROR ? "Power." :
myClass == KoLCharacter.DISCO_BANDIT ? "Me. Duh." :
myClass == KoLCharacter.ACCORDION_THIEF ? "Music." :
null;

// Only standard classes can join the guild, so we
// should not fail. But, if we do, cope.
if ( answer == null )
{
return "0";
}

// Iterate over the option strings and find the one
// that matches the correct answer.
for ( Map.Entry<Integer,String> entry : choices.entrySet() )
{
if ( entry.getValue().contains( answer ) )
{
return String.valueOf( entry.getKey() );
}
}

// Again, we should not fail, but cope.
return "0";
}
}

return decision;
Expand Down
94 changes: 64 additions & 30 deletions src/net/sourceforge/kolmafia/textui/command/ChoiceCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

package net.sourceforge.kolmafia.textui.command;

import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;

Expand Down Expand Up @@ -80,20 +79,18 @@ public void run( final String cmd, String parameters )
parameters = parameters.substring( 0, parameters.length() - 7 ).trim();
}
int decision = 0;
TreeMap choices = ChoiceCommand.parseChoices( true );
TreeMap<Integer,String> choices = ChoiceCommand.parseChoices( true );
if ( StringUtilities.isNumeric( parameters ) )
{
decision = StringUtilities.parseInt( parameters );
}
else
{
Iterator i = choices.entrySet().iterator();
while ( i.hasNext() )
for ( Map.Entry<Integer,String> entry : choices.entrySet() )
{
Map.Entry e = (Map.Entry) i.next();
if ( ((String) e.getValue()).toLowerCase().indexOf( parameters.toLowerCase() ) != -1 )
if ( entry.getValue().toLowerCase().indexOf( parameters.toLowerCase() ) != -1 )
{
decision = ((Integer) e.getKey()).intValue();
decision = entry.getKey().intValue();
break;
}
}
Expand All @@ -118,14 +115,58 @@ public void run( final String cmd, String parameters )
private static final Pattern OPTION_PATTERN = Pattern.compile( "<form(?=.*?name=option value=(\\d+)).*?class=button.*?value=\"([^\"]+)\".*?</form>", Pattern.DOTALL );
private static final Pattern LINK_PATTERN = Pattern.compile( "choice.php\\?whichchoice=\\d+&option=(\\d+)" );

public static TreeMap parseChoices( final boolean spoilers )
public static TreeMap<Integer,String> parseChoices( final String responseText )
{
TreeMap rv = new TreeMap();
if ( !ChoiceManager.handlingChoice || ChoiceManager.lastResponseText == null )
TreeMap<Integer,String> rv = new TreeMap<Integer,String>();
if ( responseText == null )
{
return rv;
}

Matcher m = OPTION_PATTERN.matcher( responseText );
while ( m.find() )
{
int decision = Integer.parseInt( m.group( 1 ) );
Integer key = IntegerPool.get( decision );
if ( rv.get( key ) != null )
{
continue;
}
String text = m.group( 2 );
rv.put( key, text );
}

m = LINK_PATTERN.matcher( responseText );
while ( m.find() )
{
int decision = Integer.parseInt( m.group( 1 ) );
Integer key = IntegerPool.get( decision );
if ( rv.get( key ) != null )
{
continue;
}
String text = "(secret choice)";
rv.put( key, text );
}

return rv;
}

public static TreeMap<Integer,String> parseChoices( final boolean spoilers )
{
TreeMap<Integer,String> rv = new TreeMap<Integer,String>();
String responseText = ChoiceManager.lastResponseText;

if ( !ChoiceManager.handlingChoice || responseText == null )
{
return rv;
}

if ( !spoilers )
{
return ChoiceCommand.parseChoices( responseText );
}

int choice = ChoiceManager.currentChoice();
Object[][] possibleDecisions = ChoiceManager.choiceSpoilers( choice );
if ( possibleDecisions == null )
Expand All @@ -134,13 +175,13 @@ public static TreeMap parseChoices( final boolean spoilers )
}
Object[] options = possibleDecisions[ 2 ];

Matcher m = OPTION_PATTERN.matcher( ChoiceManager.lastResponseText );
Matcher m = OPTION_PATTERN.matcher( responseText );
while ( m.find() )
{
int decision = Integer.parseInt( m.group( 1 ) );
Integer key = IntegerPool.get( decision );
String text = m.group( 2 );
if ( spoilers )
if ( options != null )
{
Object option = ChoiceManager.findOption( options, decision );
if ( option != null )
Expand All @@ -151,7 +192,7 @@ public static TreeMap parseChoices( final boolean spoilers )
rv.put( key, text );
}

m = LINK_PATTERN.matcher( ChoiceManager.lastResponseText );
m = LINK_PATTERN.matcher( responseText );
while ( m.find() )
{
int decision = Integer.parseInt( m.group( 1 ) );
Expand All @@ -161,13 +202,10 @@ public static TreeMap parseChoices( final boolean spoilers )
continue;
}
String text = "(secret choice)";
if ( spoilers )
Object option = ChoiceManager.findOption( options, decision );
if ( option != null )
{
Object option = ChoiceManager.findOption( options, decision );
if ( option != null )
{
text = text + " (" + option.toString() + ")";
}
text = text + " (" + option.toString() + ")";
}
rv.put( key, text );
}
Expand Down Expand Up @@ -214,25 +252,21 @@ public static String actionOption( final String action, final String responseTex

public static void printChoices()
{
TreeMap choices = ChoiceCommand.parseChoices( true );
Iterator i = choices.entrySet().iterator();
while ( i.hasNext() )
TreeMap<Integer,String> choices = ChoiceCommand.parseChoices( true );
for ( Map.Entry<Integer,String> entry : choices.entrySet() )
{
Map.Entry e = (Map.Entry) i.next();
RequestLogger.printLine( "<b>choice " + e.getKey() + "</b>: " + e.getValue() );
RequestLogger.printLine( "<b>choice " + entry.getKey() + "</b>: " + entry.getValue() );
}
}

public static void logChoices()
{
TreeMap choices = ChoiceCommand.parseChoices( true );
Iterator i = choices.entrySet().iterator();
int choice = ChoiceManager.currentChoice();
while ( i.hasNext() )
TreeMap<Integer,String> choices = ChoiceCommand.parseChoices( true );
for ( Map.Entry<Integer,String> entry : choices.entrySet() )
{
Map.Entry e = (Map.Entry) i.next();
RequestLogger.updateSessionLog( "choice " + choice + "/" + e.getKey() + ": " + e.getValue() );
RequestLogger.printLine( "<b>choice " + e.getKey() + "</b>: " + e.getValue() );
RequestLogger.updateSessionLog( "choice " + choice + "/" + entry.getKey() + ": " + entry.getValue() );
RequestLogger.printLine( "<b>choice " + entry.getKey() + "</b>: " + entry.getValue() );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ public void run( final String cmd, final String parameters )
ChoiceManager.handlingChoice = true;
ChoiceManager.lastChoice = choice;
TestCommand.contents = null;
RequestLogger.printLine( "default decision = " + ChoiceManager.getDecision( choice, ChoiceManager.lastResponseText ) );
ChoiceCommand.printChoices();
}
finally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
package net.sourceforge.kolmafia.webui;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;

Expand Down Expand Up @@ -589,21 +588,18 @@ public static final void addChoiceButtons( final StringBuffer buffer )
int choice = ChoiceManager.currentChoice();
if ( choice != 0 )
{
TreeMap choices = ChoiceCommand.parseChoices( false );
Iterator i = choices.entrySet().iterator();
StringBuilder actionBuffer = new StringBuilder();
while ( i.hasNext() )
TreeMap<Integer,String> choices = ChoiceCommand.parseChoices( false );
for ( Map.Entry<Integer,String> entry : choices.entrySet() )
{
Map.Entry e = (Map.Entry) i.next();
name = (String) e.getValue();
actionBuffer.setLength( 0 );
actionBuffer.append( "choice.php?whichchoice=" );
actionBuffer.append( choice );
actionBuffer.append( "&option=" );
actionBuffer.append( ((Integer) e.getKey()).intValue() );
actionBuffer.append( entry.getKey().intValue() );
actionBuffer.append( "&pwd=" );
actionBuffer.append( GenericRequest.passwordHash );
StationaryButtonDecorator.addButton( buffer, name, actionBuffer.toString(), true, false );
StationaryButtonDecorator.addButton( buffer, entry.getValue(), actionBuffer.toString(), true, false );
}
}
}
Expand Down

0 comments on commit b2c6370

Please sign in to comment.