Profile
- Name
- Bravo FuC v1.1
- ID
- 109139
- Shared with
- Public
- Parent
- Bravo FuC v1.0
- Children
- Created on
- August 13, 2025 at 16:03 PM UTC
- Updated on
- January 09, 2026 at 05:18 AM UTC
- Description
Fuze using Cuts v1.1
Best for
Code
-- based on Recipe: fuze using cuts created by pauldunn
-- Bravo FuC
-- v1.0
-- added more score checks and moved away from recent best
-- added Bravo Cut and Close
-- added xpcall(main), error handler, and moved everything into functions
-- added repeat main and score tracking to move away from endless mode with no gains
-- added work on worst first instead of random segment (won't repeat segments before all segments are checked)
-- added effeicent close_all_cuts() function
-- v1.1
-- added repeat and removed recursion call for memory optimization
-- added QuickFuze (now with shake)
-- fixed up some print lines
function initialize()
-- Initialize global variables
starting_score = current.GetScore()
best_score = starting_score
segment_count = structure.GetCount()
-- save slots
temp_inprogress_save_slot_number = 2
-- best score save slot number is "1"
save.Quicksave(1)
-- re ordering segments would mean that they don't happen once every segment count
segmentScores = getSegmentScores()
end
function main()
initialize()
repeat
local initialScore = best_score
print(string.format(" current score: %.3f", initialScore))
for i = 1, segment_count do
-- Set recent best for each segment. Otherwise it could try the same thing twice which is useless.
-- TODO: still has the chance of just performing the starting structure multiple times if noting during was better.
recentbest.Save()
local seg = segmentScores[i].seg
cut_and_close(seg)
fuzeUsingCuts(seg)
check_score(seg)
print(string.format(" %i/%i seg: %i score: %.3f (%.3f) (%.3f)", i, segment_count, seg, current.GetScore(), recentbest.GetScore(), creditbest.GetScore()))
check_recent_best(seg)
end
QuickFuze()
check_and_update_score(0)
until current.GetScore() <= initialScore-- repeat main if score inproved
ending_print()
end
function QuickFuze()
print(" QuickFuze")
structure.WiggleAll(25, true, true)
structure.ShakeSidechainsAll(1)
structure.WiggleAll(25, true, true)
structure.ShakeSidechainsAll(1)
structure.WiggleAll(25, true, true)
end
function fuzeUsingCuts(seg)
behavior.SetClashImportance(1)
structure.InsertCut(seg)
structure.WiggleAll(15, true, true)
close_cut_and_check_inprogress_score(seg)
behavior.SetClashImportance(0.1)
structure.WiggleAll(1, true, true)
behavior.SetClashImportance(1)
structure.WiggleAll(25, true, true)
structure.DeleteCut(seg)
check_score(seg)
structure.WiggleAll(25, true, true)
check_score(seg)
behavior.SetClashImportance(0.1)
structure.WiggleAll(2, true, true)
-- FUC needs to end with CI = 1
behavior.SetClashImportance(1)
structure.WiggleAll(25, true, true)
end
function getSegmentScores()
local scores = {}
for seg = 1, segment_count do
table.insert(scores, {seg = seg, score = current.GetSegmentEnergyScore(seg)})
end
table.sort(scores, function(a, b) return a.score < b.score end)
return scores
end
function check_recent_best(segment)
recentbest.Restore() --TODO: this will crash clients in Evolver if no valid score was ever found. impliment "recentbest.AreConditionsMet()"
close_all_cuts()
check_score(segment)
-- CI and other Behavior importance need to be good before this wiggle.
structure.WiggleAll(25, true, true)
check_and_update_score(segment)
end
function cut_and_close(segment)
-- Apply a cut to the segment
structure.InsertCut(segment)
-- Close the cut
structure.DeleteCut(segment)
check_and_update_score(segment)
end
-- this function replaces the following slow code. we don't need to check every segment if we know where the cuts are.
-- for s=1,structure.GetCount() do structure.DeleteCut(s) end
function close_all_cuts()
-- from https://foldit.fandom.com/wiki/Foldit_Lua_Function_structure.GetCuts
local table_of_cuts = structure.GetCuts()
-- print ( #table_of_cuts .. " open cutpoints found" )
for ii = 1, #table_of_cuts do
-- print ( "open cutpoint " .. ii .. " at segment " .. table_of_cuts[ ii ] )
structure.DeleteCut ( table_of_cuts[ ii ] )
end
end
-- Function to check inprogress score and update the best score
function close_cut_and_check_inprogress_score(segment)
save.Quicksave(temp_inprogress_save_slot_number)
structure.DeleteCut(segment)
close_all_cuts()
check_score(segment)
save.Quickload(temp_inprogress_save_slot_number)
end
-- Function to check and update the best score
-- Doesn't quick load best score
function check_score(segment)
local new_score = current.GetScore()
if new_score > best_score then
local gain = new_score - best_score
best_score = new_score
save.Quicksave(1)
if gain > 0.001 then -- was printing pointless gains with to much clutter. still want to keep score improvement though
if segment == 0 then
local total_gain = best_score - starting_score
print(string.format(" Best Score: %.3f Gain: %.3f Total Gain: %.3f", best_score, gain, total_gain))
else
print(string.format(" Seg: %i Score: %.3f Gain: %.3f", segment, best_score, gain))
end
end
end
end
-- Function to check and update the best score
-- Does quick load best score
function check_and_update_score(segment)
local new_score = current.GetScore()
if new_score > best_score then
local gain = new_score - best_score
best_score = new_score
save.Quicksave(1)
if gain > 0.001 then-- was printing pointless gains with to much clutter. still want to keep score improvement though
if segment == 0 then
local total_gain = best_score - starting_score
print(string.format(" Best Score: %.3f Gain: %.3f Total Gain: %.3f", best_score, gain, total_gain))
else
print(string.format(" Seg: %i Score: %.3f Gain: %.3f", segment, best_score, gain))
end
end
else
save.Quickload(1)
end
end
function ending_print()
-- Print the best score and total gain
local total_gain = best_score - starting_score
print(" Best score: " .. best_score)
print(" Total gain: " .. total_gain)
end
-- Error handler function
function error_handler(err)
print(" Error: " .. err)
-- clean up cuts before score check
close_all_cuts()
check_and_update_score(0)
behavior.SetClashImportance(1)
check_recent_best(0)
ending_print()
return
end
xpcall(main, error_handler)