package net.perdue.setisim; /** * COPYRIGHT 2002 TIM PERDUE * RELEASED UNDER GPL (GNU General Public License) * * PLEASE CONTRIBUTE YOUR CHANGES TO tim@perdue.net * * Creation date: (9/13/2002 6:12:41 PM) * @author: Tim Perdue */ import java.util.*; public class Civilization { private Galaxy galaxy; private double startYear; private int baseX; private int baseY; private double endYear = 0; private int radius = 0; private static double probability=0.0; /** * Insert the method's description here. * Creation date: (9/13/2002 7:29:02 PM) * @param param net.perdue.setisim.Galaxy */ public Civilization(Galaxy galaxy) { setGalaxy(galaxy); initialCalcs(); } /** * Insert the method's description here. * Creation date: (9/13/2002 9:30:32 PM) */ public void calc() { // If this civilization is already destroyed, // don't bother running the odds again if (getEndYear() > 0) { return; } else if (getGalaxy().getYear()-getStartYear() > getGalaxy().getPermanenceThreshold()) { // // Past the destruction threshold // radius += (getGalaxy().getSpeed() * getGalaxy().getSpeedFactor()); } else { // // How far has this civilization spread? // radius += (getGalaxy().getSpeed() * getGalaxy().getSpeedFactor()); //1-((999/1000)^N) if (probability == 0.0) { System.out.println("Probability of survival 1 year: " + (double)(1.0-(1.0 / (double)getGalaxy().getL()))); System.out.println("Probability of death 1 year: " + (double)(1.0 / (double)getGalaxy().getL())); System.out.println("L: " + getGalaxy().getL()); System.out.println("Speed Factor: " + (double)getGalaxy().getSpeedFactor()); //System.out.println("Probability of death: " + (( 1-(1 / getGalaxy().getL()) )^ (int)getGalaxy().getSpeedFactor())); probability = 1.0 - java.lang.Math.pow( (double)1.0-(1.0 / (double)getGalaxy().getL()) , (double)getGalaxy().getSpeedFactor()); System.out.println("Probability of death with speedFactor: " + probability); } // // choose a random number to see if it should die // if ( getGalaxy().getRandom().nextDouble() <= probability ) { setEndYear(getGalaxy().getYear()); //System.out.println("Dead: " + (long)(getEndYear() - getStartYear()) + " Distance: " + radius); } } } /** * Insert the method's description here. * Creation date: (9/13/2002 9:20:47 PM) * @return int */ public int getBaseX() { return baseX; } /** * Insert the method's description here. * Creation date: (9/13/2002 9:21:28 PM) * @return int */ public int getBaseY() { return baseY; } /** * Insert the method's description here. * Creation date: (9/13/2002 9:33:32 PM) * @return double */ public double getEndYear() { return endYear; } /** * Insert the method's description here. * Creation date: (9/13/2002 7:29:32 PM) * @return net.perdue.setisim.Galaxy */ public Galaxy getGalaxy() { return galaxy; } /** * Insert the method's description here. * Creation date: (9/13/2002 9:35:55 PM) * @return int */ public int getRadius() { return radius; } /** * Insert the method's description here. * Creation date: (9/13/2002 7:29:54 PM) * @return double */ public double getStartYear() { return startYear; } /** * Insert the method's description here. * Creation date: (9/13/2002 7:41:24 PM) */ private void initialCalcs() { setStartYear(getGalaxy().getYear()); setBaseX((int) ((getGalaxy().getRandom().nextGaussian()/3)*getGalaxy().getRadius()+getGalaxy().getRadius())); setBaseY((int) ((getGalaxy().getRandom().nextGaussian()/3)*getGalaxy().getRadius()+getGalaxy().getRadius())); } /** * Insert the method's description here. * Creation date: (9/13/2002 9:20:47 PM) * @param newBaseX int */ private void setBaseX(int newBaseX) { baseX = newBaseX; //System.out.println("BaseX: " + baseX); } /** * Insert the method's description here. * Creation date: (9/13/2002 9:21:28 PM) * @param newBaseY int */ private void setBaseY(int newBaseY) { baseY = newBaseY; //System.out.println("BaseY: " + baseY); } /** * Insert the method's description here. * Creation date: (9/13/2002 9:33:32 PM) * @param newEndYear double */ private void setEndYear(double newEndYear) { endYear = newEndYear; } /** * Insert the method's description here. * Creation date: (9/13/2002 7:29:32 PM) * @param newGalaxy net.perdue.setisim.Galaxy */ private void setGalaxy(Galaxy newGalaxy) { galaxy = newGalaxy; } /** * Insert the method's description here. * Creation date: (9/13/2002 9:35:55 PM) * @param newRadius int */ private void setRadius(int newRadius) { radius = newRadius; } /** * Insert the method's description here. * Creation date: (9/13/2002 7:29:54 PM) * @param newStartYear double */ private void setStartYear(double newStartYear) { startYear = newStartYear; } }