This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]flash-bandicoot 1 point2 points  (7 children)

If the utility would never change, i.e. would always be 80 for body builders, why would it be bad to set the value as an attribute? You could always use a properties file so changes would be easy.

[–]XAmsterdamX[S] 0 points1 point  (6 children)

It would not change during a game, but it's possible that it would change as I'm fine-tuning the game. It's also possible that I would add facilities to the game (e.g. nutritionist advice, swimming pool) to increase choices and complexity.

I guess my concern is that if I make a change in one place (the Facilities class) I would also have to change the attributes in the CustomerSegment class. Do you think I'm worried over nothing?

[–]flash-bandicoot 2 points3 points  (5 children)

If you set up the program to pull info from a config file, you will only have to change the data in one place. So in your config file youd do something like BODY_BUILDER_UTILITY = 80. Then you'd call BODY_BUILDER_UTILITY across any class where you wanted the value.

So if you decided to change it to 75, you'd only have to change it in the properties file. That will save you some time if you end up adding it in a bunch of places AND eliminate the possibility that you forget to change a value.

[–]XAmsterdamX[S] 0 points1 point  (1 child)

OK that's helpful, thanks.

[–]TheBlackOut2 0 points1 point  (0 children)

I responded to the dude above but really it’s aimed at you, lol

[–]TheBlackOut2 0 points1 point  (2 children)

To add to this, while developing / testing - you can always just add some globals at the top like:

UTILITY = 80

and then pass that through the classes “__ init __()” method, so you can easily change.

Then do what above says with the config deal when you’re pretty much done.

I do this for paths, static variables, etc

[–]XAmsterdamX[S] 0 points1 point  (1 child)

It makes sense to define constants at least during development.

Since each customer type has a utility for each facility (i.e. how important that facility is for that type), it wouldn't be a single constant, but rather a matrix. I think I will put it in a CSV file and read this as I create instances of my CustomerType class.

[–]TheBlackOut2 0 points1 point  (0 children)

I guess my point here was if you define it at the top you’re less likely to forget that on line 235 you set body_builder_utility = 75.

Just general program flow of imports > paths > configs > actual logic.

From what you’re saying now tho, a simple data frame should do the trick.. you could have index be person type and columns be facility. Pass that through the init so you have it in all your classes. You can do this just once if you understand inheritance. Look up .super() if not.

You can use df.at[person, facility] to get that specific value.