Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 6ac084d516
Fetching contributors…

Cannot retrieve contributors at this time

187 lines (165 sloc) 9.16 kB
public class MatingDance {
MatingDance() {
}
// gets two unique male-female pairs to test compatibility
void flirt() {
boolean twoUniques = false;
int randPpl = numPeople - 1;
flirter1 = (int)random(randPpl);
while (twoUniques == false) {
flirter2 = (int)random(randPpl);
if (flirter1 != flirter2) {
twoUniques = true;
}
}
}
// takes two results from flirt() and sees if they pass certain reproduction tests
// e.g. male-female pair? similar appearance level? same level of money?
// then returns boolean saying whether sex() will occur
boolean chemistry(int _flirter1, int _flirter2) {
boolean procreate = false;
int randomTest = (int)random(10);
if (randomTest < chemistryTolerance) {
// lots of rules
if (checkFertile(_flirter1, _flirter2)) {
if ((person[_flirter1].gender == "male" && person[_flirter2].gender == "female") || (person[_flirter2].gender == "male" && person[_flirter1].gender == "female")) {
if (abs((int)Float.parseFloat(person[_flirter1].trait.get("appearance").toString())) - abs((int)Float.parseFloat(person[_flirter2].trait.get("appearance").toString())) <= chemistryAppearanceTolerance) {
if (abs((int)Float.parseFloat(person[_flirter1].trait.get("money").toString())) - abs((int)Float.parseFloat(person[_flirter2].trait.get("money").toString())) <= chemistryMoneyTolerance) {
if (abs((int)Float.parseFloat(person[_flirter1].trait.get("religiosity").toString())) - abs((int)Float.parseFloat(person[_flirter2].trait.get("religiosity").toString())) <= chemistryReligiosityTolerance) {
procreate = true;
}
}
}
}
}
}
return procreate;
}
// takes two parents and creates an offspring person object
void sex(Person comp1, Person comp2) {
Person newPerson;
String _gender = "";
int _pickGender = (int)random(0, 1.99);
int _parent1 = comp1.uniqueID;
int _parent2 = comp2.uniqueID;
String _nationality;
switch (_pickGender) {
case 0:
_gender = "male";
break;
case 1:
_gender = "female";
break;
}
int _getNationality = (int)random(0, 4.99);
int[] percentage = {
0, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15
};
int _getMbti = (int)random(0, 99.99);
// #PeopleChange
newPerson = new Person(numPeople, percentage[_getMbti], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (int)random(90, 400), (int)random(48, 96),
0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "person"+Integer.toString(numPeople+1), _gender, _parent1,
_parent2, _getNationality, currentYear, (int)random(0, 6.99), 0, (int)random(0, 1.99), randomX(_getNationality), randomY(_getNationality));
Object characteristic, characteristic2;
for (Enumeration e = comp1.trait.keys() ; e.hasMoreElements() ;) {
characteristic = e.nextElement();
int compy1 = (int)(Float.parseFloat(comp1.trait.get(characteristic).toString()));
int compy2 = (int)(Float.parseFloat(comp2.trait.get(characteristic).toString()));
newPerson.trait.put(characteristic, punnettSquare(compy1, compy2));
}
// takes parents' traits and combines them to see what child will get
person[numPeople].strength = punnettSquare(person[_parent1].strength, person[_parent2].strength);
person[numPeople].intelligence = punnettSquare(person[_parent1].intelligence, person[_parent2].intelligence);
person[numPeople].wisdom = punnettSquare(person[_parent1].wisdom, person[_parent2].wisdom);
person[numPeople].charisma = punnettSquare(person[_parent1].charisma, person[_parent2].charisma);
person[numPeople].stamina = punnettSquare(person[_parent1].stamina, person[_parent2].stamina);
person[numPeople].wit = punnettSquare(person[_parent1].wit, person[_parent2].wit);
person[numPeople].humor = punnettSquare(person[_parent1].humor, person[_parent2].humor);
person[numPeople].education = punnettSquare(person[_parent1].education, person[_parent2].education);
person[numPeople].creativity = punnettSquare(person[_parent1].creativity, person[_parent2].creativity);
person[numPeople].responsibility = punnettSquare(person[_parent1].responsibility, person[_parent2].responsibility);
person[numPeople].discipline = punnettSquare(person[_parent1].discipline, person[_parent2].discipline);
person[numPeople].honesty = punnettSquare(person[_parent1].honesty, person[_parent2].honesty);
person[numPeople].religiosity = punnettSquare(person[_parent1].religiosity, person[_parent2].religiosity);
person[numPeople].entrepreneurialism = punnettSquare(person[_parent1].entrepreneurialism, person[_parent2].entrepreneurialism);
person[numPeople].appearance = punnettSquare(person[_parent1].appearance, person[_parent2].appearance);
person[numPeople].money = punnettSquare(person[_parent1].money, person[_parent2].money);
person[numPeople].gracefulness = punnettSquare(person[_parent1].gracefulness, person[_parent2].gracefulness);
person[numPeople].stress = punnettSquare(person[_parent1].stress, person[_parent2].stress);
person[numPeople].health = punnettSquare(person[_parent1].health, person[_parent2].health);
person[numPeople].luck = punnettSquare(person[_parent1].luck, person[_parent2].luck);
person[numPeople].talentMath = punnettSquare(person[_parent1].talentMath, person[_parent2].talentMath);
person[numPeople].talentArt = punnettSquare(person[_parent1].talentArt, person[_parent2].talentArt);
person[numPeople].talentSports = punnettSquare(person[_parent1].talentSports, person[_parent2].talentSports);
person[numPeople] = newPerson;
physics.addParticle(person[numPeople]);
springArray[numPeople] = new VerletConstrainedSpring2D(god, person[numPeople], godRL, godGravity);
springArrayGlobal[springArrayGlobalCount] = new VerletConstrainedSpring2D(person[_parent2], person[numPeople], 200, 0.005);
physics.addSpring(springArrayGlobal[springArrayGlobalCount]);
springArrayGlobalCount++;
springArrayGlobal[springArrayGlobalCount] = new VerletConstrainedSpring2D(person[_parent1], person[numPeople], 200, 0.005);
physics.addSpring(springArrayGlobal[springArrayGlobalCount]);
springArrayGlobalCount++;
int z=0;
for (int k=0;k<numPeople;k++) {
if (z < numPeople) {
newBirthSpringArray[z] = new VerletConstrainedSpring2D(person[numPeople], person[k], int(random(450, 550)), random(0.001, 0.003));
physics.addSpring(newBirthSpringArray[z]);
z++;
}
}
for (int k=0;k<numNations;k++) {
newBirthNationSpringArray[k] = new VerletConstrainedSpring2D(nation[k], person[numPeople], int(random(400, 600)), random(0.001,0.002));
physics.addSpring(newBirthNationSpringArray[k]);
}
for (int k=0;k<numReligions;k++) {
newBirthReligionSpringArray[k] = new VerletConstrainedSpring2D(religion[k], person[numPeople], int(random(200, 300)), random(0.0005, 0.0015));
physics.addSpring(newBirthReligionSpringArray[k]);
}
person[_parent1].children++;
person[_parent2].children++;
numPeople++;
populationSize++;
}
boolean beer(int _flirter1, int _flirter2) {
if ((abs((int)Float.parseFloat(person[_flirter1].trait.get("appearance").toString()) - (int)Float.parseFloat(person[_flirter2].trait.get("appearance").toString())) <= 2) && checkFertile(_flirter1, _flirter2)) {
return true;
}
else {
return false;
}
}
// can the person have a baby now?
boolean checkFertile(int _flirter1, int _flirter2) {
int female = 0;
boolean fertile = false;
if (person[_flirter1].gender == "female" && person[_flirter1].alive == true) {
female = 1;
if ((currentYear - person[_flirter1].lastBaby > gestationRate) && (person[_flirter1].age >= 18) && (person[_flirter1].age <= maxReproductiveAge) && (person[_flirter2].age >= 18)) {
fertile = true;
}
}
else if (person[_flirter2].gender == "female" && person[_flirter1].alive == true) {
female = 2;
if ((currentYear - person[_flirter2].lastBaby > gestationRate) && (person[_flirter2].age >= 18) && (person[_flirter2].age <= maxReproductiveAge) && (person[_flirter1].age >= 18)) {
fertile = true;
}
}
return fertile;
}
int punnettSquare(int comp1, int comp2) {
int mutation = (int)random(0, 9.99);
int offspringTraitVal = ceil((comp1 + comp2) / 2);
if (mutation < 3) {
offspringTraitVal += (int)random(-2, 2);
}
if (offspringTraitVal < 1) {
offspringTraitVal = 1;
}
if (offspringTraitVal > 10) {
offspringTraitVal = 10;
}
//System.out.println(comp1 + " " + comp2 + " " + offspringTraitVal);
return offspringTraitVal;
}
}
Jump to Line
Something went wrong with that request. Please try again.