import java.io.*;
public class World
{
private int size;
private Individual[][] myWorld;
private Random numGen = new Random();
/**
* This is the default constructor that creates a World of one element holding one default Individual.
*
* @since 1.6
*/
public World()
{
this.size = 1;
this.myWorld = new Individual[1][1];
for( i = 0; i < myWorld.length, i++)
{
for( j = 0, j < myWorld[0].length, j++)
{
this.myWorld[i][j] = Individual()
}
}
}//end constructor
/**
* This constructor creates a World to the given size filled with the given amount of good Individuals, or Individuals with a postive gentleness.
* The remaining spaces left in the world are filled with bad Individuals, or Individuals with a negative gentleness.
*
* @param n is the size of the world to create.
* @param g is the number of good Individuals to put into the world.
* @since 1.6
*/
public World(int n, int g)
{
this.size = n;
this.myWorld = new Individual[sqrt(n)][sqrt(n)];
int b = (n^2) - g;
for(i = 0, i < g, i++)
{
Individual goodGuy = new Indivdual(numGen.nextInt(100), numGen.nextInt(100));
myWorld[numGen.nextInt(sqrt(n))][numGen.nextInt(sqrt(n))] = goodGuy;
}
for(j = 0, j < b, j++)
{
Individual badGuy = new Individual(numGen.nextInt(100), (numGen.nextInt(100) * -1));
myWorld[numGen.nextInt(sqrt(n))][numGen.nextInt(sqrt(n))] = badGuy;
}
}//end constructor
/**
* This constructor creates a World filled with Individuals based on the data in the given file.
*
* @param fileName is the file to gather the information about the world to be created.
* @since 1.6
*/
public World(String fileName)
{
Scanner inFile = new Scanner(new FileReader("fileName"));
this.size = inFile.nextInt();
this.myWorld = new Individual[sqrt(this.size)][sqrt(this.size)];
for(i = 0, myWorld.length, i++)
{
for(j=0, myWorld[0].length, j++)
{
myWorld[i][j] = new Individual(numGen.nextInt(100), inFIle.next());
}
}
inFile.close()
}//end constructor
/**
* This accessor method returns the current size of the World.
*
* @since 1.6
*/
public void getSize()
{
return this.size;
}
end accessor
/**
* This accessor method returns a textual representation of the World.
*
* @since 1.6
*/
public void printWorld()
{
int counter = 0;
for(i = 0, i < sqrt(this.size), i++)
{
for (j = 0, j < sqrt(this.size), j++)
{
myWorld[i][j].printIndividual();
System.out.print(" ");
counter++;
if(counter > sqrt(this.size))
{
System.out.println();
counter = 0;
}
}//end method
/**
* This method returns the current number of good Individuals in the world.
*
* @since 1.6
*/
public int countsGood()
{
int goodCount = 0;
for(i = 0, i < sqrt(this.size), i++)
{
for (j = 0, j < sqrt(this.size), j++)
{
if(myWorld[i][j] > 0)
goodCount++;
}
return goodCount;
}//end method
/**
* This method returns the current number of bad Individuals in the world.
*
* @since 1.6
*/
public int countsBad()
{
int bad count = 0;
for(i = 0, i < sqrt(this.size), i++)
{
for (j = 0, j < sqrt(this.size), j++)
{
if(myWorld[i][j] < 0)
badCount++;
}
return badCount;
}//end method
}//end World object