Weird saltpetre math

How, what and why to code in BYOND.
Post Reply
User avatar
RobustAndRun
Joined: Wed Dec 27, 2017 7:14 pm
Byond Username: RobustAndRun

Weird saltpetre math

Post by RobustAndRun » #471353

So I was curious about the effect of saltpetre on plants, specifically its effect on production stats

Code: Select all

myseed.adjust_production(-round(salt/100)-prob(salt%100))
myseed.adjust_potency(round(salt*0.5))
so i wrote a quick python script to test values of this, using an interpretation of .dm's prob() function
Spoiler:

Code: Select all

import random

def splash(salt): #calculates one addition of a given amount of saltpetre

    rng = random.randrange(1,101) #this block is just my recreation the prob() function
    if rng < salt%100:
        rng = 1
    else:
        rng = 0
        
    prod_adj = (-round(salt/100)-rng)
    pot_adj = round(salt*0.5)
    
    return (prod_adj, pot_adj)


for i in range(25,101,5): #i = the units tested, from 25 to 100 in steps of 5
    avgProdList = [] #fills up with the test values for production changes, and potency changes go below
    avgPotList = []
    for j in range(50): #run each one 50 times, idunno
        a = splash(i) 
        avgProdList.append(a[0])
        avgPotList.append(a[1])
    if len(avgProdList) > 1 and len(avgPotList) > 1: #conditional to avoid div by 0, calculates the average of each, prints em
        avgProd = sum(avgProdList)/len(avgProdList)
        avgPot = sum(avgPotList)/len(avgPotList)
        print(i,"u: prod change = ",avgProd," | pot change = ",avgPot)
    else:
        pass
which in short just tests every 5u interval a bunch of times and prints the avg effect on production and potency, but what I found gets really weird around the 100u mark

test outputs:
Spoiler:

Code: Select all

25 u: prod change =  -0.08  | pot change =  12.0
30 u: prod change =  -0.32  | pot change =  15.0
35 u: prod change =  -0.26  | pot change =  18.0
40 u: prod change =  -0.38  | pot change =  20.0
45 u: prod change =  -0.4  | pot change =  22.0
50 u: prod change =  -0.44  | pot change =  25.0
55 u: prod change =  -1.5  | pot change =  28.0
60 u: prod change =  -1.56  | pot change =  30.0
65 u: prod change =  -1.6  | pot change =  32.0
70 u: prod change =  -1.62  | pot change =  35.0
75 u: prod change =  -1.76  | pot change =  38.0
80 u: prod change =  -1.78  | pot change =  40.0
85 u: prod change =  -1.78  | pot change =  42.0
90 u: prod change =  -1.96  | pot change =  45.0
95 u: prod change =  -1.98  | pot change =  48.0
100 u: prod change =  -1.0  | pot change =  50.0
do I have a poor understanding of the prob() math or is the original coding just bad??
somerandomguy
Joined: Sun Nov 05, 2017 7:41 pm
Byond Username: Astatineguy12

Re: Weird saltpetre math

Post by somerandomguy » #471362

100%100 is 0, so potloss with 100u is always round(100/100) [-1] - 0

It's just awful code
User avatar
oranges
Code Maintainer
Joined: Tue Apr 15, 2014 9:16 pm
Byond Username: Optimumtact
Github Username: optimumtact
Location: #CHATSHITGETBANGED

Re: Weird saltpetre math

Post by oranges » #471442

sound about right lol
4dplanner
Joined: Thu Mar 23, 2017 2:51 am
Byond Username: 4DPlanner
Github Username: 4dplanner

Re: Weird saltpetre math

Post by 4dplanner » #471517

You got the python wrong lol

(Round is the floor operation in byond)
Image
User avatar
RobustAndRun
Joined: Wed Dec 27, 2017 7:14 pm
Byond Username: RobustAndRun

Re: Weird saltpetre math

Post by RobustAndRun » #471849

4dplanner wrote:You got the python wrong lol

(Round is the floor operation in byond)
alright but what would have been the correct way of doing this?
4dplanner
Joined: Thu Mar 23, 2017 2:51 am
Byond Username: 4DPlanner
Github Username: 4dplanner

Re: Weird saltpetre math

Post by 4dplanner » #472054

Code: Select all

import random
import math #for floor, can't remember if you need it

def splash(salt): #calculates one addition of a given amount of saltpetre

    rng = random.randrange(0,100) #we want rng < 100 to be a 100% chance, rng < 1 to be a 1% chance etc
    if rng < salt%100:
        rng = 1
    else:
        rng = 0
        
    prod_adj = (-math.floor(salt/100)-rng) #this is what was giving your weird result
    pot_adj = round(salt*0.5)
    
    return (prod_adj, pot_adj)


for i in range(25,101,5): #i = the units tested, from 25 to 100 in steps of 5
    avgProdList = [] #fills up with the test values for production changes, and potency changes go below
    avgPotList = []
    for j in range(5000): #gotta get that SAMPLE SIZE
        a = splash(i) 
        avgProdList.append(a[0])
        avgPotList.append(a[1])
    if len(avgProdList) > 1 and len(avgPotList) > 1: #conditional to avoid div by 0, calculates the average of each, prints em
        avgProd = sum(avgProdList)/len(avgProdList)
        avgPot = sum(avgPotList)/len(avgPotList)
        print(i,"u: prod change = ",avgProd," | pot change = ",avgPot)
    else:
        pass
Image
User avatar
RobustAndRun
Joined: Wed Dec 27, 2017 7:14 pm
Byond Username: RobustAndRun

Re: Weird saltpetre math

Post by RobustAndRun » #472257

4dplanner wrote:

Code: Select all

smart man stuff

aite cool thx, next time I play botanist I'll test this out in game
User avatar
RobustAndRun
Joined: Wed Dec 27, 2017 7:14 pm
Byond Username: RobustAndRun

Re: Weird saltpetre math

Post by RobustAndRun » #472896

Alright update, tested it in game and found that 99u is indeed the best way to reduce production time, with 100u not doing anything outside of potency. Will make a new maffs function for this soon.

Update: I like the function y = round(-0.1 - 0.04x + 0.0005 x^2)
(y = prod change, x = saltp amount.)
Might add a prob into this for some RNG goodness.

This means that dumping gigantic amounts of saltpetre (above 50u at once, which is currently the ideal) will increase potency but have diminishing returns or even cause damage (90u+) to production speed.
This partially mirrors the effect of potassium nitrate irl, as a plant with an excessive amount of potassium ions in its soil/internal chemistry will have difficulty absorbing other nutrients such as nitrogen and magnesium.
User avatar
Cobby
Code Maintainer
Joined: Sat Apr 19, 2014 7:19 pm
Byond Username: ExcessiveUseOfCobby
Github Username: ExcessiveUseOfCobblestone

Re: Weird saltpetre math

Post by Cobby » #473990

are you saying this crap is actually not crap
Voted best trap in /tg/ 2014-current
4dplanner
Joined: Thu Mar 23, 2017 2:51 am
Byond Username: 4DPlanner
Github Username: 4dplanner

Re: Weird saltpetre math

Post by 4dplanner » #474036

I've just tested and 100u definitely does work as intended.
Image
4dplanner
Joined: Thu Mar 23, 2017 2:51 am
Byond Username: 4DPlanner
Github Username: 4dplanner

Re: Weird saltpetre math

Post by 4dplanner » #474037

Basically this doesn't need changing, it works fine
Image
Post Reply

Who is online

Users browsing this forum: No registered users