Life Simulator - Watch an AI Person's Life

by tanish satpal in Circuits > Computers

29 Views, 0 Favorites, 0 Comments

Life Simulator - Watch an AI Person's Life

Image 12-01-25 at 11.32 AM.jpeg

This program simulates a person’s life journey, blending humor, randomness, and storytelling. Below is a detailed explanation of the code, step by step, aligned with the sequence of the program.

Just sit back and watch an AI come to life. Its not that hard edit too!

Supplies

You need a program that can run basic Python code. I am using Google Colab and will share a link to my Colab File

Import Statements

import random
import time

• random: Used to generate random numbers for events, gender, names, and causes of death.

• time: Introduces delays for a more natural flow of the simulation.

Global Variables

game_status = "alive"
age = -1
gender = ""
name = ""
cause_death = ""

• game_status: Tracks whether the character is alive or dead.

• age: Initialized to -1, it increments in the age loop.

• gender and name: Store character attributes assigned during the simulation.

• cause_death: Holds the reason for the character’s death.

They have been initialised to be used soon in the program

Name and Cause of Death Lists

name_male_list = [...]
name_female_list = [...]
causes_death_list = [...]

Male and Female Name Lists: Provide a pool of names for character creation.

Death Causes: Contains humorous and imaginative reasons for the character’s demise.

If you want to use my list, just check it in the Google Colab document. If you want to write your own, each name needs to be in quotes and separated by a comma.

Default Chance Values

low_chance = 150
high_chance = 10

• These values influence the likelihood of life events happening during the simulation.

You can change them as your wish to see how things unfold in the character's life

Boolean Value Setup

learn_python_message = False
learn_c = False
sad_message = False
job_message = False
college_message = False
married_message = False
kids_message = False
retire_message = False

• Flags ensure certain messages or events, like learning Python, are displayed only once.

All the Functions That Will Be Covered

1. it_lives(): Simulates the start of life.

2. set_gender(): Determines the gender by flipping a virtual coin (randomized).

3. gender_print(): Displays the assigned gender and its corresponding chromosome (XX/XY).

4. set_name(): Assigns a name based on gender by selecting randomly from predefined lists.

5. name_print(): Displays the assigned name.

6. get_death(): Randomly selects a cause of death from causes_death_list.

7. death() and natural_death(): Handle death messages for early or natural causes.

8. chance_dice(a, b): Returns a random integer between a and b.

Function: It_lives()

def it_lives():
life_index = chance_dice(0, 1)
if life_index == 0:
print("From out of the blue, a new life is created. \n One cell. Infinite possibilities.")
print("\n.\n")
print("..\n")
print(".-.. .. ..-. . / -.-. .-. . .- - .. --- -.\n-- .- -.. . / -... -.-- / - .- -. .. ... ....\n")
print("some time later...")
elif life_index == 1:
print("Welcome to life as you are now a single cell...")
print("\n-\n")
print("--\n")
print(" -.-- -- --.- - / .-.- -.- - -. . -- ... .-\n")
print("A while later...")

• Introduces the simulation with two possible starting narratives chosen randomly.

The Morse Code is an eater egg. Change it to hide your name in the program!

Function: Set_gender()

def set_gender():
gender_dice = random.randint(0,1)
if gender_dice == 0:
return "female"
elif gender_dice == 1:
return "male"
gender_print()

• Randomly assigns “male” or “female” as the character’s gender via a coin flip.

Function: Gender_print()

def gender_print():
print("... a large group of awesome cells is around...\n")
print("...then a coin is flipped and a gender is chosen. \nThe cromossomes responsible for this task looks like this:")
if gender == "female":
print("\nXX")
else:
print("\nXY")
print("\n ...so your gender is " + gender + ".")

• Displays the chromosomes and narrates gender assignment.

Function: Set_name()

def set_name():
if gender == "male":
name_index_male = random.randint(0 , int(len(name_male_list)) -1 )
return name_male_list[int(name_index_male)]

if gender == "female":
name_index_female = int(random.randint(0 , int(len(name_female_list))) -1 )
return name_female_list[int(name_index_female)]

• Chooses a random name from the appropriate list based on gender.

Function: Name_print()

def name_print():
print("You have neen chosen")
print("The name given to you is \"" + str(name) + "\".")
print("\nAnd here goes your yearbook, something you will never need again:")

• Prints the assigned name.

Function: Get_death()

def get_death():
cause_index = int(random.randint(0, int(len(causes_death_list))) -1 )
cause_death = str(causes_death_list[int(cause_index)])
return cause_death

• Randomly selects a cause of death from the predefined list previously written.

Function: Death()

def death():
print("\n======== R.I.P ========")
print("\"" + str(name) + "\"" +" just passed away sadly. \nCause of your death: " + get_death() + ".")
if age <=18:
print("So sad it had to go so soon...just kiddin, ITS JUST A GAME!")
print("\nOne last wish: PRESS THE RUN BUTTON AGAIN!\n")

• Handles the event of death, displaying the name and cause.

This death is meant to be very rare, because of the next function

Function: Natural_death()

def natural_death():
print("\n======== R.I.P ========")
print("\"" + str(name) + "\"" +" just passed away by natural causes, had great fun and a long life.")
print("Oh, one last wish: PRESS THE RUN BUTTON AGAIN!")

• Manages the character’s natural death after a long life.

This is much more common, as the dice rolls will favour this.

Function: Chance_dice(a, B)

def chance_dice(a,b):
return int(random.randint(a,b))

• Generates a random number between Value a and Value b. These can be changed in different functions.

This marks the end of the functions. Now, the main ife will start.

Initial Setup of Program

it_lives()
gender = set_gender()
name = set_name()
name_print()

• Calls functions to initialize the character’s life, assign gender, and name.

Age Simulation

while game_status == "alive":
age = age + 1
time.sleep(1)
if age != 0:
print("age: " + str(age))

• Simulates the passage of time, incrementing age with each iteration.

• The age is printed in each iteration

Random Death Chance

event_chance = random.randint(1, low_chance + high_chance)
if event_chance == 66:
game_status = "dead"

• Simulates a very low chance of random death, only if the random number chosen is 66

Changing Chance Weights

if age <= 6:
high_chance = 200
elif age <= 12:
high_chance = 150
elif age <= 16:
high_chance = 120
elif age >= 65:
high_chance = 75
elif age >= 75:
high_chance = 70
elif age >= 80:
high_chance = 67

This makes it so that the older a person get, the less text is shown. This prevents things like double marriages, etc.

The Entire Life

#never is late for python
if age == chance_dice(12,37) and learn_python_message == False:
print("You really got luck and started to learn Python!")
learn_python_message = True;


if age == chance_dice(12,37) and learn_c == False:
print("You went oldschool and started to learn C.")
learn_c = True;


if age == chance_dice(4,7):
chance_first_school = chance_dice(0,4)
if chance_first_school != 1:
print("First day at new school. Lets begin your life.")
chance_friends = chance_dice(0,1)
if chance_friends == 0:
print("But you don't have that many friends yet. You keep trying",name)
elif chance_friends == 1:
print("You've made many friends. Great going!")

#teenager
if age == 16:
chance_gift = random.randint(0,2)
if chance_gift == 1:
print("Highschool is boring but you figured that you can live a life on your own.")
#college
if age >= 25 and college_message == False:
college_message = True
chance_college = chance_dice(1,5)
if chance_college == 3:
print("You got into college!")
married_message = True
elif chance_college == 4:
print("You started the Computer Science college and had fun in your first period: Python and HTML!")

#marriage
if age >= 25 and married_message == False:
married_message = True
chance_married = chance_dice(1,5)
if chance_married == 3:
print("You got married!")
elif chance_married == 4:
print("You feel in love and got married with lil Py!")
else:
married_message = False


#kids
if age >= 25 and kids_message == False:
kids_message = True
if married_message == True:
print("What nice couple you make! Congratulations, you gonna have a child!")
elif married_message == False:
print("After a short abduction you had a cute little alien child, whom you can't control.")

#work
if age >= 20 and age <= 65:
job_chance = chance_dice(1,15)
if job_chance == 5:
print("You got a new job!")

#retirement
if age >= 65 and retire_message == False:
retire_chance = chance_dice(1,3)
if retire_chance == 2:
print("You worked all your life and now got a good retirement...lots of free time to spend with the family.")
retire_message = True

This is all the possible life events. Change the ages and boolean values to get a very wacky life! Change the txt to your own creativity, it is up to you!

if game_status == "dead":
death()

if age >= 75:
old_age_death = chance_dice(0,4)
if old_age_death == 1:
game_status = "dead"
natural_death()

• Handles premature death by events and natural death due to old age.

This was the last step and ends the person's life.

Conclusion

FTKTVEIM5S780HR.jpg

The program is a creative blend of humor and randomness, offering a unique experience every time it runs. By understanding each part, you can customize it further—adding new events, expanding lists, or incorporating user input. This can truly test a person's creativity, and so many new things can be added! A lot can be changed, and I would love to see you do it! Let your creativity ride free.

And always, the Google Colab link: https://colab.research.google.com/drive/1JRapgvN5cfsyea6Zu8M3TeRaNvxIVjO5?usp=sharing