Honesty Rocks! truth rules.

Php Calculator That Calculates Genetic Percentages? I need help finding sites or tutorials.

HOME      >>       Programming

TheChosenDarkness

Okay, I have created, looked, and generally studied simple PHP calculators. However, I can not seem to find any tutorials on how to create a genetic calculator. One that calculates genetic percentages similar to that of Punnette Squares. I have seen plenty of websites that have these types of calculators, but I have yet to see any websites offer tutorials on how to create these types of calculators. So.. does anyone know of any tutorials I can find or sites that might have the tutorial I am looking for? Maybe even a tutorial here?Reason for asking: I am creating a website, simulation game, and one of the aspects of the game is calculating the colors of the offspring from a certain pair.Any help on the subject is greatly appreciated.Thanks in advance,TCD


galexcd

Well its been a long time since I've seen or used punnette squares, and I'm sure they are much more complicated than the simple 4 block ones that I learned, but I'll do a basic one for you.

So if I recall correctly you have dominant and recessive traits, such as dark hair or blond hair. And lets say dark is dominant. So we'll have this:

DD+bb=
100% to be Db

Db+Db=
25% to be DD
50% to be Db
25% to be bb

Db+bb=
50% to be Db
50% to be bb

Correct? (If I'm wrong tell me because it's been a while)

Anyway I would suggest an object oriented approach if you are going to be having different plants (or animals) with different traits. So first make the class life.

class life{function __construct($dom,$res){//constructors are new in php 5 so don't do this step if you are working with an older version$this->dom=$dom;$this->res=$res;}//Returns a life object when mating this object and the input objectfunction mate($life){switch(rand(0,3)){case 0:return new life($this->dom,$life->dom);case 1:return new life($this->res,$life->dom);case 2:return new life($this->dom,$life->res);case 3:return new life($this->res,$life->res);}}}

And that should do it. This code was not tested yet. Post back with any errors you find.

TheChosenDarkness

Yes. Exactly on the example about Punnette Squares. =] Also, I tested the code below and it works just fine. Now I just need to add a form to it so people can choose the color or genetics to generate the outcome. Correct?

My hosting company just recently upgraded to PHP 5. So.. I am still working on understanding certain aspects of PHP 5. Since I have been mainly studying PHP 4 and testing PHP 4.

Thank you again and the code was very helpful. ^^


TCD


Well its been a long time since I've seen or used punnette squares, and I'm sure they are much more complicated than the simple 4 block ones that I learned, but I'll do a basic one for you.
So if I recall correctly you have dominant and recessive traits, such as dark hair or blond hair. And lets say dark is dominant. So we'll have this:

DD+bb=
100% to be Db

Db+Db=
25% to be DD
50% to be Db
25% to be bb

Db+bb=
50% to be Db
50% to be bb

Correct? (If I'm wrong tell me because it's been a while)

Anyway I would suggest an object oriented approach if you are going to be having different plants (or animals) with different traits. So first make the class life.

class life{function __construct($dom,$res){//constructors are new in php 5 so don't do this step if you are working with an older version$this->dom=$dom;$this->res=$res;}//Returns a life object when mating this object and the input objectfunction mate($life){switch(rand(0,3)){case 0:return new life($this->dom,$life->dom);case 1:return new life($this->res,$life->dom);case 2:return new life($this->dom,$life->res);case 3:return new life($this->res,$life->res);}}}

And that should do it. This code was not tested yet. Post back with any errors you find.