botgob

Untitled

Jan 28th, 2021
498
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. double getNeighbourPercent(Actor[] neigh, Color color){
  2.         int redAmount = 0;
  3.         int blueAmount = 0;
  4.         int totalColor = neigh.length;
  5.         double totalColorPercent;
  6.         for (int i = 0; i < neigh.length; i++){
  7.             if (neigh[i] == null){
  8.                 totalColor--;
  9.             } else if (neigh[i].color == Color.RED){
  10.                 redAmount++;
  11.             } else if (neigh[i].color == Color.BLUE){
  12.                 blueAmount++;
  13.             }
  14.         }
  15.         if (totalColor == 0){
  16.             return 0.0;
  17.         }
  18.         if (color == Color.RED){
  19.             if (redAmount == 0) {
  20.                 return 0.0;
  21.             }
  22.             totalColorPercent = (double) redAmount / totalColor;
  23.         } else {
  24.             if (blueAmount == 0){
  25.                 return 0.0;
  26.             }
  27.             totalColorPercent = (double) blueAmount / totalColor;
  28.         }
  29.         return totalColorPercent;
  30.     }
RAW Paste Data