CS101: Aspiration and Hobby chooser for The Sims 2
Tags: python, codecademy, codenewbie, beginners
Published: 2023-04-26 20:05:30

*This post was created for Codecademy's Computer Science course.*

## What Is This and Why Did I Make It
20 years later, I still enjoy playing The Sims 2, objectively the best game in the Sims franchise. (Yes I said objectively, no I'm not about to get into my hot Sims takes.) For those who don't know, The Sims 2 is a life simulation game where the player and create and control the lives of Sims. It's a virtual dollhouse.

Honestly this program and blog post will really only be understandable by Sims fans who code, so I'm speaking to a small group of people here. Feel free to leave now because I'm about to throw a lot of context at you, reader.

The Sims 2 lends itself to generational play, where you would play the same family over the course of several generations. It's really fun to see a family evolve! And of course, when two Sims love each other very much, they go do a little Woohoo and wham, now your Sims are parents. But once their child becomes a teenager, the player is directed to choose an aspiration for them. Aspirations are the big thing that determines what a Sim wants and fears in life. If you have all the expansions in the game like myself, then there are six potential aspirations for any Sim.

Having played many families over two decades, there are three ways to go about choosing an aspiration when your Sim grows into a teenager.

1. Just pick one you like or want to play with for that Sim.
2. Roll a six-sided die and associate a number for each aspiration (aka, randomize it).
3. Make a complicated system that bases the aspiration on some other data, like the personality, zodiac sign and/or interests.

Guess what I decided to go with.

## Preparing the Project
The objectives for this project are as follows: 

- Build a terminal program using Python
- Add at least one interactive feature using `input()`
- Use Git version control
- Use the command line and file navigation
- Write a technical blog post on the project (oh hey!)

Now I'll be honest, having written this thing in PyCharm, I'm not really sure how I should have used the command line and file navigation any more than I needed to. So there's that. But aside from these objectives, the project was free to be really whatever I wanted, so I decided to make something I'd been wanting to make for a while now: a niche program for my Sims.

### Sim Details That Aren't Hugely Important But Provide Context
#### Personality and Zodiac Sign
Sim personalities are determined by how many points they have in five different categories, as shown below. A Sim born in-game has a personality that is a mix of their parents' with some random values for variety.

![A screenshot of a Sim's personality panel, showing five categories: Sloppy/Neat, Shy/Outgoing, Lazy/Active, Serious/Playful, Grouchy/Nice. Each category can have anywhere from 0 to 10 points in it.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9e0e3c5hosavg0nzxp0j.jpg)

You'll also see that the Sim's zodiac sign is shown as well. Zodiac signs are not determined by *when* a Sim was born (Sims don't really have years or months as we know them) but rather by their point array. You have to be in a specific range of Grouchy/Nice for the game to assign you as a Pisces, for example.

The reason I bring this up is because one might assume that since zodiac and personality points are tied together like this, that I wouldn't need to look at both in my program. However, some Sims can have a "mismatch" between their sign and their personality, especially if parents encourage a child Sim to lean a specific way on any of the categories. So I decided to calculate with both.

#### Interests
Sims have 18 interests which are completely randomized when they are born. These are not based on any genetic factors and can change in gameplay (though in my experience, they rarely do).

![A screenshot showing a Sim's Interests panel, showing 18 interests. Each interest can have any number of points from 0 to 10. I'm not going to type them all out here, please look it up.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/niskhzenrv29wrinps12.jpg)

These along with personality points primarily influence a Sim's **One True Hobby,** which is just the one hobby out of ten that they are gifted in. However, the original game code for determining that hobby is really lame and I don't like it. All Sims gifted in Cuisine have to be Sloppy? No thanks, I'm calculating it differently.

## How I Made This Thing
When brainstorming my code, I knew *what* I wanted to do, which was to make it so zodiac, interest and personality points affected some kind of score towards a specific aspiration and hobby. I decided to create several counters and make it so meeting certain criteria adds a point to some of them.

First thing I realized is that is a LOT of numbers to keep track of. 5 personality categories and 18 interests, which the user has to input themselves? Plus the counters for 6 aspirations and 10 hobbies, that's 39 different variables. To improve readability, I put all my variables in dictionaries.

Then I wrote out all the functions necessary for the user to input data about their Sim. Because my variables were part of dictionaries, it's super easy to iterate through them with for loops and update each key's value with the input.

The functions that actually calculate the aspiration and hobby are unwieldy. It's just *so* many if statements. Why? Because if a certain criteria is met, increment the associated counter by 1. Which means I made an if statement for every. Single. Criteria. This is the part of my code I like the least. I got some advice to try switch statements instead, which I will definitely try when I expand this for my personal use.

### Refactoring
After writing the bulk of the code and making sure it was working, and after tightening it up as best I could, I decided to create a class to save the Sim's data as its own object instance. I didn't have to do this, but I did anyway!

Then I also included the option to the user to save the Sim's data as a CSV file, because maybe the user would like to find this info after closing the program and launching The Sims 2 to actually assign the aspiration.

### Examples
![A screenshot showing the terminal window as my program asks for a zodiac sign and personality points.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x3h6rlm4qdy19f29zreh.jpg)

First it asks for zodiac sign and personality points. (If the user inputs a sign that isn't recognized in the list, or an integer outside of the 0-10 range, the program will prompt them to try again.)

![A second screenshot showing the terminal window as my program asks for each interest score.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/phts65ujn96ha4elc4d3.jpg)

Then the longest input sequence ever for interests.

![A third screenshot showing the terminal window as my program performs the final calculations.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h4ho29mmqec2tls4lgm0.jpg)

And finally, the terminal prompts for a name and spits out a bunch of information. I made it print the actual aspiration and hobby scores so the user could see what came in second place or dead last if they wanted to. Then it asks the user if they'd like to save the Sim!

## Summing It All Up
I made the thing from scratch, it exists. It's published on GitHub so you can check it out and probably catch things I missed. Or maybe I did everything perfect (I did not) and this will be my magnum opus (unlikely).

I plan to add other features to flesh this out more to what I really want it to be, but for now it works as intended and I'm pretty happy with it. Thanks for reading and go play some Sims!

## [Ivy's Aspiration Project](https://github.com/ivyrosefernsby/aspiration_project)