This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2013-02-16 17:41:51

Programmer_112
Scratcher
Registered: 2012-02-17
Posts: 100+

Evonomics

I was learning about evolution in school, and I decided to use Python to make an evolution sim.  It's still in the early stages, but I finally got a version out.  Here is the code

Code:

import random

extinct = False

print "Welcome to Evonomics Alpha!  This simulation focuses on following the evolution of a species through a certain amount of years in a given environment"
norp = raw_input("Do you want to make a new species or use a preexisting one?  Input the whole word with a capital at the start.")

if norp == "Preexisting":
    choice = raw_input("Which species do you want to use?  Type 'giraffe', 'lion', 'elephant', 'tiger', 'wolf', or 'dog'.")
    name = choice
    
    if choice == "giraffe":
        heightdom = "Tall"
        heighthigh = 180
        heightlow = 156
        speed = 5
        fight = 4
        food = "Herbivore"
        repnumb = 3
        reptime = 8
        survive = 7
        temp = 5
        al = 30
    
    elif choice == "elephant":
        heightdom = "Tall"
        heighthigh = 120
        heightlow = 108
        speed = 7
        fight = 6
        food = "Herbivore"
        repnumb = 2
        reptime = 12
        survive = 8
        temp = 10
        al = 45
        
    elif choice == "lion":
        heightdom = "Tall"
        heighthigh = 55
        heightlow = 4
        speed = 35
        fight = 7
        food = "Omnivore"
        repnumb = 4
        reptime = 8
        survive = 5
        temp = 15
        al = 35
        
    elif choice == "tiger":
        heightdom = "Short"
        heighthigh = 45
        heightlow = 35
        speed = 50
        fight = 6
        food = "Omnivore"
        repnumb = 3
        reptime = 7
        survive = 6
        temp = 10
        al = 25
        
    elif choice == "wolf":
        heightdom = "Tall"
        heighthigh = 50
        heightlow = 40
        speed = 30
        fight = 6
        food = "Carnivore"
        repnumb = 4
        reptime = 12
        survive = 8
        temp = 20
        al = 15
        
    elif choice == "dog":
        heightdom = "Tall"
        heighthigh = 40
        heightlow = 25
        fight = 4
        food = "Omnivore"
        speed = 20
        repnumb = 7
        reptime = 10
        survive = 7
        temp = 15
        al = 10

elif norp == "New":
    name = raw_input("What is the race called?")
    heightdom = raw_input("Are they more likely to be tall or short?  Input the whole word with a capital at the start.")
    heightlow = input("What is the minimum height in inches?")
    heighthigh = input("What is the maximum height in inches?")
    food = raw_input("Is the animal a carnivore, herbivore, or an omnivore?  Type the whole word with a capital at the start.")
    reptime = input("How many months does it take them to reproduce?")
    repnumb = input("How many offspring do they have at a time?")
    temp = input("How many degrees of natural insulation do they have?")
    fight = input("On a scale of 1 to 10, how well do they fight?")
    speed = input("On a scale of 1 to 10, how fast are they?")
    survive = input("On a scale of 1 to 10, how well do they adapt?")
    al = input("How many years is their average lifespan?")

if heightlow > heighthigh:
    x = heightlow
    heightlow = heighthigh
    heighthigh = x

average = 0.5*(heighthigh+heightlow)
a=int(heightlow)
b=int(heighthigh)
c=int(average)
if heightdom == "Tall":
    if random.randint(0, 4) == 4:
        height = random.randint(a, c)
    else:
        height = random.randint(c, b)
elif heightdom == "Short":
    if random.randint(0, 4) == 4:
        height = random.randint(c, b)
    else:
        height = random.randint(a, c)
x = random.randint(85, 130)/100
weight = x*height
needs = 0.010203020301*weight


environment = raw_input("What environment should it be released in? Type 'desert', 'tundra', 'plains', or 'forest'.")

if environment == "desert":
    temp2 = 9
    foodh = 2
    foodc = 3
    dis = 4
    bonus = 1000000

elif environment == "tundra":
    temp2 = 10
    foodh = 1
    foodc = 2
    dis = 2
    bonus = 1000000

elif environment == "plains":
    temp2 = 65
    foodh = 6
    foodc = 6
    dis = 5
    bonus = 85

elif environment == "forest":
    temp2 = 50
    foodh = 9
    foodc = 7
    dis = 7
    bonus = 110


years = input("How many years should this be simulated?")
pop = input("How many should be released into the wild?")
monthsmore = reptime
yearsdone = 0
yearsleft = al

for i in range (0, years):
    yearsleft -= 1
    popbefore = pop
    for j in range (0, 12):
        for k in range (0, pop):
            if temp2 + temp > 100 or temp2 + temp < 15:
                if not survive + random.randint(1, 2) > 10:
                    pop -= 1
        if food == "Herbivore" and needs*pop > 25*foodh:
            pop -= random.randint(1, pop/10)
            needs -= random.randint(15, 35)/10
        else:
            if food == "Carnivore" and needs*pop > 25*foodc:
                pop -= random.randint(1, pop/10)
                needs -= random.randint(15, 35)/10
            else:
                if food == "Omnivore" and needs*pop > 25*(foodc+foodh):
                    pop -= random.randint(1, pop/10)
                    needs -= random.randint(15, 35)/10
                    
        if random.randint(0, 100) < dis+1:
            pop = random.randint(0, 1)+pop/10

        for l in range (0, pop):
            if food == "Carnivore":
                if fight > random.randint(3, 6):
                    foodc +=0.05
            elif food == "Herbivore":
                if fight < random.randint(5, 8) and speed < random.randint(4, 9):
                    pop -= 1
                    fight += 0.1
            elif food == "Omnivore":
                if fight > random.randint(3, 6):
                    foodc +=0.05
                if fight < random.randint(5, 8):
                    pop -= 1
                    fight += 0/1

        monthsmore -= 1
        if monthsmore == 0:
            for i in range (0, pop/2):
                pop += repnumb
                x = random.randint(3, 9)
                x -= 6
                x = x//1000
                height += x
                y = random.randint(2, 6)
                y -= 4
                y = y/1000
                weight += y
                if random.randint(0, 200) == 1:
                    if food == "Carnivore":
                        foodc += 0.02
                    elif food == "Herbivore":
                        foodh += 0.02
            monthsmore = reptime

        if height > bonus and food == "Herbivore":
            foodh += 5

        if weight > 75*survive:
            pop -= 5
            weight -= 10

        if weight < 20*survive:
            pop -= 5
            weight += 10

    if pop < 50:
        pop -= random.randint(0, 25)
    elif pop < 150:
        pop -= random.randint(0, 50)
    else:
        pop -= random.randint(1, pop/10)
    if yearsleft == 0:
        scaler = random.randint(95, 105)
        scaler = scaler/100
        pop -= oldpop*scaler

    if pop < 1:
        print "Your species went extinct.  They had average height ", height, "inches, weight ", weight, "pounds, and survived for ", yearsdone, " years.  Please close the IDLE and play again!"
        extinct = True
    else:
        yearsdone += 1
        print yearsdone, " years have passed so far.  This breed of ", name, " currently has a population of ", pop, " in the ", environment, "environment."
        
        if extinct:
            break
    if extinct:
        break


if not extinct:
    print "Your species went extinct.  They had average height ", height, " inches, and weight ", weight, " pounds.  Please close the IDLE and play again!"

That is the code.  It's about 260 lines.  To use it, just put it into a Python 2.7 document and run it.

Enjoy!

Last edited by Programmer_112 (2013-02-16 17:42:18)


http://i49.tinypic.com/rk60py.png

Offline

 

#2 2013-02-16 20:35:04

ImagineIt
Scratcher
Registered: 2011-02-28
Posts: 1000+

Re: Evonomics

I love evolution simulators.  smile

Offline

 

#3 2013-02-16 20:40:30

Programmer_112
Scratcher
Registered: 2012-02-17
Posts: 100+

Re: Evonomics

Yeah.  I'm unhappy with mine because I was too lazy to make individual beings (too much lag to test) so it killed humans off in about 2 months.  I think there is not enough credit given to adapting.  I'm gonna try to fix it soon.  Thanks for looking!

Last edited by Programmer_112 (2013-02-16 20:40:54)


http://i49.tinypic.com/rk60py.png

Offline

 

#4 2013-02-16 20:46:57

ImagineIt
Scratcher
Registered: 2011-02-28
Posts: 1000+

Re: Evonomics

Supposedly a quotation mark is invalid syntax?

Offline

 

#5 2013-02-16 20:52:29

Programmer_112
Scratcher
Registered: 2012-02-17
Posts: 100+

Re: Evonomics

ImagineIt wrote:

Supposedly a quotation mark is invalid syntax?

Are you running it in Python 2.7?  If you are, please post the error message.


http://i49.tinypic.com/rk60py.png

Offline

 

#6 2013-02-16 20:56:25

ImagineIt
Scratcher
Registered: 2011-02-28
Posts: 1000+

Re: Evonomics

Programmer_112 wrote:

ImagineIt wrote:

Supposedly a quotation mark is invalid syntax?

Are you running it in Python 2.7?  If you are, please post the error message.

3.3

Offline

 

#7 2013-02-16 21:01:25

Programmer_112
Scratcher
Registered: 2012-02-17
Posts: 100+

Re: Evonomics

ImagineIt wrote:

Programmer_112 wrote:

ImagineIt wrote:

Supposedly a quotation mark is invalid syntax?

Are you running it in Python 2.7?  If you are, please post the error message.

3.3

That might be the problem.  What does the error message say?


http://i49.tinypic.com/rk60py.png

Offline

 

#8 2013-02-16 21:02:05

zubblewu
Scratcher
Registered: 2011-02-17
Posts: 1000+

Re: Evonomics

we aren't even allowed to learn about evolution in school apparently.

sounds cool, I'll try it some time


........................................................................................................................................................................................................................................

Offline

 

#9 2013-02-16 21:05:11

Programmer_112
Scratcher
Registered: 2012-02-17
Posts: 100+

Re: Evonomics

zubblewu wrote:

we aren't even allowed to learn about evolution in school apparently.

sounds cool, I'll try it some time

That's sad.  It's a really cool subject.


http://i49.tinypic.com/rk60py.png

Offline

 

#10 2013-02-16 21:08:30

zubblewu
Scratcher
Registered: 2011-02-17
Posts: 1000+

Re: Evonomics

well I mean I already know about it but
hooray ultra relijus state


........................................................................................................................................................................................................................................

Offline

 

#11 2013-02-16 21:15:13

Programmer_112
Scratcher
Registered: 2012-02-17
Posts: 100+

Re: Evonomics

zubblewu wrote:

well I mean I already know about it but
hooray ultra relijus state

Which one?  I live in Utah, but we still learn about evolution.


http://i49.tinypic.com/rk60py.png

Offline

 

#12 2013-02-16 21:34:09

ImagineIt
Scratcher
Registered: 2011-02-28
Posts: 1000+

Re: Evonomics

Programmer_112 wrote:

ImagineIt wrote:

Programmer_112 wrote:


Are you running it in Python 2.7?  If you are, please post the error message.

3.3

That might be the problem.  What does the error message say?

invalid syntax.

Offline

 

#13 2013-02-16 21:35:13

ImagineIt
Scratcher
Registered: 2011-02-28
Posts: 1000+

Re: Evonomics

zubblewu wrote:

we aren't even allowed to learn about evolution in school apparently.

sounds cool, I'll try it some time

-_- You might as well not be allowed to learn about anything science then. Like, what if people believe that the sun rising is really God lifting it up and not the Earth rotating?

Last edited by ImagineIt (2013-02-16 21:35:46)

Offline

 

#14 2013-02-16 21:39:55

Programmer_112
Scratcher
Registered: 2012-02-17
Posts: 100+

Re: Evonomics

ImagineIt wrote:

Programmer_112 wrote:

ImagineIt wrote:


3.3

That might be the problem.  What does the error message say?

invalid syntax.

What is the code around it?  Sometimes it just gives you a approximate position


http://i49.tinypic.com/rk60py.png

Offline

 

#15 2013-02-16 22:17:37

zubblewu
Scratcher
Registered: 2011-02-17
Posts: 1000+

Re: Evonomics

ImagineIt wrote:

zubblewu wrote:

we aren't even allowed to learn about evolution in school apparently.

sounds cool, I'll try it some time

-_- You might as well not be allowed to learn about anything science then. Like, what if people believe that the sun rising is really God lifting it up and not the Earth rotating?

well I mean it may not be true. I heard it from my social studies teacher (who happens to be a communist and pastafarian) when we were talking about social darwinism so... but I wouldn't have a hard time believing it

anyway, is python 2.7 still available for download


........................................................................................................................................................................................................................................

Offline

 

#16 2013-02-16 22:17:40

soupoftomato
Scratcher
Registered: 2009-07-18
Posts: 1000+

Re: Evonomics

zubblewu wrote:

we aren't even allowed to learn about evolution in school apparently.

sounds cool, I'll try it some time

I'm in Kentucky and we learn it


I'm glad to think that the community will always be kind and helpful, the language will always be a fun and easy way to be introduced into programming, the motto will always be: Imagine, Program, Share - Nomolos

Offline

 

#17 2013-02-16 22:20:23

ImagineIt
Scratcher
Registered: 2011-02-28
Posts: 1000+

Re: Evonomics

zubblewu wrote:

ImagineIt wrote:

zubblewu wrote:

we aren't even allowed to learn about evolution in school apparently.

sounds cool, I'll try it some time

-_- You might as well not be allowed to learn about anything science then. Like, what if people believe that the sun rising is really God lifting it up and not the Earth rotating?

well I mean it may not be true. I heard it from my social studies teacher (who happens to be a communist and pastafarian) when we were talking about social darwinism so... but I wouldn't have a hard time believing it

anyway, is python 2.7 still available for download

Well there's a chance that everything may not be true. It may just be as religious people say "God's doing." Not to say I don't believe in God.

Offline

 

#18 2013-02-16 22:20:45

zubblewu
Scratcher
Registered: 2011-02-17
Posts: 1000+

Re: Evonomics

soupoftomato wrote:

zubblewu wrote:

we aren't even allowed to learn about evolution in school apparently.

sounds cool, I'll try it some time

I'm in Kentucky and we learn it

wow everyone else does it
we also can't talk about cloning


........................................................................................................................................................................................................................................

Offline

 

#19 2013-02-16 22:20:47

sonicfan12p
Scratcher
Registered: 2011-11-16
Posts: 1000+

Re: Evonomics

ImagineIt wrote:

zubblewu wrote:

we aren't even allowed to learn about evolution in school apparently.

sounds cool, I'll try it some time

-_- You might as well not be allowed to learn about anything science then. Like, what if people believe that the sun rising is really God lifting it up and not the Earth rotating?

Who believes that... tongue


Why are the secret organizations getting all the attention?  mad

Offline

 

#20 2013-02-16 22:22:00

zubblewu
Scratcher
Registered: 2011-02-17
Posts: 1000+

Re: Evonomics

sonicfan12p wrote:

ImagineIt wrote:

zubblewu wrote:

we aren't even allowed to learn about evolution in school apparently.

sounds cool, I'll try it some time

-_- You might as well not be allowed to learn about anything science then. Like, what if people believe that the sun rising is really God lifting it up and not the Earth rotating?

Who believes that... tongue

people used to believe the earth was flat
some actually still do


........................................................................................................................................................................................................................................

Offline

 

#21 2013-02-16 22:25:21

Programmer_112
Scratcher
Registered: 2012-02-17
Posts: 100+

Re: Evonomics

Back on topic, please.  I don't want this closed.


http://i49.tinypic.com/rk60py.png

Offline

 

#22 2013-02-16 22:25:26

sonicfan12p
Scratcher
Registered: 2011-11-16
Posts: 1000+

Re: Evonomics

zubblewu wrote:

sonicfan12p wrote:

ImagineIt wrote:

-_- You might as well not be allowed to learn about anything science then. Like, what if people believe that the sun rising is really God lifting it up and not the Earth rotating?

Who believes that... tongue

people used to believe the earth was flat
some actually still do

True, I guess anything can be believable to those who are prone to believe it.

Anyway, I'd love to see an Evolution simulator that actually works, without drastically changing the laws of genetics.  tongue

Last edited by sonicfan12p (2013-02-16 22:27:34)


Why are the secret organizations getting all the attention?  mad

Offline

 

#23 2013-02-16 22:29:16

zubblewu
Scratcher
Registered: 2011-02-17
Posts: 1000+

Re: Evonomics

I'd like to see one that actually simulates the DNA and the organisms development and each individual nucleotide
that might take a while to happen


........................................................................................................................................................................................................................................

Offline

 

#24 2013-02-16 22:31:35

Programmer_112
Scratcher
Registered: 2012-02-17
Posts: 100+

Re: Evonomics

sonicfan12p wrote:

zubblewu wrote:

sonicfan12p wrote:


Who believes that... tongue

people used to believe the earth was flat
some actually still do

True, I guess anything can be believable to those who are prone to believe it.

Anyway, I'd love to see an Evolution simulator that actually works, without drastically changing the laws of genetics.  tongue

I tried.  I'm working on making it better, but it doesn't work yet.  Do you have any ideas on how to improve the code without too much lag?


http://i49.tinypic.com/rk60py.png

Offline

 

#25 2013-02-16 22:34:34

Programmer_112
Scratcher
Registered: 2012-02-17
Posts: 100+

Re: Evonomics

zubblewu wrote:

I'd like to see one that actually simulates the DNA and the organisms development and each individual nucleotide
that might take a while to happen

Yep.  More than a while.


http://i49.tinypic.com/rk60py.png

Offline

 

Board footer