A-level Computing/AQA/Paper 1/Skeleton program/2017

From Wikibooks, open books for an open world
Jump to: navigation, search

This is for the new Computer Science Specification. Keep in mind that there is another Comp1 exam for Computing (for retakes?) though this specific page is for the new course.

This is where suggestions can be made about what some of the questions might be and how can we solve them.

Please be respectful and do not vandalise or tamper with the page, as this would affect students' preparation for their exams!

Add a way for a disease to kill rabbits in warrens[edit]

Natural disaster (eg Storm or Fire) affects number of animals in a given radius[edit]

C# Solution:

Answer :

Answer :

        private void AdvanceTimePeriod()
        {
            int NewFoxCount = 0;
            if (ShowDetail)
            {
                Console.WriteLine();
            }
            //Start of Fire//
            if (Rnd.Next(1, 5) <= 2)
            {
                int x, y, z;
                int PercentageToKill = 33;
                int radius = 2;
                x = Rnd.Next(0, LandscapeSize);
                y = Rnd.Next(0, LandscapeSize);
                Console.WriteLine("Fire at (" + x + "," + y + ")");
                for (int Xco = x - radius; Xco <= x + radius; Xco++)
                {
                    for (int Yco = y - radius; Yco <= y + radius; Yco++)
                    {
                        try {
                            if (Landscape[Xco, Yco].Warren != null)
                            {
                                int RabbitsToKill = Landscape[Xco, Yco].Warren.GetRabbitCount() * PercentageToKill / 100;
                                Landscape[Xco, Yco].Warren.EatRabbits(RabbitsToKill);
                                if (ShowDetail)
                                {
                                    Console.WriteLine(PercentageToKill + "% rabbits killed in Warren at (" + Xco + "," + Yco + ")");
                                }
                            }
                        }
                        catch { }
                    }
                }
            }
            //End of Fire//

Delphi/Pascal Solution

Answer :

Answer :

//Start of Fire
    if (Random(20) <= 2) then
    begin
      FRadius := Random(5);
      PercentToKill := Random(100);
      xFire := Random(LandscapeSize);
      yFire := Random(LandscapeSize);

      Writeln('A fire has occured at (', XFire,',', YFire,')');

      for Xco := (xFire - FRadius) to (xFire + FRadius) do
        Begin
          for Yco := (yFire - FRadius) to (yFire + FRadius) do
            begin
            try
              begin
                if not(Landscape[Xco][Yco].Warren = nil) then
                  begin
                    RabbitsToKill := Round(Landscape[Xco][Yco].Warren.GetRabbitCount() * PercentToKill / 100);
                    Landscape[Xco][Yco].Warren.EatRabbits(RabbitsToKill);
                    
                    if (ShowDetail) then
                      Writeln(RabbitsToKill, ' have died in the fire at (', Xco, ',', Yco, ')');
                  end;
              end;
            except
            end;
          end;
        end;
      end;
//End of Fire

//Harry Barron, Faringdon Community College

Java Solution

Answer :

Answer :

This method needs to be called from somewhere. I added an option in the simulation menu to execute the storm code. If you call the storm via the menu like I did, then other factors such as the rabbits dying from natural causes and being eaten still happen for the warrens affected.

    private void StormLocation(){
        int locationX = Rnd.nextInt(LandscapeSize);
        int locationY = Rnd.nextInt(LandscapeSize);
        int radius = 5;
        System.out.println("Storm At: "+locationX+","+locationY + ", Radius:" + radius);
        for(int LocCentreY = locationY-(int) Math.floor(radius/2), endpoint = locationY+(int) Math.floor(radius/2); LocCentreY < endpoint+1; LocCentreY++){
            if(LocCentreY > 0 && LocCentreY < LandscapeSize){
                for(int LocCentreX = locationX-(int) Math.floor(radius/2), endpointX = locationX+(int) Math.floor(radius/2); LocCentreX < endpointX+1; LocCentreX++){
                    if(LocCentreX > 0 && LocCentreX < LandscapeSize){

                        if(Landscape[LocCentreX][LocCentreY].Warren != null){
                            int percentage = Rnd.nextInt(100);
                            int rabbitCount = Landscape[LocCentreX][LocCentreY].Warren.GetRabbitCount();
                            int rabbitcountnew = rabbitCount * percentage/100;
                            Landscape[LocCentreX][LocCentreY].Warren.EatRabbits(rabbitCount-rabbitcountnew);
                            System.out.println("Warren At "+LocCentreX+","+LocCentreY+" Was hit by the storm, lowering the rabbit count from "+rabbitCount+" to "+ rabbitcountnew);

                        }
                    }
                }
            }
        }
    }
// Joel LB, Twyford Sixth Form

Python Solution:

Answer :

Answer :

"""FIRE TRIGGER BASED ON RANDOM CHANCE
          INSERT AT START of AdvanceTimePeriod"""
    if random.randint(1,5) <= 2:
      self.fire(self.__LandscapeSize)

"""FIRE SUBROUTINE"""
  def fire(self, LandscapeSize):
    x = 9#random.randint(0,LandscapeSize)
    y = 5#random.randint(0, LandscapeSize)
    radius = random.randint(1,3)
    PercentageKill = 40
    print(radius, "Fire starts at (" + str(x) + "," + str(y) + ")")

    for xAxis in range(x - radius, x + radius):
      for yAxis in range(y - radius, y + radius):
        if 0 < xAxis < LandscapeSize and 0 < yAxis < LandscapeSize:
          if not self.__Landscape[xAxis][yAxis].Warren is None:
            rabbitDeaths = self.__Landscape[xAxis][yAxis].Warren.GetRabbitCount() * PercentageKill // 100
            self.__Landscape[xAxis][yAxis].Warren.EatRabbits(rabbitDeaths)

            if self.__ShowDetail:
              print(rabbitDeaths, "rabbits have met a grizzly end at (" + str(xAxis) + "," + str(yAxis) + ")")

##Alvise and Matt, Budmouth College

VB.NET Solution

Answer :

Answer :

Private Sub AdvanceTimePeriod()
           Dim num As Integer
           Randomize()
           num = (Rnd.Next(1, 5) <= 2)
           Dim NewFoxCount As Integer = 0
           If ShowDetail Then
               Console.WriteLine()
           End If
           If (num <= 2) Then
               Dim x As Integer
               Dim y As Integer
               Dim percentagetokill As Integer
               Dim radius As Integer
               Dim xco As Integer
               Dim yco As Integer
               Dim Rabbitstokill As Integer
               percentagetokill = 33
               radius = 2
               x = Rnd.Next(0, LandscapeSize)
               y = Rnd.Next(0, LandscapeSize)
               Console.WriteLine("Fire at" & x & "," & y)
               For xco = x - radius To x + radius
                   For yco = y - radius To y + radius
                       If (Landscape(xco, yco).Warren IsNot Nothing) Then
                           Rabbitstokill = (Landscape(xco, yco).Warren.GetRabbitCount()) * (percentagetokill / 100)
                           Landscape(xco, yco).Warren.EatRabbits(Rabbitstokill)
                           If (ShowDetail) Then
                               Console.WriteLine(percentagetokill & "% rabbits killed in warren at" & xco & " " & yco)
                           End If
                       End If
                   Next
               Next
           End If

'JS

Check if input coordinates are valid[edit]

C# Solution:

Answer :

Answer :

//Charles' Linq solution is slow, since it iterates through the entire range and checks for equality.
//Other solutions use a try-catch block, which is bad practice, since exception throwing should be avoided
//unless a genuinely unforeseeable problem has occurred.
//My Solution: (by Samuel Collins):
private int InputCoordinate(char Coordinatename)
{
    int Coordinate;
    Console.Write("  Input " + Coordinatename + " coordinate: ");
    while (!int.TryParse(Console.ReadLine(), out Coordinate) || Coordinate >= LandscapeSize || Coordinate < 0)
        Console.Write($"Invalid Input. Enter an integer from 0 to {LandscapeSize - 1}: ");
    return Coordinate;
}
//Note: string interpolation requires C# 6/7. The same behaviour can be achieved using + symbols in earlier versions.


//Written by Charles Batten using Linq for coordinate range chceking
using System.Linq;
private int InputCoordinate(char Coordinatename)
{
   while (true)
   {
      Console.WriteLine("Enter the {0} coordinate:", Coordinatename);
      bool succeeded = Int32.TryParse(Console.ReadLine(), out int coordinate);

      if(succeeded && Enumerable.Range(0, LandscapeSize).Contains(coordinate))
      {
         return coordinate;
      }
      else
      {
         Console.WriteLine("The coordinate you entered was invalid.");
         Console.WriteLine("Please enter an integer between 0 and {0}", (LandscapeSize - 1));
      }
   }
}

//In Response To Luke's Attempt, I attempted to solve the problem and developed the following solution.
        private int InputCoordinate(char Coordinatename)
        {
            bool invalidInput = true;
            int Coordinate = 0;
            Console.Write("  Input " + Coordinatename + " coordinate: ");
            try
            {
                Coordinate = Convert.ToInt32(Console.ReadLine());
                do
                {
                    if (Coordinate > LandscapeSize)
                    {
                        Console.Write("Invalid Input Please Input A Value smaller than " + LandscapeSize + ": ");
                        Coordinate = Convert.ToInt32(Console.ReadLine());
                    }
                }
                while (Coordinate > LandscapeSize);
            }
            catch
            {
                Console.Write("Invalid Input: ");
                while(invalidInput == true)
                {
                    try
                    {
                        Coordinate = Convert.ToInt32(Console.ReadLine());
                        invalidInput = false;
                    }
                    catch
                    {
                     //Continues Loop If Invalid Input
                     invalidInput = true;
                    }
                }
            }
            return Coordinate;
        }
//Declyn Sealey, St Mary's College

//For a better solution:
        private int InputCoordinate(char Coordinatename)
        {
            int Coordinate = 0;
            while (true)
            {
                Console.Write("  Input " + Coordinatename + " coordinate: ");
                try
                {
                    Coordinate = Convert.ToInt32(Console.ReadLine());
                    if (0 <= Coordinate && Coordinate < LandscapeSize)
                    {
                        break;
                    }
                    else
                    {
                        Console.Write("Invalid Input. Try again");
                    }
                }
                catch
                {
                    Console.Write("Invalid Input. Try again");
                }
            }
            return Coordinate;
        }

Delphi/Pascal Solution

Answer :

Answer :

Java Solution

Answer :

Answer :

 private int InputCoordinate(char CoordinateName)
    {
        int Coordinate;
        Coordinate = Console.readInteger("  Input " + CoordinateName + " coordinate: ");
        while ( Coordinate < 0 || Coordinate > LandscapeSize ){
        	Console.println("This coordinate is not on the board, enter again.");
        	Coordinate = Console.readInteger("  Input " + CoordinateName + " coordinate: ");
        }
        return Coordinate;
    }

//This is the alternative solution and works by checking the coordinates for menu options 3 and 4, this is worse but still works:
            if (MenuOption == 3)
            {
                x = InputCoordinate('x');
                y = InputCoordinate('y');
               while ( x > LandscapeSize || x < 0 || y > LandscapeSize || y < 0){// validation
            	   Console.println("Sorry these coordinates are invalid, enter again");
            	   x = InputCoordinate('x');
                   y = InputCoordinate('y');
               }
                if (Landscape[x][y].Fox != null)
                {
                    Landscape[x][y].Fox.Inspect();
                }
               
             	   
            }
            if (MenuOption == 4)
            {
                x = InputCoordinate('x');
                y = InputCoordinate('y');
                while ( x > LandscapeSize || x < 0 || y > LandscapeSize || y < 0){// validation
             	   Console.println("Sorry these coordinates are invalid, enter again");
             	   x = InputCoordinate('x');
                    y = InputCoordinate('y');
                }
                if (Landscape[x][y].Warren != null )
                {
                    Landscape[x][y].Warren.Inspect();
                    ViewRabbits = Console.readLine("View individual rabbits (y/n)?");
                    if ( ViewRabbits.equals("y") )
                    {
                        Landscape[x][y].Warren.ListRabbits();
                    }
                }
            }

Python Solution:

Answer :

Answer :

  def __InputCoordinate(self, CoordinateName):
    while True:
      try:
        # Attempt to parse the input string as an integer
        Coordinate = int(input("  Input " + CoordinateName + " coordinate:"))
      except:
        # If parsing failed print the line and start the next iteration of the loop
        print("Input co-ordinate not an integer")
        continue
      # Once parsing was successful, check the integer is between 0 and the LandscapeSize
      if Coordinate in range(self.__LandscapeSize):
        # Break from the loop on success
        break
      else:
        # If the integer is not within the valid limits, print an error and go to the next loop iteration
        print("Co-ordinate must be between 0 and {0} inclusive".format(self.__LandscapeSize - 1))
    return Coordinate

VB.NET Solution

Answer :

Answer :

    Private Function InputCoordinate(ByVal CoordinateName As Char) As Integer
        Dim Coordinate As Integer
        Do
            Console.Write("  Input " & CoordinateName & " coordinate: ")
            Coordinate = CInt(Console.ReadLine())
            'Checks to see if the Input is within the bounds of the map
        Loop Until Coordinate < LandscapeSize And Coordinate >= 0
        Return Coordinate
    End Function

Display number of rabbits born that period[edit]

(This can be done if option 2 selected when advancing time period)

C# Solution:

Answer :

Answer :

    private void AdvanceTimePeriod()
    {
			int newRabbitsBorn = 0;
      int NewFoxCount = 0; //Stores the number of new rabbits in a period
      if (ShowDetail)
      {
        Console.WriteLine();
      }
      for (int x = 0; x < LandscapeSize; x++)
      {
        for (int y = 0; y < LandscapeSize; y++)
        {
          if (Landscape[x, y].Warren != null)
          {
            if (ShowDetail)
            {
              Console.WriteLine("Warren at (" + x + "," + y + "):");
              Console.Write("  Period Start: ");
              Landscape[x, y].Warren.Inspect();
            }
            if (FoxCount > 0)
            {
              FoxesEatRabbitsInWarren(x, y);
            }
            if (Landscape[x, y].Warren.NeedToCreateNewWarren())
            {
              CreateNewWarren();
            }
            Landscape[x, y].Warren.AdvanceGeneration(ShowDetail);
            if (ShowDetail)
            {
              Console.Write("  Period End: ");
              Landscape[x, y].Warren.Inspect();
              Console.ReadKey();
            }
            if (Landscape[x, y].Warren.WarrenHasDiedOut())
            {
              Landscape[x, y].Warren = null;
              WarrenCount--;
            }

						newRabbitsBorn = newRabbitsBorn + Landscape[x, y].Warren.getNewRabbitsBorn(); //Adds up new rabbits born from each warren
						Landscape[x, y].Warren.resetNewRabbitsBorn(); //set back to 0

          }
        }
      }
			Console.WriteLine("Total number of rabbits born this period: " + newRabbitsBorn);
			newRabbitsBorn = 0;
//Rest of AdvanceTimePeriod() for Foxes

class Warren
  {
		public int totalRabbitsBorn = 0;
//Other Variables
private void MateRabbits(bool ShowDetail)
    {
      int Mate = 0;
      int Babies = 0;
      double CombinedReproductionRate;
      for (int r = 0; r < RabbitCount; r++)
      {
        if ((Rabbits[r].IsFemale()) && (RabbitCount + Babies < MaxRabbitsInWarren))
        {
          do
          {
            Mate = Rnd.Next(0, RabbitCount);
          } while ((Mate == r) || (Rabbits[Mate].IsFemale()));
          CombinedReproductionRate = (Rabbits[r].GetReproductionRate() + Rabbits[Mate].GetReproductionRate()) / 2;
          if (CombinedReproductionRate >= 1)
          {
            Rabbits[RabbitCount + Babies] = new Rabbit(Variability, CombinedReproductionRate);
						Babies++;
						totalRabbitsBorn++;
          }
        }
      }
      RabbitCount = RabbitCount + Babies;
      if (ShowDetail)
      {
        Console.WriteLine("  " + Babies + " baby rabbits born.");
      }
    }
		public int getNewRabbitsBorn()
		{
			return totalRabbitsBorn;
		}
		public void resetNewRabbitsBorn()
		{
			totalRabbitsBorn = 0;
		}

//Alex Marchant, UTC Reading

Delphi/Pascal Solution

Answer :

Answer :

Java Solution

Answer :

Answer :

Python Solution:

Answer :

Answer :

  """Add NewRabbitsThisPeriod to the start of AdvanceTimePeriod,
  it will reset every time period"""
  NewRabbitsThisPeriod = 0

  """Add Return Babies to the end of MateBabies"""
  Return Babies

  """In AdvanceGeneration Set NewRabbits equal to MateRabbits on the line MateRabbits is currently on. Return NewRabbits at the end of the line"""
  NewRabbits = self.__MateRabbits(ShowDetail)
  Return NewRabbits

  """in AdvanceTimePeriod Add the return Value of AdvanceGeneraton to NewRabbitsThisPeriod. Print if show detail after the the first double for Loop"""
  NewRabbitsThisPeriod += self.__Landscape[x][y].Warren.AdvanceGeneration(self.__ShowDetail)
  if self.__ShowDetail:
  print("New Rabbits Born: " + str(NewRabbitsThisPeriod))
#Jordan, Budmouth College

VB.NET Solution

Answer :

Answer :

Constraints for number of animals placed[edit]

(This can be done if option 2 selected)

C# Solution:

Answer :

Answer :

                   class Program
    {
        static void Main(string[] args)
        {
            Simulation Sim;
            int MenuOption = 0;
            int LandscapeSize;
            int InitialWarrenCount;
            int InitialFoxCount;
            int Variability;
            bool FixedInitialLocations;

            do
            {
                Console.WriteLine("Predator Prey Simulation Main Menu");
                Console.WriteLine();
                Console.WriteLine("1. Run simulation with default settings");
                Console.WriteLine("2. Run simulation with custom settings");
                Console.WriteLine("3. Exit");
                Console.WriteLine();
                Console.Write("Select option: ");
                try
                {
                    MenuOption = Convert.ToInt32(Console.ReadLine());
                }
                catch
                {   bool validInput = false;
                    while(validInput == false)
                    {
                        Console.WriteLine("Invalid Input Please Try Again: ");
                        try
                        {
                            MenuOption = Convert.ToInt32(Console.ReadLine());
                            validInput = true;
                        }
                        catch
                        {
                        }
                    }
                }
                if ((MenuOption == 1) || (MenuOption == 2))
                {
                    if (MenuOption == 1)
                    {
                        LandscapeSize = 15;
                        InitialWarrenCount = 5;
                        InitialFoxCount = 5;
                        Variability = 0;
                        FixedInitialLocations = true;
                    }
                    else
                    {
                        Console.Write("Landscape Size: ");
                        LandscapeSize = Convert.ToInt32(Console.ReadLine());
                        Console.Write("Initial number of warrens: ");
                        InitialWarrenCount = Convert.ToInt32(Console.ReadLine());
                        while (InitialWarrenCount > 10) //Set The Limit as 10 for the InitialWarrenCount however this can be changed.
                        {
                            Console.Write("Too Many Warrens Please Input A Value Less Than 10: ");
                            InitialWarrenCount = Convert.ToInt32(Console.ReadLine());
                        }
                        Console.Write("Initial number of foxes: ");
                        InitialFoxCount = Convert.ToInt32(Console.ReadLine());
                        while(InitialFoxCount > 5) //Set The Limit as 5 for the InitialFoxCount however this can be changed.
                        {
                            Console.Write("Too Many Foxes Please Input A Value Less Than 5: ");
                            InitialFoxCount = Convert.ToInt32(Console.ReadLine());
                        }
                        Console.Write("Randomness variability (percent): ");
                        Variability = Convert.ToInt32(Console.ReadLine());
                        FixedInitialLocations = false;
                    }
                    Sim = new Simulation(LandscapeSize, InitialWarrenCount, InitialFoxCount, Variability, FixedInitialLocations);
                }
            } while (MenuOption != 3);
            Console.ReadKey();
        }
    }//Declyn Sealey, St Marys College

 static void Main(string[] args) //Allows user to input any number of warrens and foxes as long as the total 
                                 //does not exceed the total area
        {
            Simulation Sim;
            int MenuOption;
            int LandscapeSize;
            int InitialWarrenCount;
            int InitialFoxCount;
            int Variability;
            bool FixedInitialLocations;
            do
            {
                Console.WriteLine("Predator Prey Simulation Main Menu");
                Console.WriteLine();
                Console.WriteLine("1. Run simulation with default settings");
                Console.WriteLine("2. Run simulation with custom settings");
                Console.WriteLine("3. Exit");
                Console.WriteLine();
                Console.Write("Select option: ");
                MenuOption = Convert.ToInt32(Console.ReadLine());
                if ((MenuOption == 1) || (MenuOption == 2))
                {
                    if (MenuOption == 1)
                    {
                        LandscapeSize = 15;
                        InitialWarrenCount = 5;
                        InitialFoxCount = 5;
                        Variability = 0;
                        FixedInitialLocations = true;
                    }
                    else
                    {
                        Console.Write("Landscape Size: ");
                        LandscapeSize = Convert.ToInt32(Console.ReadLine());
                        int MaxWarren = LandscapeSize * LandscapeSize; //The max amount of warrens is one warren per square
                        Console.Write("Initial number of warrens: ");
                        InitialWarrenCount = Convert.ToInt32(Console.ReadLine());
                        if (InitialWarrenCount > MaxWarren) //If number is bigger than MaxWarren then user must input a smaller number 
                        {
                            Console.WriteLine("Invalid input, please enter a number less than " + MaxWarren);
                            Console.Write("Initial number of warrens: ");
                            InitialWarrenCount = Convert.ToInt32(Console.ReadLine());
                        }
                        int MaxFox = (LandscapeSize * LandscapeSize) - InitialWarrenCount + 1;  //The max amount of foxes is one fox  
                                                                                                //per left over squares
                        Console.Write("Initial number of foxes: ");                             //MaxFoxes and MaxWarrens always adds up                                                                                               
                        InitialFoxCount = Convert.ToInt32(Console.ReadLine());                  //to LandscapeSize^2
                        if (InitialFoxCount > MaxFox) //If number is bigger than MaxFox then user must input a smaller number
                        {
                            Console.WriteLine("Invalid input, please enter a number less than " + MaxFox);
                            Console.Write("Initial number of foxes: ");
                            InitialFoxCount = Convert.ToInt32(Console.ReadLine());
                        }
                        Console.Write("Randomness variability (percent): ");
                        Variability = Convert.ToInt32(Console.ReadLine());
                        FixedInitialLocations = false;
                    }
                    Sim = new Simulation(LandscapeSize, InitialWarrenCount, InitialFoxCount, Variability, FixedInitialLocations);
                }
            } while (MenuOption != 3);
            Console.ReadKey();
        }
    } //William Parkinson, Bridgwater College

Delphi/Pascal Solution

Answer :

Answer :

Java Solution

Answer :

Answer :

public class Main
{
    public static void main(String[] args) {
        Simulation Sim;
        int MenuOption;
        int LandscapeSize;
        int InitialWarrenCount;
        int InitialFoxCount;
        int Variability;
        Boolean FixedInitialLocations;
        do
        {
            Console.println("Predator Prey Simulation Main Menu");
            Console.println();
            Console.println("1. Run simulation with default settings");
            Console.println("2. Run simulation with custom settings");
            Console.println("3. Exit");
            Console.println();
            MenuOption = Console.readInteger("Select option: ");
            if (MenuOption == 1 || MenuOption == 2)
            {
                if (MenuOption == 1)
                {
                    LandscapeSize = 15;
                    InitialWarrenCount = 5;
                    InitialFoxCount = 5;
                    Variability = 0;
                    FixedInitialLocations = true;
                }
                else
                {   //Added input validation and restrictions on input like the number of inital warrens and foxes cannot be greater than the number of squares and that they have to be positive
                	LandscapeSize=-1;
                    LandscapeSize = Console.readInteger("Landscape Size: ");
                    while(LandscapeSize<0){
                    	Console.println("Please enter a number greater than 0!");
                    	LandscapeSize = Console.readInteger("Landscape Size: ");
                    }
                    
                    InitialWarrenCount=-1;
                    InitialWarrenCount = Console.readInteger("Initial number of warrens: ");
                    while(InitialWarrenCount<0 || InitialWarrenCount>=(LandscapeSize*LandscapeSize)){
                    	Console.println("Please enter a number between 0 and "+(LandscapeSize*LandscapeSize));
                    	InitialWarrenCount = Console.readInteger("Initial number of warrens: ");
                    }
                    
                    InitialFoxCount=-1; 
                    InitialFoxCount = Console.readInteger("Initial number of foxes: ");
                    while(InitialFoxCount<0 || InitialFoxCount>=(LandscapeSize*LandscapeSize)){
                    	Console.println("Please enter a number between 0 and "+(LandscapeSize*LandscapeSize));
                    	InitialFoxCount = Console.readInteger("Initial number of foxes: ");
                    }
                    
                    Variability=-2; 
                    Variability = Console.readInteger("Randomness variability (percent): ");
                    while(Variability<-1||Variability>101){
                    	Console.println("Please enter a number between 0 and 100!");
                    	 Variability = Console.readInteger("Randomness variability (percent): ");
                    }
                    
                    FixedInitialLocations = false;
                }
                Sim = new Simulation(LandscapeSize, InitialWarrenCount, InitialFoxCount, Variability, FixedInitialLocations);
            }
        } while (MenuOption != 3);
        Console.readLine();
    }
} // Gman, Reading School

Python Solution:

Answer :

Answer :

def Main():
  MenuOption = 0
  while MenuOption != 3:
    print("Predator Prey Simulation Main Menu")
    print()
    print("1. Run simulation with default settings")
    print("2. Run simulation with custom settings")
    print("3. Exit")
    print()
    MenuOption = int(input("Select option: "))
    if MenuOption == 1 or MenuOption == 2:
      if MenuOption == 1:
        LandscapeSize = 15
        InitialWarrenCount = 5
        InitialFoxCount = 5
        Variability = 0
        FixedInitialLocations = True
      else:
        LandscapeSize = int(input("Landscape Size: "))
        # ------- NEW -------
        # Store the LandscapeSize^2 in the variable 'Limit' because I'm lazy
        Limit = LandscapeSize * LandscapeSize
        
        # Get the InitialWarrenCount input and loop until it is less than the limit,
        # in this case LandscapeSize^2 as that's the max number of places on the board
        InitialWarrenCount = int(input("Initial number of warrens: "))
        while not InitialWarrenCount in range(0, Limit + 1):
            print("Please enter a value between 0 and {0} inclusive".format(Limit))
            InitialWarrenCount = int(input("Initial number of warrens: "))

        # Exactly the same deal as the warrens
        InitialFoxCount = int(input("Initial number of foxes: "))
        while not InitialFoxCount in range(0, Limit + 1):
            print("Please enter a value between 0 and {0} inclusive".format(Limit))
            InitialFoxCount = int(input("Initial number of foxes: "))
        # -------------------
        Variability = int(input("Randomness variability (percent): "))
        FixedInitialLocations = False
      Sim = Simulation(LandscapeSize, InitialWarrenCount, InitialFoxCount, Variability, FixedInitialLocations)
  input()

VB.NET Solution

Answer :

Answer :

When inspecting a fox, if there is no fox present in the given coordinates, display error message and loop coordinate input[edit]

C# Solution:

Answer :

Answer :

public Simulation(int LandscapeSize, int InitialWarrenCount, int InitialFoxCount, int Variability, bool FixedInitialLocations)
        {
            int menuOption;
            int x;
            int y;
            string viewRabbits;
            this.LandscapeSize = LandscapeSize;
            this.Variability = Variability;
            bool animalFound = false; //Bool used to make the search function loop is no animal is found.
            Landscape = new Location[LandscapeSize, LandscapeSize];
            CreateLandscapeAndAnimals(InitialWarrenCount, InitialFoxCount, FixedInitialLocations);
            DrawLandscape();

            do
            {
                Console.WriteLine();
                Console.WriteLine("1. Advance to next time period showing detail");
                Console.WriteLine("2. Advance to next time period hiding detail");
                Console.WriteLine("3. Inspect fox");
                Console.WriteLine("4. Inspect warren");
                Console.WriteLine("5. Exit");
                Console.WriteLine();
                Console.Write("Select option: ");
                menuOption = Convert.ToInt32(Console.ReadLine());

                if (menuOption == 1)
                {
                    TimePeriod++;
                    ShowDetail = true;
                    AdvanceTimePeriod();
                }
                if (menuOption == 2)
                {
                    TimePeriod++;
                    ShowDetail = false;
                    AdvanceTimePeriod();
                }
                if (menuOption == 3)
                {
                    do
                    {
                        x = InputCoordinate('x');
                        y = InputCoordinate('y');
                        if (Landscape[x, y].Fox != null)
                        {
                            animalFound = true; //Exits the loop when a fox has been found.
                            Landscape[x, y].Fox.Inspect();
                        }
                        else
                        {
                            animalFound = false;
                            //Tells the user there is no fox here.
                            Console.WriteLine("No fox found at (" + x + ", " + y + ")");

                            //Just in case they didn't mean to inspect:
                            Console.WriteLine("Would you like to continue the simulation? (y/n)");
                            if (Console.ReadLine() == "y")
                            {
                                animalFound = true;
                            }
                        }
                    }
                    while (animalFound == false);
                }
                if (menuOption == 4)
                {
                    do
                    {
                        x = InputCoordinate('x');
                        y = InputCoordinate('y');
                        if (Landscape[x, y].Warren != null)
                        {
                            animalFound = true;
                            Landscape[x, y].Warren.Inspect();
                            Console.Write("View individual rabbits (y/n)?");
                            viewRabbits = Console.ReadLine();
                            if (viewRabbits == "y")
                            {
                                Landscape[x, y].Warren.ListRabbits();
                            }
                        }
                        else
                        {
                            animalFound = false;
                            //Tells the user there is no warren here.
                            Console.WriteLine("No Warren found at (" + x + ", " + y + ")");

                            //Just in case they didn't mean to inspect:
                            Console.WriteLine("Would you like to continue the simulation? (y/n)");
                            if (Console.ReadLine() == "y")
                            {
                                animalFound = true;
                            }
                        }
                    }
                    while (animalFound == false);
                }
            }
            while (((WarrenCount > 0) || (FoxCount > 0)) && (menuOption != 5));
            Console.ReadKey();
        }
//Logan Dibnah, St Mary's College

Delphi/Pascal Solution

Answer :

Answer :

      if MenuOption = 3 then
        begin
        Repeat
          x := InputCoordinate('x');  
          y := InputCoordinate('y');  
          if not(Landscape[x][y].Fox = nil) then  
            Landscape[x][y].fox.Inspect()  
          else
          begin
            Writeln;
            Writeln('No Fox was found at this location');
            Writeln;
          end
          until not(Landscape[x][y].Fox = nil)
        end;

//Harry Barron, Faringdon Community College

Java Solution

Answer :

Answer :

if (MenuOption == 3)
            {
                x = InputCoordinate('x');
                y = InputCoordinate('y');
                
                //Validating x Co-ordinate
                while(x<0 || x>LandscapeSize){
                   System.out.println("Please enter in an x coordinate within range:");
                   x = InputCoordinate('x');
                }
                
                //Validating y Co-ordinate
                while(y<0 || y>LandscapeSize){
                   System.out.println("Please enter in an y coordinate within range:");
                   y = InputCoordinate('y');
                }
                
                //Validating that a fox is the position selected
                while (Landscape[x][y].Fox == null)
                {
                    System.out.println("Please enter in new coordinates:");
                   x = InputCoordinate('x');
                   y = InputCoordinate('y'); 
                }
                
                if(Landscape[x][y].Fox != null){
                    Landscape[x][y].Fox.Inspect();
                }
            
            }

Python Solution:

Answer :

Answer :

if MenuOption == 3:
        x = self.__InputCoordinate("x")
        y = self.__InputCoordinate("y")
        while self.__Landscape[x][y].Fox is None:
          print "Fox not found"
          x = self.__InputCoordinate("x")
          y = self.__InputCoordinate("y")
        self.__Landscape[x][y].Fox.Inspect()

VB.NET Solution

Answer :

Answer :

If MenuOption = 3 Then
                Do
                    x = InputCoordinate("x")
                    y = InputCoordinate("y")
                    'Gives repsonse when no fox is found
                    If Not Landscape(x, y).Fox Is Nothing Then
                        Landscape(x, y).Fox.Inspect()
                    Else
                        Console.WriteLine()
                        Console.WriteLine("No fox was found at this location")
                        Console.WriteLine()
                    End If
                Loop Until Not Landscape(x, y).Fox Is Nothing
            End If

Add a new animal (Eagles/Coyotes?) that can hunt foxes[edit]

C# Solution:

Answer :

Answer :

Delphi/Pascal Solution

Answer :

Answer :

Java Solution

Answer :

Answer :

Python Solution:

Answer :

Answer :

# This is a simple solution that can be improved upon with variability, making the eagles move, etc
# But as none of that is specified in the question (and it's two in the morning) I'll let you do that!
# Also worth noting is that these eagles are tanks and will pretty much destroy all foxes as they will kill all foxes with a Euclidian distance <= 5
# They also cannot die, breed or move. However, this would not be hard to implement using the animal class


# Add an Eagle property to the existing Location class
# This is so we can store instances of the Eagle in different locations in the grid
class Location:
  def __init__(self):
    self.Fox = None
    self.Warren = None
    # ---------- New ----------
    self.Eagle = None
    # -------------------------


# Add an EagleCount variable to Simulation in the init method
# This is so we can keep track of all the Eagle instances
self.__EagleCount = 0


# Create an Eagle class that inherits from Animal (I just stole the constructor from the fox but this is where you can get creative)
class Eagle(Animal):
  def __init__(self, Variability):
    self.__DEFAULT_LIFE_SPAN = 7
    self.__DEFAULT_PROBABILITY_DEATH_OTHER_CAUSES = 0.1
    super(Eagle, self).__init__(self.__DEFAULT_LIFE_SPAN, self.__DEFAULT_PROBABILITY_DEATH_OTHER_CAUSES, Variability)
    self.__FoodUnitsNeeded = int(10 * self._CalculateRandomValue(100, Variability) / 100)
    self.__FoodUnitsConsumedThisPeriod  = 0


# Add a KilledByEagle property in the Fox class (This is lazy but it works)
# It should be false by default
KilledByEagle = False


# Add the eagles in the Simulation.__CreateLandscapeAndAnimals() method
# Add the following lines of code after and outside of the FixedInitialLocations conditional
# Loop from 0 - n eagles that need to be placed (I hard coded 5)
# Check different Locations on the grid until it can place an eagle
for e in range(0, 5):
      x = random.randint(0, self.__LandscapeSize - 1)
      y = random.randint(0, self.__LandscapeSize - 1)

      while not self.__Landscape[x][y].Eagle is None:
        x = random.randint(0, self.__LandscapeSize - 1)
        y = random.randint(0, self.__LandscapeSize - 1)

      if self.__ShowDetail:
        print("New Eagle at ({0}, {1})".format(x, y))

      self.__Landscape[x][y].Eagle = Eagle(self.__Variability)
      self.__EagleCount += 1


# Overwrite the CheckIfKilledByOtherFactor() method in the fox class, inherited from the animal class
# Add a conditional to check if Fox.KilledByEagle is true. If not run the original method and return its values
# Reference the parent class method using super(Fox, self)
def CheckIfKilledByOtherFactor(self):
    if self.KilledByEagle:
      print("Eagles killed fox!")
      self._IsAlive = False
      return True
    else:
      return super(Fox, self).CheckIfKilledByOtherFactor()


# Create an __EaglesEatFox() method in Simulation that takes a fox's x and y
# It will loop through each space in the grid and check for an eagle
# Once an eagle is found it will check the Euclidian distance between the Eagle and the Fox
# If the distance is less than 5 is will mark the Fox for death when the AdvanceGeneration() method is run on it
def __EaglesEatFox(self, foxX, foxY):
    for EagleX in range(0, self.__LandscapeSize):
      for EagleY in range(0, self.__LandscapeSize):
        if not self.__Landscape[EagleX][EagleY].Eagle is None:
          dist = self.__DistanceBetween(EagleX, EagleY, foxX, foxY)
          # print("Distance = {0}".format(dist))

          if dist <= 5:
            self.__Landscape[foxX][foxY].Fox.KilledByEagle = True


# In Simulation().__AdvanceTimePeriod() run the __EaglesEatFox() method just before the AdvanceGeneration method is run on the fox (in the second set of loops)
# Pass it the current X and Y coordinates of the fox
# In this example the count will always be 5 but you could add the ability for them to breed and die
# A lot of this can be achieved using the animal class we are inheriting from
if self.__EagleCount > 0:
            self.__EaglesEatFox(x, y)

VB.NET Solution

Answer :

Answer :

//Ben Sosteric Riddlesdown
Dim InitialEagleCount As Integer
        Dim Variability As Integer
        Dim FixedInitialLocations As Boolean
        Do
            Console.WriteLine("Predator Prey Simulation Main Menu")
            Console.WriteLine()
            Console.WriteLine("1. Run simulation with default settings")
            Console.WriteLine("2. Run simulation with custom settings")
            Console.WriteLine("3. Rabbit Paradise")
            Console.WriteLine("4. Exit")
            Console.WriteLine()
            Console.Write("Select option: ")
            MenuOption = CInt(Console.ReadLine())
            If MenuOption = 1 Or MenuOption = 2 Or MenuOption = 3 Then
                If MenuOption = 1 Then
                    LandscapeSize = 14
                    InitialWarrenCount = 5
                    InitialFoxCount = 5
                    InitialEagleCount = 5
                    Variability = 0
                    FixedInitialLocations = True
                ElseIf MenuOption = 3 Then
                    LandscapeSize = 20
                    InitialWarrenCount = 20
                    InitialFoxCount = 0
                    InitialEagleCount = 0
                    Variability = 1
                    FixedInitialLocations = False

                Else
                    Console.Write("Landscape Size: ")
                    LandscapeSize = CInt(Console.ReadLine())
                    Console.Write("Initial number of warrens: ")
                    InitialWarrenCount = CInt(Console.ReadLine())
                    Console.Write("Initial number of foxes: ")
                    InitialFoxCount = CInt(Console.ReadLine())
                    Console.WriteLine("Initial number of eagles: ")
                    InitialEagleCount = CInt(Console.ReadLine)
                    Console.Write("Randomness variability (percent): ")
                    Variability = CInt(Console.ReadLine())
                    FixedInitialLocations = False
                End If
                Dim Sim As New Simulation(LandscapeSize, InitialWarrenCount, InitialFoxCount, InitialEagleCount, Variability, FixedInitialLocations)
            End If

Class Location
        Public Fox As Fox
        Public Warren As Warren
        Public Eagle As Eagles

        Public Sub New()
            Fox = Nothing
            Warren = Nothing
            Eagle = Nothing
        End Sub
    End Class

Class Simulation
        Private Landscape(,) As Location
        Private TimePeriod As Integer = 0
        Private WarrenCount As Integer = 0
        Private FoxCount As Integer = 0
        Private Eaglecount As Integer = 0
        Private ShowDetail As Boolean = False
        Private LandscapeSize As Integer
        Private Variability As Integer
        Private Shared Rnd As New Random()

        Public Sub New(ByVal LandscapeSize As Integer, ByVal InitialWarrenCount As Integer, ByVal InitialFoxCount As Integer, ByVal InitialEagleCount As Integer, ByVal Variability As Integer, ByVal FixedInitialLocations As Boolean)
            Dim MenuOption As Integer
            Dim x As Integer
            Dim y As Integer
            Dim ViewRabbits As String
            Dim checkfox As Boolean
            Me.LandscapeSize = LandscapeSize
            Me.Variability = Variability
            Landscape = New Location(LandscapeSize, LandscapeSize) {}
            CreateLandscapeAndAnimals(InitialWarrenCount, InitialFoxCount, InitialEagleCount, FixedInitialLocations)
            DrawLandscape()
            Do
                Console.WriteLine()
                Console.WriteLine("0. Advance time by 10 periods hiding detail")
                Console.WriteLine("1. Advance to next time period showing detail")
                Console.WriteLine("2. Advance to next time period hiding detail")
                Console.WriteLine("3. Inspect fox")
                Console.WriteLine("4. Inspect warren")
                Console.WriteLine("5. Inspect Eagle")
                Console.WriteLine("6. Exit")
//Under the same sub
If MenuOption = 5 Then
                    x = InputCoordinate("x")
                    y = InputCoordinate("y")
                    If Not Landscape(x, y).Eagle Is Nothing Then
                        Landscape(x, y).Eagle.Inspect()
                    End If
                End If
            Loop While (WarrenCount > 0 Or FoxCount > 0 Or Eaglecount > 0) And MenuOption <> 6
            Console.ReadKey()

 Private Sub AdvanceTimePeriod(ByVal menuoption As Integer)
            Dim NewFoxCount As Integer = 0
            Dim NewEagleCount As Integer = 0
            If ShowDetail Then
                Console.WriteLine()
            End If
            For z = 0 To 9
                If menuoption <> 0 Then
                    z = 9
                End If
                For x = 0 To LandscapeSize - 1
                    For y = 0 To LandscapeSize - 1
                        If Not Landscape(x, y).Warren Is Nothing Then
                            If ShowDetail Then
                                Console.WriteLine("Warren at (" & x & "," & y & "):")
                                Console.Write("  Period Start: ")
                                Landscape(x, y).Warren.Inspect()
                            End If
                            If FoxCount > 0 Then
                                FoxesEatRabbitsInWarren(x, y)
                            End If
                            If Eaglecount > 0 Then
                                EaglesEatFoxes(x, y)
                            End If
//Under same sub
 For x = 0 To LandscapeSize - 1
                    For y = 0 To LandscapeSize - 1
                        If Not Landscape(x, y).Eagle Is Nothing Then
                            If ShowDetail Then
                                Console.WriteLine("Eagle at (" & x & "," & y & "): ")
                            End If
                            Landscape(x, y).Eagle.AdvanceGeneration(ShowDetail)
                            If Landscape(x, y).Eagle.CheckIfDead() Then
                                Landscape(x, y).Eagle = Nothing
                                Eaglecount -= 1
                            Else
                                If Landscape(x, y).Eagle.ReproduceThisPeriod() Then
                                    If ShowDetail Then
                                        Console.WriteLine("  Eagle has reproduced. ")
                                    End If
                                    NewEagleCount += 1
                                End If
                                If ShowDetail Then
                                    Landscape(x, y).Eagle.Inspect()
                                End If
                                Landscape(x, y).Eagle.ResetFoodConsumed()
                            End If
                        End If
                    Next
                Next
                If NewEagleCount > 0 Then
                    If ShowDetail Then
                        Console.WriteLine("New Eagles born: ")
                    End If
                    For f = 0 To NewEagleCount - 1
                        CreateNewEagle()
                    Next
                End If
                If ShowDetail Then
                    Console.ReadKey()
                End If
                DrawLandscape()
                Console.WriteLine()
            Next
        End Sub

Private Sub CreateLandscapeAndAnimals(ByVal InitialWarrenCount As Integer, ByVal InitialFoxCount As Integer, ByVal InitialEagleCount As Integer, ByVal FixedInitialLocations As Boolean)

Landscape(3, 7).Eagle = New Eagles(Variability, 45)
                Landscape(4, 9).Eagle = New Eagles(Variability, 70)
                Landscape(1, 6).Eagle = New Eagles(Variability, 45)
                Landscape(8, 4).Eagle = New Eagles(Variability, 45)
                Landscape(11, 5).Eagle = New Eagles(Variability, 45)
                Eaglecount = 5
            Else
                For w = 0 To InitialWarrenCount - 1
                    CreateNewWarren()
                Next
                For f = 0 To InitialFoxCount - 1
                    CreateNewFox()
                Next
                For e = 0 To InitialEagleCount - 1
                    CreateNewEagle()
                Next
            End If
        End Sub

Private Sub CreateNewEagle()
            Dim x As Integer
            Dim y As Integer
            Do
                x = Rnd.Next(0, LandscapeSize)
                y = Rnd.Next(0, LandscapeSize)
            Loop While Not Landscape(x, y).Eagle Is Nothing
            If ShowDetail Then
                Console.WriteLine("  New Eagle at (" & x & "," & y & ")")
            End If
            Landscape(x, y).Eagle = New Eagles(Variability, 46)
            Eaglecount += 1
        End Sub

  Private Sub EaglesEatfoxes(ByVal WarrenX As Integer, ByVal WarrenY As Integer)
            Dim FoodConsumed As Integer
            Dim PercentToEat As Integer
            Dim Dist As Double
            Dim RabbitsToEat As Integer
            Dim RabbitCountAtStartOfPeriod As Integer = Landscape(WarrenX, WarrenY).Warren.GetRabbitCount()
            For EagleX = 0 To LandscapeSize - 1
                For EagleY = 0 To LandscapeSize - 1
                    If Not Landscape(EagleX, EagleY).Eagle Is Nothing Then
                        Dist = DistanceBetween(EagleX, EagleY, WarrenX, WarrenY)
                        If Dist <= 3.5 Then
                            PercentToEat = 20
                        ElseIf Dist <= 7 Then
                            PercentToEat = 10
                        Else
                            PercentToEat = 0
                        End If
                        RabbitsToEat = CInt(Math.Round(CDbl(PercentToEat * RabbitCountAtStartOfPeriod / 100)))
                        FoodConsumed = Landscape(WarrenX, WarrenY).Warren.EatRabbits(RabbitsToEat)
                        Landscape(EagleX, EagleY).Eagle.GiveFood(FoodConsumed)
                        If ShowDetail Then
                            Console.WriteLine("  " & FoodConsumed & " foxes eaten by Eagle at (" & EagleX & "," & EagleY & ").")
                        End If
                    End If
                Next
            Next
        End Sub

 Private Sub DrawLandscape()
If Not Landscape(x, y).Eagle Is Nothing Then
                        Console.Write("E")
                    Else
                        Console.Write(" ")
                    End If
                    Console.Write("|")
                Next
                Console.WriteLine()
            Next
        End Sub

Class Eagles
        Inherits Animal
        Enum Genders
            Male
            Female
        End Enum
        Private ReproductionRate As Double
        Private FoodUnitsNeeded As Integer = 10
        Private FoodUnitsConsumedThisPeriod As Integer = 0
        Private Const DefaultLifespan As Integer = 7
        Private Const DefaultProbabilityDeathOtherCauses As Double = 0.1
        Private Const GenderratioEagle As Integer = 34
        Private Gender As Genders

        Public Sub New(ByVal Variability As Integer, ByVal parentsreproductionrate As Double)
            MyBase.New(DefaultLifespan, DefaultProbabilityDeathOtherCauses, Variability)
            FoodUnitsNeeded = CInt(10 * MyBase.CalculateRandomValue(100, Variability) / 100)
            ReproductionRate = parentsreproductionrate * MyBase.CalculateRandomValue(100, Variability) / 100
            If Rnd.Next(0, 100) < GenderratioEagle Then
                Gender = Genders.Male
            Else
                Gender = Genders.Female
            End If
        End Sub

        Public Sub AdvanceGeneration(ByVal ShowDetail As Boolean)
            If FoodUnitsConsumedThisPeriod = 0 Then
                IsAlive = False
                If ShowDetail Then
                    Console.WriteLine("  Eagle dies as has eaten no food this period.")
                End If
            Else
                If CheckIfKilledByOtherFactor() Then
                    IsAlive = False
                    If ShowDetail Then
                        Console.WriteLine("  Eagle killed by other factor.")
                    End If
                Else
                    If FoodUnitsConsumedThisPeriod < FoodUnitsNeeded Then
                        CalculateNewAge()
                        If ShowDetail Then
                            Console.WriteLine("  Eagle ages further due to lack of food.")
                        End If
                    End If
                    CalculateNewAge()
                    If Not IsAlive Then
                        If ShowDetail Then
                            Console.WriteLine("  Eagle has died of old age.")
                        End If
                    End If
                End If
            End If
        End Sub

        Public Sub ResetFoodConsumed()
            FoodUnitsConsumedThisPeriod = 0
        End Sub

        Public Function ReproduceThisPeriod() As Boolean
            Const ReproductionProbability As Double = 0.10
            If Rnd.Next(0, 100) < ReproductionProbability * 100 And Gender = Genders.Female Then
                Return True
            Else
                Return False
            End If
        End Function

        Public Sub GiveFood(ByVal FoodUnits As Integer)
            FoodUnitsConsumedThisPeriod = FoodUnitsConsumedThisPeriod + FoodUnits
        End Sub

        Public Overrides Sub Inspect()
            MyBase.Inspect()
            Console.Write("Food needed " & FoodUnitsNeeded & " ")
            Console.Write("Food eaten " & FoodUnitsConsumedThisPeriod & " ")
            Console.WriteLine()
            MyBase.Inspect()
            Console.Write("Rep rate " & Math.Round(ReproductionRate, 1) & " ")
            If Gender = Genders.Female Then
                Console.WriteLine("Gender Female")
            Else
                Console.WriteLine("Gender Male")
            End If
        End Sub
    End Class

Foxes have a random chance to move towards the closest warren each time period[edit]

C# Solution:

Answer :

Answer :

Delphi/Pascal Solution

Answer :

Answer :

Java Solution

Answer :

Answer :

Python Solution:

Answer :

Answer :

VB.NET Solution

Answer :

Answer :

A fox moves in a random direction if they haven't eaten enough food that turn[edit]

(Could be extended to move towards nearest warren as in previous question)

C# Solution:

Answer :

Answer :

Delphi/Pascal Solution

Answer :

Answer :

Java Solution

Answer :

Answer :

Python Solution:

Answer :

Answer :

VB.NET Solution

Answer :

Answer :

If a fox moves, the food needed for the next time period should increase relative to how far it has traveled[edit]

C# Solution:

Answer :

Answer :

Delphi/Pascal Solution

Answer :

Answer :

Java Solution

Answer :

Answer :

Python Solution:

Answer :

Answer :

VB.NET Solution

Answer :

Answer :

Animals need water as well as food in order to survive[edit]

C# Solution:

Answer :

Answer :

Delphi/Pascal Solution

Answer :

Answer :

Java Solution

Answer :

Answer :

Python Solution:

Answer :

Answer :

VB.NET Solution

Answer :

Answer :

If a fox eats more food than it needs, its reproduction rate increases[edit]

(Could be extended to cause a lower chance of movement/range of movement)

C# Solution:

Answer :

Answer :

Delphi/Pascal Solution

Answer :

Answer :

Java Solution

Answer :

Answer :

Python Solution:

Answer :

Answer :

VB.NET Solution

Answer :

Answer :

Add geographical areas of the grid where only certain animals can survive (i.e. Mountainous regions where rabbits cannot create warrens and where it is harder for foxes to survive, but eagles can flourish, etc.)[edit]

C# Solution:

Answer :

Answer :

Delphi/Pascal Solution

Answer :

Answer :

Java Solution

Answer :

Answer :

Python Solution:

Answer :

Answer :

VB.NET Solution

Answer :

Answer :

If already added another animal (e.g. Eagle), make it so that they prefer hunting around the added geographical areas. (Extension of above).[edit]

C# Solution:

Answer :

Answer :

Delphi/Pascal Solution

Answer :

Answer :

Java Solution

Answer :

Answer :

Python Solution:

Answer :

Answer :

VB.NET Solution

Answer :

Answer :

For reproduction to occur, there must be 2 or more of the species in adjacent cells to reproduce[edit]

C# Solution:

Answer :

Answer :

Delphi/Pascal Solution

Answer :

Answer :

Java Solution

Answer :

Answer :

Python Solution:

Answer :

Answer :

VB.NET Solution

Answer :

Answer :

(Extension) Make it so that all animals are able to create their own respective homes (eg Dens for foxes or nests for eagles)[edit]

C# Solution:

Answer :

Answer :

Delphi/Pascal Solution

Answer :

Answer :

Java Solution

Answer :

Answer :

Python Solution:

Answer :

Answer :

VB.NET Solution

Answer :

Answer :


Add a food source for rabbits (such as grass)[edit]

C# Solution:

Answer :

Answer :

Delphi/Pascal Solution

Answer :

Answer :

Java Solution

Answer :

Answer :

Python Solution:

Answer :

Answer :

VB.NET Solution

Answer :

Answer :