Profile


Name
Hill Climb
ID
108079
Shared with
Public
Parent
None
Children
Created on
October 20, 2022 at 07:27 AM UTC
Updated on
December 26, 2022 at 23:39 PM UTC
Description

Mutates, shakes, and wiggles in a loop until a local optimum is found.

Best for


Code


function Round(n, num_decimals) local mult = 10^(num_decimals or 0) return math.floor(n * mult + 0.5) / mult end function WiggleUntilComplete(max_wiggles) for i=1, max_wiggles do local starting_score = current.GetScore() structure.WiggleAll(1) if (current.GetScore() - starting_score < 0.001) then break end end end function DesignUntilComplete() local starting_score = current.GetScore() structure.MutateSidechainsAll(1) structure.ShakeSidechainsAll(1) WiggleUntilComplete(8) local ending_score = current.GetScore() local score_delta = ending_score - starting_score print(os.date("%X"), "Improved score by", Round(score_delta, 3), "to", Round(ending_score, 3)) if (score_delta > 0.001) then DesignUntilComplete() end end function Main() starting_wiggle_power = behavior.GetWigglePower() behavior.SetWigglePower("m") local starting_score = current.GetScore() print(os.date("%X"), "Starting hill climb at", Round(starting_score, 3)) DesignUntilComplete() behavior.SetWigglePower(starting_wiggle_power) local ending_score = current.GetScore() print(os.date("%X"), "Total score increase of", Round(ending_score - starting_score, 3)) print(os.date("%X"), "Finished hill climb at", Round(ending_score, 3)) end Main()

Comments