private static SnakeAction DoRun(GameBoard gameBoard) { if (!gameBoard.AmIEvil()) { restEvelRound = 0; } else if (restEvelRound == 0) { restEvelRound = MaxEvelRounds; } if (restEvelRound > 0) { restEvelRound--; } var head = gameBoard.GetMyHead(); if (head == null) { prevDirection = Direction.Right; return(new SnakeAction(IsEnemyInTheTail(gameBoard), prevDirection)); } var huntingElements = gameBoard.FindAllElements(goodElements); var hunting = huntingElements .OrderBy(element => Math.Abs(element.X - head.Value.X) + Math.Abs(element.Y - head.Value.Y)) .FirstOrDefault(element => isNotDeadEnd2(gameBoard, element)); if (hunting == null) { prevDirection = GetDefaultDirection(gameBoard, head.Value); return(new SnakeAction(IsEnemyInTheTail(gameBoard), prevDirection)); } prevDirection = GetDirectionToTarget(gameBoard, head.Value, hunting); return(new SnakeAction(IsEnemyInTheTail(gameBoard), prevDirection)); }
private int FindEnemyConcentration(BoardPoint target, GameBoard gameBoard, int squareSize) => FindConcentration(target, gameBoard.FindAllElements(EnemyHeadDown, EnemyHeadUp, EnemyHeadLeft, EnemyHeadRight, EnemyHeadEvil), squareSize);
private int FindEvilSnakesConcentration(BoardPoint target, GameBoard gameBoard, int squareSize) => FindConcentration(target, gameBoard.FindAllElements(EnemyHeadEvil), squareSize);