The Good, The Bad and The Stirred Up
Here, I am generating multiple events for a character. Each output has a two sentence storyline.
Jimmy will not be stirred up easily. Jimmy has not insulted others.
#the code
import random
from itertools import chain
agent_name= "Nemo"
class insulting():
def __init__(self):
self.score = random.randint(1,5)
self.text = ["insulted others","is insulting others","will insult others"]
self.text_not = ["has not insulted others","is not insulting others","will not insult others"]
self.factors = ["agreeableness","cooperation","pleasantness","rudeness"]
class stirred_up():
def __init__(self):
self.score = random.randint(1,5)
self.text = ["was stirred up easily","is stirred up easily","will be stirred up easily"]
self.text_not = ["was not stirred up easily","is not stirred up easily","will not be stirred up easily"]
self.factors = ["anger","neuroticism","tranquility"]
def get_factors(kwargs):
for factor in kwargs:
print(factor)
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, kwarg):
r= random.randint(0,2)
match(c):
case('yes'):
print(agent_name+" "+kwarg.text[r])
print ("The probability of this was: "+ str(action_probability_mod(kwarg.score)))
print ("The base probability of this was: "+ str(action_probability(kwarg.score)))
case('no'):
print(agent_name+" "+kwarg.text_not[r])
print ("The probability of this was: "+ str(1-action_probability_mod(kwarg.score)))
print ("The base probability of this was: "+ str(1-action_probability(kwarg.score)))
def get_storyline(kwarg):
prob=action_probability_mod(kwarg.score)
choice= choose(prob)
text_gen(choice, kwarg)
print("stress modifier: "+ str(stress))
print("###")
stirred_up=stirred_up()
print("tendency to be stirred up score: "+str(stirred_up.score))
print("\nfactors: ")
get_factors(stirred_up.factors)
print("###\n")
get_storyline(stirred_up)
print("\n###")
insult=insulting()
print("tendency to insult score: "+str(insult.score))
print("\nfactors: ")
get_factors(insult.factors)
print("###\n")
get_storyline(insult)
Comments
Post a Comment