From ee9e6f02e94edac5deac8a54e587960e2267f4b6 Mon Sep 17 00:00:00 2001 From: Alexandre LETOURNEUX Date: Fri, 31 May 2024 23:46:46 +0200 Subject: [PATCH] Delete Wolf.java --- Wolf.java | 89 ------------------------------------------------------- 1 file changed, 89 deletions(-) delete mode 100644 Wolf.java diff --git a/Wolf.java b/Wolf.java deleted file mode 100644 index f152d70..0000000 --- a/Wolf.java +++ /dev/null @@ -1,89 +0,0 @@ -package backend; -import java.awt.Color; -import java.util.ArrayList; -import java.util.Random; - -public class Wolf extends Agent { - - int hunger; - Random rand; - - Wolf(int x,int y){ - //first we call the constructor of the superClass(Animal) - super(x,y,Color.red, 50, 5); - hunger = 0; - rand = new Random(); - } - - public boolean liveTurn(ArrayList neighbors, Simulator world) { - - // color darken the more it is starved - if(hunger<=100 && hunger>0) { - Color color = new Color((int)(255-2.54*hunger), 0, 0); - this.changeColor(color); - } - - if(this.searchPrey(triggerRadius, world).isEmpty()) { // no prey nearby ? - this.lurk(world); - hunger++; - } - else { // hunt prey ! - this.hunt(this.searchPrey(triggerRadius, world).get(0), this.searchPrey(triggerRadius, world).get(1), world); - if(world.getCell(x, y)==1) { - world.setCell(x, y, 0); - if(hunger > 30) {hunger = hunger - 30;} - } - } - return hunger>100; - } - - private ArrayList searchPrey(int radius, Simulator world) { // targets the nearest prey (= sheep) - ArrayList coordinates = new ArrayList(); - ArrayList preys = new ArrayList(); - preys = world.getNeighboringAnimals(this.x, this.y, radius); - coordinates.add(preys.get(0).getX()); // start tracking down the first sheep in sight - coordinates.add(preys.get(0).getY()); - return coordinates; - } - - private void lurk(Simulator world) { - int direction = rand.nextInt(4); - if(direction == 0 && x < world.getWidth()-1) { - x+=1; - } - if(direction == 1 && y < world.getHeight()-1) { - y+=1; - } - if(direction == 2 && x > 0) { - x-=1; - } - if(direction == 3 && y > 0) { - y-=1; - } - } - - private void hunt(int x, int y, Simulator world) { - int clever = rand.nextInt(6 - this.intelligence); - System.out.println(this.intelligence); - if(this.intelligence == 0) { - this.lurk(world); - } - - if(clever == 0) { - if(this.x < x && x < world.getWidth()-1) { - this.x+=1; - } - if(this.y < y && y < world.getHeight()-1) { - this.y+=1; - } - if(this.x > x && x > 0) { - this.x-=1; - } - if(this.y > y && y > 0) { - this.y-=1; - } - } - else {this.lurk(world);} - } - -}