Identifying the closest player to an internal 2D grid I've written a function that returns which player is closer to a given 2D grid within a larger 2D grid. I would like to make the function shorter (in LOC) and better. I would appreciate any advice on this topic.
it gets location for both players(x and y) and same for the carpet(the smaller grid), and than calculate the distance b/w each player to the carpet. the reason it takes so much if's is because i'm calculating x from x and y from y, and if the player is on the far side of x/y i have to add size to compassion. that's why i have an if for every corner plus if player is in the range of y/x
public static int getWhoIsCloser(
      int xFirstPlayer,
      int yFirstPlayer,
      int xSecondPlayer,
      int ySecondPlayer,
      int xCarpet,
      int yCarpet,
      int size) {

    size = size - 1;
    int xFirstPlayerProximity = 0;
    int yFirstPlayerProximity = 0;
    int xSecondPlayerProximity = 0;
    int ySecondPlayerProximity = 0;
    int firstPlayerResult;
    int secondPlayerResult;

    if (xFirstPlayer &gt;= xCarpet &amp;&amp; xFirstPlayer &lt;= xCarpet + size) {
      yFirstPlayer -= (yCarpet + size);
      firstPlayerResult = Math.abs(yFirstPlayer);
    } else if (yFirstPlayer &gt;= yCarpet &amp;&amp; yFirstPlayer &lt;= yCarpet + size) {
      xFirstPlayer -= (xCarpet + size);
      firstPlayerResult = Math.abs(xFirstPlayer);
    } else {
      if (xFirstPlayer &lt; xCarpet &amp;&amp; yFirstPlayer &lt; yCarpet) {
        xFirstPlayerProximity = xFirstPlayer - xCarpet;
        yFirstPlayerProximity = yFirstPlayer - yCarpet;
      } else if (xFirstPlayer &lt; xCarpet &amp;&amp; yFirstPlayer &gt; yCarpet) {
        xFirstPlayerProximity = xFirstPlayer - xCarpet;
        yFirstPlayerProximity = yFirstPlayer - (yCarpet + size);
      } else if (xFirstPlayer &gt; xCarpet &amp;&amp; yFirstPlayer &lt; yCarpet) {
        xFirstPlayerProximity = xFirstPlayer - (xCarpet + size);
        yFirstPlayerProximity = yFirstPlayer - yCarpet;
      } else if (xFirstPlayer &gt; xCarpet &amp;&amp; yFirstPlayer &gt; yCarpet) {
        xFirstPlayerProximity = xFirstPlayer - (xCarpet + size);
        yFirstPlayerProximity = yFirstPlayer - (yCarpet + size);
      }
      firstPlayerResult = Math.abs(xFirstPlayerProximity) + Math.abs(yFirstPlayerProximity);
    }
    if (xSecondPlayer &gt;= xCarpet &amp;&amp; xSecondPlayer &lt;= xCarpet + size) {
      ySecondPlayer -= (yCarpet + size);
      secondPlayerResult = Math.abs(ySecondPlayer);
    } else if (ySecondPlayer &gt;= yCarpet &amp;&amp; ySecondPlayer &lt;= yCarpet + size) {
      xSecondPlayer -= (xCarpet + size);
      secondPlayerResult = Math.abs(xSecondPlayer);
    } else {
      if (xSecondPlayer &lt; xCarpet &amp;&amp; ySecondPlayer &lt; yCarpet) {
        xSecondPlayerProximity = xSecondPlayer - xCarpet;
        ySecondPlayerProximity = ySecondPlayer - (yCarpet);
      } else if (xSecondPlayer &lt; xCarpet &amp;&amp; ySecondPlayer &gt; yCarpet) {
        xSecondPlayerProximity = xSecondPlayer - (xCarpet);
        ySecondPlayerProximity = ySecondPlayer - (yCarpet + size);
      } else if (xSecondPlayer &gt; xCarpet &amp;&amp; ySecondPlayer &lt; yCarpet) {
        xSecondPlayerProximity = xSecondPlayer - (xCarpet + size);
        ySecondPlayerProximity = ySecondPlayer - yCarpet;
      } else if (xSecondPlayer &gt; xCarpet &amp;&amp; ySecondPlayer &gt; yCarpet) {
        xSecondPlayerProximity = xSecondPlayer - (xCarpet + size);
        ySecondPlayerProximity = ySecondPlayer - (yCarpet + size);
      }
      secondPlayerResult = Math.abs(xSecondPlayerProximity) + Math.abs(ySecondPlayerProximity);
    }

    if (firstPlayerResult &gt; secondPlayerResult) {
      return 2;
    } else if (firstPlayerResult &lt; secondPlayerResult) {
      return 1;
    } else {
      return 0;
    }
  }
You are exactly duplicating the code for checking the distance for player 1 and player 2. You could move that code into a separate getDistanceToCarpet function, and have the getWhoIsCloser function call that twice.
If I understand your code correctly, you seem to be using so-called taxicab distance, meaning the total distance is equal to the X distance plus the Y distance (this is perfectly valid, as long as you're doing it on purpose). This is convenient, because it lets you separately calculate the X and Y distances and then just add them together.
Let's look at just the X distance for now. We can see that if X is on the carpet, the distance is 0. If is is less than xCarpet, it's equal to xCarpet - xPlayer, and if it's more than xCarpet + size the distance is equal to xPlayer - (xCarpet + size).
And hey, we're doing the same exact thing for Y. We could just copy-paste it and replace all the xes with ys, or we could break it out into another function. The copy-paste approach can be error-prone, so I'd recommend more functions.

Put all that together, it might look a little something like this:
public static int singleAxisDistance(int playerCoordinate, int carpetCoordinate, int carpetSize) {
    if (playerCoordinate &lt; carpetCoordinate) {
        return carpetCoordinate - playerCoordinate;
    } else if (playerCoordinate &lt; carpetCoordinate + carpetSize - 1) {
        return 0;
    } else {
        return playerCoordinate - (carpetCoordinate + carpetSize - 1);
    }
}

public static int getDistanceToCarpet(int xPlayer, int yPlayer, int xCarpet, int yCarpet, int sizeCarpet) {
    int xDistance = getSingleAxisDistanceToCarpet(xPlayer, xCarpet, sizeCarpet);
    int yDistance = getSingleAxisDistanceToCarpet(yPlayer, yCarpet, sizeCarpet);

    return xDistance + yDistance;
}

public static int getWhoIsCloser(
      int xFirstPlayer,
      int yFirstPlayer,
      int xSecondPlayer,
      int ySecondPlayer,
      int xCarpet,
      int yCarpet,
      int size) {

    int firstPlayerResult = distanceToCarpet(xFirstPlayer, yFirstPlayer, xCarpet, yCarpet, size);
    int secondPlayerResult = distanceToCarpet(xSecondPlayer, ySecondPlayer, xCarpet, yCarpet, size);

    if (firstPlayerResult &gt; secondPlayerResult) {
        return 2;
    } else if (firstPlayerResult &lt; secondPlayerResult) {
        return 1;
    } else {
        return 0;
    }
}

If I were to look past that function, I might eventually want to bundle the parameters into position and carpet objects, and put the distance calculations in their classes. Passing a single object is usually neater than passing multiple primitive values, and tends to have less of a risk of getting the parameters confused. And while I admit it's a matter of opinion, I do think this looks nicer on some level:
public static int getWhoIsCloser(
      Point firstPlayerPosition,
      Point secondPlayerPosition,
      Carpet carpet) {

    int firstPlayerDistance = firstPlayerPosition.getDistanceTo(carpet);
    int secondPlayerDistance = secondPlayerPosition.getDistanceTo(carpet);

    if (firstPlayerDistance &gt; secondPlayerDistance) {
        return 2;
    } else if (firstPlayerDistance &lt; secondPlayerDistance) {
        return 1;
    } else {
        return 0;
    }
}
```