Icon representing a recipe

Recipe: Evolution of fuzes

created by rarkenin

Profile


Name
Evolution of fuzes
ID
46222
Shared with
Public
Parent
None
Children
None
Created on
June 15, 2013 at 19:21 PM UTC
Updated on
June 15, 2013 at 19:21 PM UTC
Description

v4.
Tries to evolve fuze patterns by selecting pattern with best DELTA. Uses recent best now.

Best for


Code


--[[ Evolutionary fuzes rev2. Loops through opcodes as shown below. Takes better DELTA of last two. In local minima, ONE generation could be lost. ]]-- -- options VVVV normal=true --set false to seek energy in exploration puzzles minPpi = 2 --minimum poinst gain from loop to run again -- end of options ^^^^^^ opcodes={} opcodes_old={} --[[ Opcodes 1=set CI=1 and wiggle 2=set CI .9 and wiggle 3=set CI .8 and wiggle 4=set CI .7 and wiggle 5=set CI .6 and wiggle 6=set CI .5 and wiggle 7=set CI .4 and wiggle 8=set CI .3 and wiggle 9=set CI .2 and wiggle 10=set CI .1 and wiggle 11=set CI .08 and wiggle 12=set CI .05 and wiggle 13=set CI .03 and wiggle 14=set CI 0 and wiggle 15=wiggle sidechains 16=wiggle at last CI again. 17=mutate ]]-- gainbefore=0 gainafter=0 function evolve() opcodes_old=opcodes operation=math.random(10) if(operation<=6) then pos=math.random(table.getn(opcodes)) opcodes[pos]=math.random(9) end if(operation>6 and operation<=7) then table.remove(opcodes, math.random(table.getn(opcodes))) end if(operation>7) then table.insert(opcodes, math.random(table.getn(opcodes)+1), math.random(18)) end -- print(table.concat(opcodes, ", ")) -- Finished updating opcodes save.Quicksave(85) gainbefore=gainafter gainafter=opcodeExec(opcodes) if(gainbefore>=gainafter) then print("Took old which beat new by "..gainbefore-gainafter) opcodes=opcodes_old -- save.Quickload(85) else print("Gained a gain of "..gainafter-gainbefore) end recentbest.Restore() end function evolverFuzes() recentbest.Save() print("Creating dialog") local dlg = dialog.CreateDialog("Start sequence prompt") dlg.label=dialog.AddLabel("Start sequence:") dlg.button=dialog.AddButton("OK", 1) dlg.tbox=dialog.AddTextbox("startSeq", "9 1 6 1 3 1 1") dialog.Show(dlg) local opString=dlg.tbox.value print(opString) for opCode in string.gmatch(opString, "[0-9]*") do print("inserting "..opCode) table.insert(opcodes,tonumber(opCode)) end gainafter=opcodeExec(opcodes) gainbefore=gainafter while(true) do evolve() end end function opcodeExec(inCodes) print("executing "..table.concat(inCodes,",")) local scorein=current.GetScore() for i, opcodeE in ipairs(inCodes) do -- print("got "..opcodeE) if(opcodeE==1) then -- print("CI 1.0") behavior.SetClashImportance(1.0) structure.WiggleAll(1) end if(opcodeE==2) then -- print("CI 1.0") behavior.SetClashImportance(0.9) structure.WiggleAll(1) end if(opcodeE==3) then -- print("CI 1.0") behavior.SetClashImportance(0.8) structure.WiggleAll(1) end if(opcodeE==4) then -- print("CI 1.0") behavior.SetClashImportance(0.7) structure.WiggleAll(1) end if(opcodeE==5) then -- print("CI 1.0") behavior.SetClashImportance(0.6) structure.WiggleAll(1) end if(opcodeE==6) then -- print("CI 1.0") behavior.SetClashImportance(0.5) structure.WiggleAll(1) end if(opcodeE==7) then -- print("CI 1.0") behavior.SetClashImportance(0.4) structure.WiggleAll(1) end if(opcodeE==8) then -- print("CI 1.0") behavior.SetClashImportance(0.3) structure.WiggleAll(1) end if(opcodeE==9) then -- print("CI 1.0") behavior.SetClashImportance(0.2) structure.WiggleAll(1) end if(opcodeE==10) then -- print("CI 1.0") behavior.SetClashImportance(0.1) structure.WiggleAll(1) end if(opcodeE==11) then -- print("CI 1.0") behavior.SetClashImportance(0.08) structure.WiggleAll(1) end if(opcodeE==12) then -- print("CI 1.0") behavior.SetClashImportance(0.05) structure.WiggleAll(1) end if(opcodeE==13) then -- print("CI 1.0") behavior.SetClashImportance(0.03) structure.WiggleAll(1) end if(opcodeE==14) then -- print("CI 1.0") behavior.SetClashImportance(0) structure.WiggleAll(1) end if(opcodeE==15) then -- print("CI 1.0") structure.WiggleSidechains(1) end if(opcodeE==16) then -- print("CI 1.0") structure.WiggleAll(1) end if(opcodeE==17) then -- print("CI 1.0") structure.MutateSidechainsAll(1) end end return current.GetScore()-scorein end --[[ p=print CI=set_behavior_clash_importance segCnt=get_segment_count() function Score() if normal==true then return get_ranked_score(true) else return get_score(true) end end function round(x)--cut all afer 3-rd place return x-x%0.001 end function Wiggle(how, iters, minppi) if how==nil then how="wa" end if iters==nil then iters=6 end if minppi==nil then minppi=0.1 end if iters>0 then iters=iters-1 sp=Score() if how == "s" then do_shake(1) elseif how == "wb" then do_global_wiggle_backbone(2) elseif how == "ws" then do_global_wiggle_sidechains(2) elseif how == "wa" then do_global_wiggle_all(2) end ep = Score() ig=ep-sp if how~="s" then if ig > minppi then return Wiggle(how, iters, minppi) end --tail call end end end bestScore=Score() function SaveBest() local g=Score()-bestScore if g>0 then if g>0.001 then p("Gained another ",round(g)," pts.") end bestScore=Score() quicksave(84) else quickload(84) end end function FuzeEnd() CI(1) Wiggle("wa",1) Wiggle("s",1) Wiggle() restore_recent_best() SaveBest() end function Fuze1(ci1,ci2) CI(ci1) Wiggle("s",1) CI(ci2) Wiggle("wa",1) end function Fuze2(ci1,ci2) CI(ci1) Wiggle("wa",1) CI(1) Wiggle() CI(ci2) Wiggle("wa",1) end function Fuzes() bestScore=Score() local ss=Score() quicksave(3) select_all() reset_recent_best() p("Starting repeatable Fuzes... Score: ",round(ss)) --PF p("Fuze 1/6") Fuze1(0.3,0.6) FuzeEnd() p("Fuze 2/6") Fuze2(0.5,0.7) FuzeEnd() p("Fuze 3/6") Fuze2(0.7,0.5) FuzeEnd() --BF p("Fuze 4/6") Fuze1(0.05,1) restore_recent_best() SaveBest() p("Fuze 5/6") Fuze1(0.07,1) restore_recent_best() SaveBest() p("Fuze 6/6") Fuze2(0.3,1) restore_recent_best() SaveBest() local g=Score()-ss p("Loop gain: ",round(g)) if g>minPpi then return Fuzes() else p("End score: ",round(Score())) end end ]]-- -- main call -- Fuzes() evolverFuzes() --end of script

Comments


javatlacati Lv 1

ERROR: [string "–[[Evolutionary fuzes rev2. Loops trough…"]:161 attempt to call field 'WiggleSidechains' (a nil vlue)