Page 7 of 8 FirstFirst ... 5 6 7 8 LastLast
Results 61 to 70 of 80

Thread: Rethinking Candy

  1. #61
    Developer Veracity's Avatar
    Join Date
    Mar 2006
    Location
    The Unseelie Court
    Posts
    11,001

    Default

    Thanks.

    First I gave ASH all the info about candies.
    Then I gave it access to the internal methods that the GUI frame uses to display its candy lists.
    Then I gave it access to the internal methods I wrote today to pick a pair of candies.
    Finally, I gave you a function to use if/when you decide that you trust those algorithms.

    You might be amused by the Java code for the two algorithms.

    This is the one that picks a pair of candies, favoring the most numerous in inventory:

    Code:
    	private static Candy[] synthesisPairByCount( final int effectId, final int flags )
    	{
    		int tier = CandyDatabase.getEffectTier( effectId );
    
    		List<Candy> candy1List = CandyDatabase.itemIdSetToCandyList( CandyDatabase.candyForTier( tier, flags ) );
    		Collections.sort( candy1List, INVERSE_COUNT_COMPARATOR );
    
    		for ( Candy candy : candy1List )
    		{
    			if ( candy.getCount() == 0 )
    			{
    				// Ran out of available candies
    				return NO_PAIR;
    			}
    
    			int itemId = candy.getItemId();
    			List<Candy> candy2List = CandyDatabase.itemIdSetToCandyList( CandyDatabase.sweetSynthesisPairing( effectId, itemId, flags ) );
    			Collections.sort( candy2List, INVERSE_COUNT_COMPARATOR );
    
    			for ( Candy pairing : candy2List )
    			{
    				int count = pairing.getCount();
    				if ( count == 0 )
    				{
    					// Nothing left in this list. Select a new candy1
    					break;
    				}
    				
    				if ( candy.equals( pairing ) && count == 1 )
    				{
    					// Pairs with itself but only have one.
    					continue;
    				}
    
    				Candy[] result = new Candy[2];
    				result[0] = candy;
    				result[1] = pairing;
    				return result;
    			}
    		}
    
    		return NO_PAIR;
    	}
    This is the one that favors the cheapest total mall price for the two candies:

    Code:
    	private static Candy[] synthesisPairByCost( final int effectId, final int flags )
    	{
    		int tier = CandyDatabase.getEffectTier( effectId );
    
    		int bestCost = Integer.MAX_VALUE;
    		Candy candy1 = null;
    		Candy candy2 = null;
    
    		List<Candy> candy1List = CandyDatabase.itemIdSetToCandyList( CandyDatabase.candyForTier( tier, flags ) );
    		Collections.sort( candy1List, MALL_PRICE_COMPARATOR );
    
    		for ( Candy candy : candy1List )
    		{
    			int cost1 = candy.getCost();
    			if ( cost1 > bestCost )
    			{
    				break;
    			}
    
    			int itemId = candy.getItemId();
    			List<Candy> candy2List = CandyDatabase.itemIdSetToCandyList( CandyDatabase.sweetSynthesisPairing( effectId, itemId, flags ) );
    			Collections.sort( candy2List, MALL_PRICE_COMPARATOR );
    
    			for ( Candy pairing : candy2List )
    			{
    				int cost2 = pairing.getCost();
    				int currentCost = cost1 + cost2;
    
    				if ( currentCost >= bestCost )
    				{
    					break;
    				}
    
    				candy1 = candy;
    				candy2 = pairing;
    				bestCost = currentCost;
    			}
    		}
    
    		if ( candy1 == null || candy2 == null )
    		{
    			return NO_PAIR;
    		}
    
    		Candy[] result = new Candy[2];
    		result[0] = candy1;
    		result[1] = candy2;
    
    		return result;
    	}
    I say you might be amused because you could just about translate those directly in to ASH, since I exposed the same internal Candy functions to ASH.

    Code:
    		List<Candy> candy1List = CandyDatabase.itemIdSetToCandyList( CandyDatabase.candyForTier( tier, flags ) );
    		Collections.sort( candy1List, INVERSE_COUNT_COMPARATOR );
    is essentially

    Code:
    item [int] list = candy_for_tier( tier, flag );
    sort list by -available_amount( value );
    and

    Code:
    			List<Candy> candy2List = CandyDatabase.itemIdSetToCandyList( CandyDatabase.sweetSynthesisPairing( effectId, itemId, flags ) );
    			Collections.sort( candy2List, INVERSE_COUNT_COMPARATOR );
    is essentially

    Code:
    item[ int] list = sweet_synthesis_pairing( effect, item, flags );
    sort list by -available_amount( value );
    Ph'nglui mglw'nafh Cthulhu
    R'lyeh wgah-nagl fhtagn.

  2. #62
    Minion Bale's Avatar
    Join Date
    Jun 2008
    Posts
    13,244

    Default

    Interesting! Basically, the whole process with all those functions being made available to ash one-by-one was just a matter of exposing the functions as you were writing them so that you could solve the problem of automation in java. Thanks for the peek inside.

    Rather neat that you did it the same way I'd program in ash.

  3. #63
    Developer Veracity's Avatar
    Join Date
    Mar 2006
    Location
    The Unseelie Court
    Posts
    11,001

    Default

    Revision 17647 does this:

    Code:
    > synthesize? greed
    
    Item 'Milk Studs' is a complex candy. You have 246 available to you without using the mall, where it costs 100 Meat.
    Item 'sterno-flavored Hob-O' is a complex candy. You have 12 available to you without using the mall, where it costs 235 Meat.
    Synthesizing those two candies will give you 30 turns of Synthesis: Greed (Meat +300%)
    
    > synthesize? Milk Studs, sterno-flavored Hob-O
    
    Item 'Milk Studs' is a complex candy. You have 246 available to you without using the mall, where it costs 100 Meat.
    Item 'sterno-flavored Hob-O' is a complex candy. You have 12 available to you without using the mall, where it costs 235 Meat.
    Synthesizing those two candies will give you 30 turns of Synthesis: Greed (Meat +300%)
    The only visible difference is that it tells you the result of having the effect.

    Well, and the fact that rather than matching over ALL effect names, it matches only on the 15 effects that are a result of synthesizing candy. You could previously say "synthesize Synthesis: Greed" (and you still can), but leaving out the Synthesis: part of the name forces fuzzy matching and it will unambiguously find the desired the effect, rather than possibly resulting in an ambiguous result, considering the other 2000 or so effect names.

    Which is to say, the second half of the effect names are, effectively, keywords you can use.

    If we wanted real keywords - "meat", "items", "muscle", "muscle exp", etc. - that would be additional coding.

    I'm not feeling particularly motivated.
    Ph'nglui mglw'nafh Cthulhu
    R'lyeh wgah-nagl fhtagn.

  4. #64
    Senior Member
    Join Date
    Jan 2014
    Posts
    135

    Default

    Datafile correction: sugar-coated pine cone is complex, not simple. It had a candy credit value of 10, which implied simple, but verification has it as complex.

    Most of the other candies have been manually verified with no discrepancies.

  5. #65
    Developer Veracity's Avatar
    Join Date
    Mar 2006
    Location
    The Unseelie Court
    Posts
    11,001

    Default

    Revision 17656. Thanks.
    Ph'nglui mglw'nafh Cthulhu
    R'lyeh wgah-nagl fhtagn.

  6. #66

    Default

    Awesome work on all of this, just one tiny thingy: any chance the buffs can be added to the modifier maximizer? Without that, I'm sure I'll forgot to grab them at some future point, and then I'll be all sad.

  7. #67
    Developer Veracity's Avatar
    Join Date
    Mar 2006
    Location
    The Unseelie Court
    Posts
    11,001

    Default

    Revision 17660 adds the "synthesize" commands to statuseffects.txt, so the maximizer knows how to generate the effects. The maximizer needs to be taught more about that command to decide whether it is really available: you need to have spleen available and CandyDatabase.synthesisPair( effectId ) needs to return something other than CandyDatabase.NO_PAIR.
    Ph'nglui mglw'nafh Cthulhu
    R'lyeh wgah-nagl fhtagn.

  8. #68
    Developer Veracity's Avatar
    Join Date
    Mar 2006
    Location
    The Unseelie Court
    Posts
    11,001

    Default

    And revision 17661 teaches the maximizer about the synthesize command. That was easier than I expected.
    Ph'nglui mglw'nafh Cthulhu
    R'lyeh wgah-nagl fhtagn.

  9. #69
    Developer
    Join Date
    Apr 2010
    Posts
    3,995

    Default

    Yeah, hard bit is the command, easy bit maximizer, when it's dealing with effects.

  10. #70

    Default

    That was faster than I expected, nice.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •