patch petit bug de modification concurente

This commit is contained in:
2022-11-21 15:51:09 -05:00
parent 773679057e
commit 6df297fc82
2 changed files with 8 additions and 1 deletions

View File

@@ -71,11 +71,14 @@ public class Bird implements Runnable {
public Food findNearestFood() { public Food findNearestFood() {
Food nearestFood = null; Food nearestFood = null;
int minDistance = Integer.MAX_VALUE; int minDistance = Integer.MAX_VALUE;
for (Food f : park.getFoods()) { int i = 0;
while(i < park.getFoods().size()){
Food f = park.getFoods().get(i);
if (this.position.distance(f.getPosition()) < minDistance && f.isFresh()) { if (this.position.distance(f.getPosition()) < minDistance && f.isFresh()) {
nearestFood = f; nearestFood = f;
minDistance = this.position.distance(f.getPosition()); minDistance = this.position.distance(f.getPosition());
} }
i++;
} }
return nearestFood; return nearestFood;
} }

View File

@@ -243,4 +243,8 @@ public class Park extends JPanel implements MouseListener {
} }
} }
public boolean isBusy(){
return (numWriter.get() > 0);
}
} }