First Post: Personality Based Simulator

The initial python program, written with Pydroid3, outputted a string (either Jimmy was insulting or Jimmy wasn't insulting) and an associated probability of the string's occurrence.

Here, Jimmy beat the odds and became insulting.

The final version includes an environmental modifier, Jimmy's stress level.
In this output, the stress modifier can lower or raise the base probability of the string occurrence.

#The Code

import random 
from itertools import chain

action_score1= random.randint(1,5)
action1="insulting others"
agent_name= "Jimmy"

stress= random.randint(-10,10)/10
stress_modifier= stress*0.2

def action_probability(score):
    match(score):
        case(1):
            return 0.1
        case(2):
            return 0.2
        case(3):
            return 0.5
        case(4):
            return 0.6
        case(5):
            return 0.8

def action_probability_mod(score):
    match(score):
        case(1):
            return 0.1+(stress*0.1)
        case(2):
            return 0.2+stress_modifier
        case(3):
            return 0.5+stress_modifier
        case(4):
            return 0.6+stress_modifier
        case(5):
            return 0.8+stress_modifier
            
def choose(probability):
   instances=probability*100
   instances_not=100-instances
   yes_occur=int(instances)
   no_occur= int(instances_not)
   my_list=[("yes,"*yes_occur). split (","), ("no," *no_occur).split(",")]
   flat_list = list(chain(*my_list))
   c= random.choice(flat_list)
   return c
  
def text_gen(c):
    match(c):
        case('yes'):
            print(agent_name+ " is "+action1)
            print ("The probability of this was: "+ str(action_probability_mod(action_score1)))
            print ("The base probability of this was: "+ str(action_probability(action_score1)))
        case('no'):
            print(agent_name+ " is not "+action1)
            print ("The probability of this was: "+ str(1-action_probability_mod(action_score1)))
            print ("The base probability of this was: "+ str(1-action_probability(action_score1)))
             
prob=action_probability_mod(action_score1)
choice= choose(prob)
text_gen(choice)
print("stress modifier: "+ str(stress))

Comments

Popular posts from this blog

Narrative Development Environment