我完全不知道如何解决这个问题,但我在 Java 中为 AI 寻路系统使用了一个数组,我需要对这些值进行排序。这是我正在生成的数组:
int[][] paths = new int[Settings.GAME_COLS][Settings.GAME_ROWS]; // Just creating an Array that has room for every tile in the Game, so the Array can be used like this: paths[x][y]
int tempF = 0;
tempF = Math.abs(14 + (((aiX + 1) - playerX) + ((aiY - 1) - playerY)));
paths[aiX + 1][aiY - 1] = tempF;
tempF = Math.abs(14 + (((aiX + 1) - playerX) + ((aiY + 1) - playerY)));
paths[aiX + 1][aiY + 1] = tempF;
tempF = Math.abs(14 + (((aiX - 1) - playerX) + ((aiY + 1) - playerY)));
paths[aiX - 1][aiY + 1] = tempF;
tempF = Math.abs(14 + (((aiX - 1) - playerX) + ((aiY - 1) - playerY)));
paths[aiX - 1][aiY - 1] = tempF;
tempF = Math.abs(10 + (((aiX + 1) - playerX) + (aiY - playerY)));
paths[aiX + 1][aiY ] = tempF;
tempF = Math.abs(10 + (((aiX - 1) - playerX) + (aiY - playerY)));
paths[aiX - 1][aiY ] = tempF;
tempF = Math.abs(10 + ((aiX - playerX) + ((aiY + 1) - playerY)));
paths[aiX ][aiY + 1] = tempF;
tempF = Math.abs(10 + ((aiX - playerX) + ((aiY - 1) - playerY)));
paths[aiX ][aiY - 1] = tempF;
这一切都可以完美地找到并生成包含所需信息的数组,但我需要根据添加到数组中的“tempF”值对数组进行排序。是否有捷径可寻?