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
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
• 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: 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
• 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
• 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
• 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()
• 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()
• Randomly assigns “male” or “female” as the character’s gender via a coin flip.
Function: Gender_print()
• Displays the chromosomes and narrates gender assignment.
Function: Set_name()
• Chooses a random name from the appropriate list based on gender.
Function: Name_print()
• Prints the assigned name.
Function: Get_death()
• Randomly selects a cause of death from the predefined list previously written.
Function: Death()
• 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()
• 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)
• 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
• Calls functions to initialize the character’s life, assign gender, and name.
Age Simulation
• Simulates the passage of time, incrementing age with each iteration.
• The age is printed in each iteration
Random Death Chance
• Simulates a very low chance of random death, only if the random number chosen is 66
Changing Chance Weights
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
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!
• Handles premature death by events and natural death due to old age.
This was the last step and ends the person's life.
Conclusion
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