Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void run() {
- try {
- Thread.sleep(speed - 1);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- for (int i = 0; i < AIs; i++) {
- NeatEngine.setInput(0, player[i][0] - food[i][0], i);
- NeatEngine.setInput(1, player[i][1] - food[i][1], i);
- NeatEngine.setInput(2, checkPosition(player[i][0] - 1, player[i][1], i), i);
- NeatEngine.setInput(3, checkPosition(player[i][0] + 1, player[i][1], i), i);
- NeatEngine.setInput(4, checkPosition(player[i][0], player[i][1] - 1, i), i);
- NeatEngine.setInput(5, checkPosition(player[i][0], player[i][1] + 1, i), i);
- NeatEngine.setInput(6, checkPosition(player[i][0] - 1, player[i][1] - 1, i), i);
- NeatEngine.setInput(7, checkPosition(player[i][0] - 1, player[i][1] + 1, i), i);
- NeatEngine.setInput(8, checkPosition(player[i][0] + 1, player[i][1] - 1, i), i);
- NeatEngine.setInput(9, checkPosition(player[i][0] + 1, player[i][1] + 1, i), i);
- NeatEngine.runNN(i);
- if (NeatEngine.getOutput(0, i) < 0.5) {
- if (player[i][0] > 0) {
- player[i][0]--;
- }
- } else if (NeatEngine.getOutput(0, i) > 0.5) {
- if (player[i][0] < gridSize) {
- player[i][0]++;
- }
- }
- if (NeatEngine.getOutput(1, i) < 0.5) {
- if (player[i][1] > 0) {
- player[i][1]--;
- }
- } else if (NeatEngine.getOutput(1, i) > 0.5) {
- if (player[i][1] < gridSize) {
- player[i][1]++;
- }
- }
- if (player[i][0] == food[i][0] && player[i][1] == food[i][1]) {
- points[i]++;
- pt = newPosition(i);
- food[i][0] = pt[0];
- food[i][1] = pt[1];
- }
- for (int j = 0; j < enemies; j++) {
- if (player[i][0] == enemy[i][j][0] && player[i][1] == enemy[i][j][1]) {
- /*if (points[i] <= 0) {
- points[i]--;
- } else {
- points[i] = 0;
- }*/
- points[i] --;
- pt = newPosition(i);
- player[i][0] = pt[0];
- player[i][1] = pt[1];
- pt = newPosition(i);
- enemy[i][j][0] = pt[0];
- enemy[i][j][1] = pt[1];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement