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

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 we can 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
C# Solution: Not Answer :

Delphi/Pascal Solution Answer :

Java Solution Answer :

Python Solution: Answer :

VB.NET Solution Answer :

This code also allows for the disease spreading, and with each turn the disease will spread and there is a higher chance of rabbits dying.

VB.NET Solution (using object-oriented programming) Answer :

This code allows for the disease to spread between warrens and animals. It has no symptoms, but increases the ProbabilityOfDeathOtherCauses variable by 10%. This code was VERY QUICKLY made by Shaun Aziz and almost definitely contains lots of errors. Feel free to fix them and add your name below(preferably along with what you fixed): Nobody has yet to fix anything. :(

Natural disaster (e.g. storm or fire) affects number of animals in a given radius
C# Solution: Answer :

Delphi/Pascal Solution Answer :

Java Solution 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.

Python Solution: Answer :

VB.NET Solution Answer :

Check if input coordinates are valid
C# Solution: Answer :

Delphi/Pascal Solution Answer :

Java Solution Answer :

Python Solution: Answer :

VB.NET Solution Answer :

Display number of rabbits born that period (This question is unlikely as it is already coded into Visual Basic and Java)
(This can be done if option 1 selected when advancing time period)

C# Solution: Answer :

Delphi/Pascal Solution Answer :

Java Solution Answer :

Python Solution: Answer :

VB.NET Solution Answer :

Constraints for number of animals placed
(This can be done if option 2 selected)

C# Solution: Answer :

Delphi/Pascal Solution Answer :

Java Solution Answer :

Python Solution: Answer :

VB.NET Solution Answer :

When inspecting a fox, if there is no fox present in the given coordinates, display error message and loop coordinate input
C# Solution: Answer :

Delphi/Pascal Solution Answer :

Java Solution Answer :

Python Solution: Answer :

Python Alternative Solution: Answer :Solution: if MenuOption == 3: Select=True while Select==True: x = self.__InputCoordinate("x") y = self.__InputCoordinate("y") if not self.__Landscape[x][y].Fox is None: self.__Landscape[x][y].Fox.Inspect Select=False

VB.NET Solution

VB.NET Solution Answer :

Add a new animal (Eagles/Coyotes?) that can hunt foxes
C# Solution: Answer, includes an eagle with an adapted fox class, eagle has 25% chance of consuming closest fox, has the same fox attributes and working food/death system (it is quick and dirty, many improvements should be made):

Delphi/Pascal Solution '''Answer is incomplete at the moment. Will finish it in 2 days (Some Functionality added see below the first answer):'''

Java Solution Answer :I came up with this as a quick test. I'm sure this could be done in a more efficient way but this does work. More instructions near the bottom of this!

Python Solution: Answer :

VB.NET Solution Answer :

Foxes have a random chance to move towards the closest warren each time period
C# Solution: '''Includes a new procedure and appended AdvanceTimePeriod procedure, only problem being there is a chance foxes could be moved twice, a boolean value in the fox class which signifies if they have been moved that period or not would solve this. Answer :'''

Delphi/Pascal Solution Answer :

Java Solution Answer :

Python Solution: Answer :

VB.NET Solution Answer :

A fox moves in a random direction if they haven't eaten enough food that turn
(Could be extended to move towards nearest warren as in previous question)

C# Solution: Answer :

Delphi/Pascal Solution Answer :

Java Solution Answer :

Python Solution: Answer :#IN THE ADVANCEPERIOD if not self.__Landscape[x][y].Fox is None: if self.__Landscape[x][y].Fox.GetEatenEnoughFood is False: OldXL = x-1 OldXU = x+1 OldYL = y-1 OldYU = y+1 if x == 0: OldXL = 0 elif x == self.__LandscapeSize - 1: OldXU = self.__LandscapeSize - 1 if y == 0: OldYL = 0 elif y == self.__LandscapeSize - 1: OldYU = self.__LandscapeSize - 1 NewX = random.randint(OldXL, OldXU) NewY = random.randint(OldYL, OldYU) while not self.__Landscape[NewX][NewY].Fox is None: NewX = random.randint(OldXL, OldXU) NewY = random.randint(OldYL, OldYU) self.__Landscape[NewX][NewY].Fox = self.__Landscape[x][y].Fox self.__Landscape[x][y].Fox = None print("(",x,",",y,") has moved to (",NewX,",",NewY,")",sep="")

def __init__(self, Variability): self.__DEFAULT_LIFE_SPAN = 7 self.__DEFAULT_PROBABILITY_DEATH_OTHER_CAUSES = 0.1 super(Fox, 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 self.__EatenEnoughFood = True
 * 1) IN FOX CLASS

def AdvanceGeneration(self, ShowDetail): self.__EatenEnoughFood = True if self.__FoodUnitsConsumedThisPeriod == 0: self._IsAlive = False if ShowDetail: print(" Fox dies as has eaten no food this period.") else: if self.CheckIfKilledByOtherFactor: self._IsAlive = False if ShowDetail: print(" Fox killed by other factor.") else: if self.__FoodUnitsConsumedThisPeriod < self.__FoodUnitsNeeded: self.CalculateNewAge self.__EatenEnoughFood = False if ShowDetail: print(" Fox ages further due to lack of food.") self.CalculateNewAge if not self._IsAlive: if ShowDetail: print(" Fox has died of old age.")

def GetEatenEnoughFood(self): return self.__EatenEnoughFood

VB.NET Solution Answer :

Answer 2:

If a fox moves, the food needed for the next time period should increase relative to how far it has travelled
C# Solution: Answer :

Delphi/Pascal Solution Answer :

Java Solution Answer :

Python Solution: Answer :

VB.NET Solution Answer :

Animals need water as well as food in order to survive
C# Solution: Answer :

Delphi/Pascal Solution Answer :

Java Solution Answer :

Python Solution: Answer :

VB.NET Solution Answer :

If a fox eats more food than it needs, its reproduction rate increases
(Could be extended to cause a lower chance of movement/range of movement)

C# Solution: Answer :

Delphi/Pascal Solution Answer :

Java Solution Answer :

Python Solution: Answer :

VB.NET Solution 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.)==

C# Solution: Answer :

Delphi/Pascal Solution Answer :

Java Solution Answer :

Python Solution: Answer : class Location: def __init__(self): self.Fox = None self.Warren = None self.Mountain = None class Simulation: def __init__(self,LandscapeSize, InitialWarrenCount, InitialFoxCount, Variability, FixedInitialLocations,InitialMountainCount): self.__ViewRabbits = "" self.__TimePeriod = 0 self.__WarrenCount = 0 self.__FoxCount = 0 self.__MountainCount = 0 self.__ShowDetail = False self.__LandscapeSize = LandscapeSize self.__Variability = Variability self.__FixedInitialLocations = FixedInitialLocations self.__Landscape = [] 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 InitialMountainCount = 1 InitialWarrenCount = 5 InitialFoxCount = 5 Variability = 0 FixedInitialLocations = True else: LandscapeSize = int(input("Landscape Size: ")) InitialWarrenCount = int(input("Initial number of warrens: ")) InitialFoxCount = int(input("Initial number of foxes: ")) InitialMountainCount = int(input("Initial number of Mountains: ")) Variability = int(input("Randomness variability (percent): ")) FixedInitialLocations = False Sim = Simulation(LandscapeSize, InitialWarrenCount, InitialFoxCount, Variability, FixedInitialLocations,InitialMountainCount) input
 * 1) add relevant variables like MountainCount and InitialMountainCount into the main part of program and simulation.

class Mountain: def __init__(self): self.__MountainList=[] def CreateMountain: random=random.randint(1,99) self.__MountainList.append(random) def __DrawLandscape(self): print print("TIME PERIOD:", self.__TimePeriod) print print("  ", end = "") for x in range (0, self.__LandscapeSize): if x < 10: print(" ", end = "") print(x, "|", end = "") print for x in range (0, self.__LandscapeSize * 4 + 3): print("-", end = "") print for y in range (0, self.__LandscapeSize): if y < 10: print(" ", end = "") print("", y, "|", sep = "", end = "") for x in range (0, self.__LandscapeSize): if not self.__Landscape[x][y].Warren is None: if self.__Landscape[x][y].Warren.GetRabbitCount < 10: print(" ", end = "") print(self.__Landscape[x][y].Warren.GetRabbitCount, end = "") else: print(" ", end = "") if not self.__Landscape[x][y].Fox is None: print("F", end = "") if not self.__Landscape[x][y].Mountain is None: print("M", end = "") else: print(" ", end = "") print("|", end = "") print
 * 1) Class mountains gives mountain size for later addition where inspection will be avadiable.
 * 1) also need to edit the draw landscape function to add an M for when a mountain is present

def __CreateLandscapeAndAnimals(self, InitialWarrenCount, InitialFoxCount, FixedInitialLocations,InitialMountainCount): for x in range (0, self.__LandscapeSize): for y in range (0, self.__LandscapeSize): self.__Landscape[x][y] = Location if FixedInitialLocations: self.__Landscape[1][1].Warren = Warren(self.__Variability, 38) self.__Landscape[2][8].Warren = Warren(self.__Variability, 80) self.__Landscape[9][7].Warren = Warren(self.__Variability, 20) self.__Landscape[10][3].Warren = Warren(self.__Variability, 52) self.__Landscape[13][4].Warren = Warren(self.__Variability, 67) self.__WarrenCount = 5 self.__Landscape[2][10].Fox = Fox(self.__Variability) self.__Landscape[6][1].Fox = Fox(self.__Variability) self.__Landscape[8][6].Fox = Fox(self.__Variability) self.__Landscape[11][13].Fox = Fox(self.__Variability) self.__Landscape[12][4].Fox = Fox(self.__Variability) self.__FoxCount = 5 self.__Landscape[2][2].Mountain = Mountain self.__MountainCount = 1 else: for w in range (0, InitialWarrenCount): self.__CreateNewWarren for f in range (0, InitialFoxCount): self.__CreateNewFox for m in range (0, InitialMountainCount): self.__CreateNewMountain def __CreateNewMountain(self): x = random.randint(0, self.__LandscapeSize - 1) y = random.randint(0, self.__LandscapeSize - 1) while not self.__Landscape[x][y].Mountain is None: x = random.randint(0, self.__LandscapeSize - 1) y = random.randint(0, self.__LandscapeSize - 1) if self.__ShowDetail: print(" You have discovered a Mountain  at (", x, ",", y, ")", sep = "") self.__Landscape[x][y].Mountain = Mountain self.__MountainCount += 1 def __CreateNewWarren(self): x = random.randint(0, self.__LandscapeSize - 1) y = random.randint(0, self.__LandscapeSize - 1) while not self.__Landscape[x][y].Warren is None and not self.__Landscape[x][y].Mountain is None: x = random.randint(0, self.__LandscapeSize - 1) y = random.randint(0, self.__LandscapeSize - 1) if self.__ShowDetail: print("New Warren at (", x, ",", y, ")", sep = "") self.__Landscape[x][y].Warren = Warren(self.__Variability) self.__WarrenCount += 1 Charles Naden-Lamb Fallibroome Academy
 * 1) lastly allow mountains to be added for default and custom settings.
 * 1) To stop warrens appearing with mountains just add this to the CreateNewWarren

VB.NET Solution Answer :

If already added another animal (e.g. Eagle), make it so that they prefer hunting around the added geographical areas. (Extension of above).
C# Solution: Answer :

Delphi/Pascal Solution Answer :

Java Solution Answer :

Python Solution: Answer :

VB.NET Solution Answer :

For reproduction to occur, there must be 2 or more of the species in adjacent cells to reproduce
C# Solution: Answer :

Delphi/Pascal Solution Answer :

Java Solution Answer :

Python Solution: Answer :

VB.NET Solution Answer :

(Extension) Make it so that all animals are able to create their own respective homes (eg Dens for foxes or nests for eagles)
C# Solution: Answer :

Delphi/Pascal Solution Answer :

Java Solution Answer :

Python Solution: Answer :

VB.NET Solution Answer :

Add a food source for rabbits (such as grass)
C# Solution: Answer :

Delphi/Pascal Solution Answer :

Java Solution Answer :

Python Solution: Answer :

VB.NET Solution Answer :

(Extension) Meteor that has a low random chance of spawning and destroys everything inside a warren and foxes (Singular Class)
C# Solution: Answer :

Delphi/Pascal Solution Answer :

Java Solution Answer :

Python Solution: Answer :

VB.NET Solution Answer :

Increase the probability of death for foxes in particular regions of the board
C# Solution: Answer :

Delphi/Pascal Solution Answer :

Java Solution Answer :

Python Solution: Answer :

VB.NET Solution Answer :

Reign Of The Giant (Too Complicated, Unlikely)
This part of the code is inspired by the computer survival game 'Don't Starve'. It features many improvements and additions to the code, some which have already been completed above. But the main feature is transforming the simulation into a game, by allowing the user to move around the landscape and interact with the Warren's, Foxes and any other Entities you may have implemented.

The list of challenges are as follows: Python Solution:Reign Of The Giant Python Solution Thomas O'Keeffe (BEEF CORP)
 * 1) Insert the player into a random location, that is unoccupied. Display the first letter of the player name on the landscape.
 * 2) Move around the landscape. You can move N,E,S,W,  for each time period. Or you can stay put.
 * 3) Add health and hunger attributes to the player. You can display these attributes via a menu option. The hunger attribute should decrease by 1 unit after each time period.
 * 4) Allow the player to fight a fox. This can only happen if the player is close to a fox (2 units), and the player must startle the fox. Foxes do not startle players. Winning the fight will result in a random amount of food gained and damage to player health. Therefore if you loose the fight the player will die and return to default simulation (spectate mode).
 * 5) Add in the Eagle class next. The Eagle can attack the player by taking a cheeky stab. This means an Eagle has the ability to move around the landscape, but there is a potential for errors in the display now. For example, if you (the player), a warren, and an Eagle are all in the same cell things are going to get west. So ensure an Eagle can't enter a cell that has a player and warren in it. There can only be one Eagle per Simulation (for now), with a 10% chance of attacking the player if it is within 2 cells. When an Eagle attacks it will decrease the players health by 10. Finally, make sure an Eagle has private attributes for it's own Health and Hunger.

Queen Elizabeth School,Kirby Lonsdale

Validate the Input Coordinate subroutine in Simulation class (EXAM Question - June 2017)
C# Solution: Answer :

Delphi/Pascal Solution Answer :

Java Solution Answer :

Python Solution: Answer :

Death by other causes increases with age for Rabbits, increase is more rapid in males. (EXAM Question - June 2017)
C# Solution: Answer :

Delphi/Pascal Solution Answer :

Java Solution Answer :

Python Solution: Answer :

Add a River on to the Landscape (EXAM Question - June 2017)
C# Solution: Answer :

Delphi/Pascal Solution Answer :

Java Solution Answer :

Python Solution: Answer :

11.1 - Program code for Location class.

11.2 - Program code for CreateLandscapeAndAnimals subroutine from the Simulation class.

11.3 - Program code for DrawLandscape subroutine from the Simulation class.

11.4 - Program code for CreateWarren and CreateNewFox subroutines from the Simulation class.

Stop the animals from crossing the River when moving (EXAM Question - June 2017)
C# Solution: Answer :

Delphi/Pascal Solution Answer :

Java Solution Answer :

Python Solution: Answer :