Icon representing a recipe

Recipe: Filter code for recipe writers

created by Timo van der Laan

Profile


Name
Filter code for recipe writers
ID
100662
Shared with
Public
Parent
None
Children
None
Created on
February 04, 2015 at 19:59 PM UTC
Updated on
February 04, 2015 at 19:59 PM UTC
Description

NOT a recipe, but code to be included to recipes so they run most of the time with filter off. Works if and only if there is no interaction between those filters and the tools. Problem: if there are intermediate solutions with better scores because of the filters, those will not be found.

Best for


Code


-- NOT a program, code to insert in any recipe so it will run -- as much as possible with Slow Filters OFF while saving only gains with -- Filters ON. -- TvdL, 3-2-2015 -- First step: check if Filters are active -- Names are choozen so they will probably not interfere with existing ones. TvdLscore=current.GetEnergyScore() behavior.SetSlowFiltersDisabled(true) TvdLscore2=current.GetEnergyScore() behavior.SetSlowFiltersDisabled(false) TvdLmaxbonus=TvdLscore-TvdLscore2 function TvdLFilter() local ask=dialog.CreateDialog("Slow filters seem to be active") ask.disable=dialog.AddCheckbox("Run with disabled slow filters",TvdLFilteractive) ask.l1=dialog.AddLabel("Current bonus is: "..TvdLmaxbonus) ask.l2=dialog.AddLabel("If this is not the maximum bonus change nextline") if TvdLmaxbonus < 0 then TvdLmaxbonus=0 end ask.maxbonus=dialog.AddSlider("Set maxbonus/10",TvdLmaxbonus/10,0,200,0) ask.l3=dialog.AddLabel("Scores will only be checked for real gains if") ask.l4=dialog.AddLabel("Score with filter off+maxbonus is a potential gain") ask.continue=dialog.AddButton("Continue",1) dialog.Show(ask) TvdLmaxbonus=10*ask.maxbonus.value TvdLFilteractive=ask.disable.value end BetterRecentBest=false function FilterOff() -- Filters off but restore a better recentbest with filter off behavior.SetSlowFiltersDisabled(true) if BetterRecentBest then save.Quicksave(99) save.Quickload(98) recentbest.Save() save.Quickload(99) end end function FilterOn() -- Filter on but remember recent best if better than current BetterRecentBest= recentbest.GetEnergyScore() > current.GetEnergyScore() if BetterRecentBest then save.Quicksave(99) recentbest.Restore() save.Quicksave(98) save.Quickload(99) end behavior.SetSlowFiltersDisabled(false) end TvdLFilteractive=(math.abs(TvdLmaxbonus) > 0.1) if TvdLFilteractive then --Filters active, give people a choice --And ask what the maximum bonus is. TvdLFilter() end -- End of lines you must insert before anything else -- The next line should be inserted just after the setting of current best score if TvdLFilteractive then FilterOff() end if TvdLFilteractive then FilterOff() end -- Put the next part in place where you save a gain -- Lines to be added direct after the function line if (not TvdLFilteractive) or (current.GetEnergyScore()+TvdLmaxbonus>YOURBESTSCORE) then if TvdLFilteractive then FilterOn() end -- Lines to be added just before the end of your function if TvdLFilteractive then FilterOff() end end -- -- Example of how it works out in/around my SaveBest() function bestScore=Score() if TvdLFilteractive then FilterOff() end function SaveBest() if (not TvdLFilteractive) or (Score()+TvdLmaxbonus>bestScore()) then if TvdLFilteractive then FilterOn() end local g=Score()-bestScore if g>0 then if g>0.01 then print("Gained another "..round3(g).." pts.") end bestScore=Score() save.Quicksave(3) end if TvdLFilteractive then FilterOff() end end end -- If you restore something after the script is cancelled insert this line if TvdLFilteractive then FilterOn() end

Comments


Timo van der Laan Lv 1

All reported scores inside programs when the filter code is active will be exclusive the bonus. So sometimes a lower score (but with a higher bonus) will be reported. But note that it is a better score.