Life Simulator Journey Part 01

Journey Coding a Life Simulator Part 01

Introduction

There was this game I used to play a LOT two years ago, BitLife. It’s a life simulator where you could basically do whatever you want, from modeling to becoming the most wanted person in your country. It’s just a really fun game.

A few weeks ago, I was trying to come up with a new project idea and finally landed on creating a life simulator. I wanted to create this big project where you could observe AIs make all these different life choices based on certain criterias assigned to them (their IQ level, leadership skills, etc…). I quickly realised that what I wanted to make was basically BitLife but the player wouldn’t be the one making the choices and would instead be able to observe a whole population of entities live out their lives.

How am I supposed to organise this project?

After deciding on this idea, I was really motivated. I finally had something to work on. However, I quickly realised that I had no clue as to how I was supposed to organise this project. I didn’t even know what language to choose. I was debating on whether I should use a Game Engine or not, whether Python or C++ was more suitable for this project. I finally decided on coding in Python and if I wanted to add a graphical interface later on, I would use the Pygame library.

Okay, now I had an idea and a programming language but I still had no concrete organisation plan. It had been a while since I coded in Python and I didn’t know how to properly manage all the objects and classes that I would need. So as any experienced programmer would do, I decided to say “Screw it!” and just start without wasting any more time.

Person Object

The first thing I started with was the person object. I knew that I wanted every person generated by the program to have stats that would help determine the person’s choices. For now, the list of stats that I came up with is:

These stats will help me get started with the generation of a person.

The beauty and leadership levels are based on a random integer between 0 and 100. However, the IQ level can’t be totally random like the others because the likelihood that someone possesses an IQ of 40 in real life is very low and people tend to be situated in between 85 and 115. So, based on a graph that I found here, I created this function to generate the IQ level:

def generateRandomIQ():
    # the information used below comes from: https://www.iq-brain.com/iq-test-scores/
    a = random.random()
    if a <= 0.021:
        return random.randint(0, 70)
    elif a <= 0.161:
        return random.randint(71, 85)
    elif a <= 0.5101:
        return random.randint(86, 100)
    elif a <= 0.841:
        return random.randint(101, 115)
    elif a <= 0.981:
        return random.randint(116, 145)
    elif a <= 1:
        return random.randint(146, 220)

I added a few more attributes to the person object like a first name, a last name and gender. I stored all the different first name, last name and gender options in arrays like these:

female_first_name_list = ["Jane", "Veronica", "Xiomara", "Petra", "Alba", "Anezka", "Julia"]

male_first_name_list = ["Michael", "Rogelio", "Rafael", "Pierre", "John", "Jack", "Patrick"]

last_name_list = ["Snow", "Smith", "Cordero", "Villanueva", "Obama", "Allen", "Firey"]

genders = ["male", "female"]

Note: As you can see by the names that I chose, I was watching Jane the Virgin while coding this simulator ;).

The female and male first names are separated into two different arrays and based on the gender attribute, a name will be chosen. In the same way, the person’s pronouns are chosen and put in an array:

        self.pronoun = []
        if self.gender == "male":
            self.pronoun = ["he", "his", "him"]
            self.first_name = UtilityFunctions.chooseRandomItemInArray(Data.male_first_name_list)
        elif self.gender == "female":
            self.pronoun = ["she", "her", "her"]
            self.first_name = UtilityFunctions.chooseRandomItemInArray(Data.female_first_name_list)

Every time a new person is generated, a message is sent out like this one:

John Allen is born! His stats are 97 for IQ, 65 for beauty and 1 for leadership.

Great, now we have our first person with different randomly generated stats!

Project Structure

Right now, we have a main.py fie that is used to generate people from the Person class. This class is defined in /Entities/Person/Person.py. In /Entities/Person we also have the Data.py file that stores all the first name, last name and gender arrays and UtilityFunctions.py file that stores all the functions used to generate random stats values.

It’s Time to Say Goodbye

So if you read everything until now, thanks! I just want to make sure that you know this was in no means a tutorial but just a post documenting my development process. My way of creating this simulator is probably not the best way and there will probably be some radical changes as to how I’m structuring this project, so stay tuned!

If you want to take a look at the code, go over to https://github.com/therokdaba/Simulator (what is described in this post is from Commit 2) and if you have any questions or remarks don’t hesitate to reach out on discord to therokdaba#9872.

Goodbye and see you next time :)!

Check out Part 02!

Go back to the homepage of this website.