Sunday, October 9, 2022
HomeGame Developmentarithmetic - Formulation to assign star score based mostly on cooking time...

arithmetic – Formulation to assign star score based mostly on cooking time over/beneath goal


Myself, I wish to hop right into a spreadsheet to play with formulation like these.

Verify the “Cooking Stars” tab of this workbook for a technique we may deal with it.
You’ll be able to obtain it or make a replica so you may edit it and play with the numbers to see the way it behaves.

enter image description here

This is a walkthrough of my course of:

First, I wished to make the 2 sides of the curve behave the identical for our math. So I make a “normalized” worth that rises from 0 at time zero to 1 on the “excellent level” (referred to as TargetValue in my spreadsheet), after which sinks from 1 to 0 once more by the top of the interval at time one:

$$textual content {normalized} = start{circumstances}
frac x {textual content {goal worth}}, & x le textual content{goal worth}
frac {1 – x} {1 – textual content {goal worth}}, & x > textual content{goal worth}
finish{circumstances}$$

That provides us a “curve” that is actually simply peaked roof, with two straight sides assembly at a pointy nook at (goal worth, 1), then sloping right down to (0, 0) and (1, 0) on both facet. That is the blue dashed line within the graph above.

We will flip a linear ramp between 0 and 1 like this right into a easy sigmoid curve utilizing the smoothstep perform:

$$textual content{easy}(x) = 3 x ^2 – 2 x^3$$

Making use of this to our normalized worth between 0 and 1 provides us the purple dashed curve within the graph. This has the tough form we would like, however the peak is simply too broad, and never symmetrical: if now we have a goal worth on the excessive facet like 0.8, the lengthy interval on the left has a way more light ramp-up than the brief interval on the fitting. We additionally may like to have the ability to form how tight the height is.

So let’s add one other variable, “strictness”, and warp our normalized worth from earlier right into a “strictified” worth like so:

$$textual content{strictified} = start{circumstances}
textual content{normalized}^{textual content {strictness} instances textual content{goal worth}}, & x le textual content{goal worth}
textual content{normalized}^{textual content {strictness} instances left( 1 – textual content{goal worth} proper)}, & x > textual content{goal worth}
finish{circumstances}$$

Elevating a quantity in [0, 1] to an influence > 1 like this bends it right into a curve, shrinking many of the values towards zero and making the rise to 1 on the finish steeper. That makes our 5⭐ vary narrower. By making use of the next energy on the facet with the broader interval, we squeeze that facet of the height correspondingly extra aggressively, whereas going gentler on the facet with the narrower hole to fill, general making the height in our rating perform extra symmetrical in form.

FInally we are able to apply smoothstep to that strictified worth to get a remaining rating. We will multiply the worth by 5 and ground to an integer, then add one to get our star depend.

You can also make the strictness quantity greater to make the height of the curve narrower, or decrease to make the height wider.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments