public char snkalg(snake[] snakes, apple apl) { DisTO(snakes); int col = apl.appleX(); int row = apl.appleY(); if (Save == 'w' || Save == 's') { if (Ysnake[0] - row < up && Ysnake[0] - row > 0) { return('w'); } if (row - Ysnake[0] < down && row - Ysnake[0] > 0) { return('s'); } if (col - Xsnake[0] < right && Xsnake[0] - col < 0) { return('d'); } if (Xsnake[0] - col < left && Xsnake[0] - col > 0) { return('a'); } } else if (Save == 'a' || Save == 'd') { if (col - Xsnake[0] < right && Xsnake[0] - col < 0 && Save != 'a') { return('d'); } if (Xsnake[0] - col < left && Xsnake[0] - col > 0 && Save != 'd') { return('a'); } if (Ysnake[0] - row < up && Ysnake[0] - row > 0 && Save != 's') { return('w'); } if (row - Ysnake[0] < down && row - Ysnake[0] > 0 && Save != 'w') { return('s'); } } return(WhatToReturn(up, down, right, left)); }
public int RunAI(snake[] snakes, apple apl) { /*if(diagonalDownLeft > 1) * { * diagonalDownLeft = 1; * } * else * { * diagonalDownLeft = 0; * } * * if (diagonalDownRight > 1) * { * diagonalDownRight = 1; * } * else * { * diagonalDownRight = 0; * } * * if (diagonalUpLeft > 1) * { * diagonalUpLeft = 1; * } * else * { * diagonalUpLeft = 0; * } * * if (diagonalUpRight > 1) * { * diagonalUpRight = 1; * } * else * { * diagonalUpRight = 0; * }*/ double[] input = new double[inputLength]; for (int i = 0; i < snakes.Length; i++) { XsnakesHeads[i] = snakes[i].headX(); } for (int i = snakes.Length; i < snakes.Length * 2; i++) { YsnakesHeads[i - snakes.Length] = snakes[i - snakes.Length].headY(); } aplDisY = (Ysnake[0] - apl.appleY()); aplDisX = (Xsnake[0] - apl.appleX()); int counter = 0; double a = 1; double b = 1; double c = 0; if (Save == 'w') { counter = 0; input[8] = aplDisY; input[9] = -aplDisX; } else if (Save == 'a') { counter = 2; input[8] = aplDisX; input[9] = aplDisY; } else if (Save == 's') { counter = 4; input[8] = -aplDisY; input[9] = aplDisX; } else { counter = 6; input[8] = -aplDisY; input[9] = -aplDisX; } input[counter % 8] = down * a; counter++; input[counter % 8] = diagonalDownLeft * b; counter++; input[counter % 8] = left * a; counter++; input[counter % 8] = diagonalUpLeft * b; counter++; input[counter % 8] = up * a; counter++; input[counter % 8] = diagonalUpRight * b; counter++; input[counter % 8] = right * a; counter++; input[counter % 8] = diagonalDownRight * b; counter = 8; input[0] = 0; input[10] = c * ttl / 10; return(nn.Result(input)); }
public void advance(char dir, apple apl, snake[] snakes, bool printapl) { if (l > 2) { if (Save == 'w' && dir == 's') { dir = Save; } if (Save == 's' && dir == 'w') { dir = Save; } if (Save == 'a' && dir == 'd') { dir = Save; } if (Save == 'd' && dir == 'a') { dir = Save; } } ttl--; num++; if (!alive) { if (l > 0) { l--; } else { delete(); Xsnake[0] = -1; Ysnake[0] = -1; delete(); } } else { runTime++; for (int i = l; i > 0; i--) { Xsnake[i] = Xsnake[i - 1]; Ysnake[i] = Ysnake[i - 1]; } if (dir == 's') { Ysnake[0]++; } if (dir == 'w') { Ysnake[0]--; } if (dir == 'd') { Xsnake[0]++; } if (dir == 'a') { Xsnake[0]--; } if ((apl.appleX() == Xsnake[0]) && (apl.appleY() == Ysnake[0])) { l++; num = 0; apl.newCord(snakes, s); if (printapl) { apl.print(); } //ttl = ((ttl + ttlConst) * 6) / 10; ttl = ttl + ttlConst; } } Save = dir; }