Page 1 of 1

simplify personality point system

Posted: Sun Sep 05, 2021 5:56 pm
by lindsay-jb
Hey! So I have three personality points that I'm keeping track of which affect automated MC responses. However, the code I made for it is a little unwieldy. The problem comes when I'm specifying the heirarchy in case they have equal points. I want it to be genuine > sarcastic > aggressive; or in other words, if genuine = sarcastic or genuine = aggressive, then genuine is dominant, and if sarcastic = aggressive, sarcastic is dominant. So whenever I have moments where I specify the type of response, I have to type out this whole thing:

Code: Select all

if genuine > sarcastic and genuine > aggressive or genuine > sarcastic and genuine == aggressive or genuine == sarcastic and genuine > aggressive or genuine == sarcastic and genuine == aggressive:
   	rowan "Dialogue"
        jump ch1_s2_menu3_main

elif sarcastic > genuine and sarcastic > aggressive or sarcastic > genuine and sarcastic == aggressive:
   	rowan "Dialogue"
        jump ch1_s2_menu3_main

elif aggressive > genuine and aggressive > sarcastic:
   	rowan "Dialogue"
        jump ch1_s2_menu3_main
As you can see, it's quite... long. I'm just wondering if there's a way I can set up the weight so I don't have to write that super long statement for the genuine personality every time?

Re: simplify personality point system

Posted: Sun Sep 05, 2021 6:47 pm
by Ocelot
As usual, if you want complex behavior from your variables, either make them a class, or shove them in class:

Code: Select all

class Traits:
    def __init__(self):
        self.genuine = 0
        self.sarcastic = 0
        self.aggressive = 0

    @property
    def dominant_trait(self):
        trait = sorted([(self.genuine, 3, 'genuine'), (self.sarcastic, 2, 'sarcastic'), (self. aggressive, 1, 'aggressive')])
        return trait[-1][2]

# Definition of personality variable
default personality = Traits()
# You can easily manipulate individual personality points
    $ personality.sarcastic += 3
    $ personality.aggressive += 3
# And checking dominant trait is pretty easy
if personality.dominant_trait == 'sarcastic':
    # . . .
elif personality.dominant_trait = 'aggressive':
    # . . .

Re: simplify personality point system

Posted: Thu Sep 23, 2021 7:55 pm
by lindsay-jb
Thank you! I've adapted my code to do the points this way. And just a quick verification, how do i establish the hierarchy in case there are ties in points? i'm guessing that's done in the default spot?

Re: simplify personality point system

Posted: Fri Sep 24, 2021 3:35 am
by Ocelot
This code creates a list of tuples (trait_value, tiebreaker, trait_name) and sorts it ascending (largest last). Then it takes last (largest) element (trait[-1]) and extracts name from it (trait[-1][2]).

Tuples are compared by comparing its elements in order. If first element (trait value in my code) of one tuple is larger or smaller that the other, the whole tuple is considered larger or smaller. When those elements are equal (tie in points), Python goes to compare second element in tuples. In my code this element is a tiebreaker. 'Geniune' trait has a tiebreaker value of 3 — larger than any other. If 'Geniune' trait value ties with other trait, it will come on top, because its tiebreaker value will compare higher than one he tied with.

Re: simplify personality point system

Posted: Fri Sep 24, 2021 7:19 am
by jeffster
Without classes:

Code: Select all

init python:
    def resp(r_genuine, r_sarcastic, r_aggressive):
        if sarcastic < aggressive > genuine:
            return r_aggressive
        if sarcastic > genuine:
            return r_sarcastic
        return r_genuine
So every time you need to choose the response automatically, you call that function with those 3 responses for this situation, and it returns the proper one:

Code: Select all

rowan resp("I hear you", "Oh yeah, sure", "Screw you")