public IActionResult End([FromBody] NetSnake.Model.Request request) { return(Ok()); }
public IActionResult Move([FromBody] NetSnake.Model.Request request) { // Hitta närmsta mat // Undvik ormar GameBoard = new GameBoard(request.you, request.board); GameBoard.Update(request.you, request.board); var head = request.you.body.First(); var heuristic = new ManhattanHeuristicAlgorithm(); TileNavigator navigator = new TileNavigator( GameBoard, GameBoard, new PythagorasAlgorithm(), heuristic); int dist = Int32.MaxValue; //Tile? foodTile = null; //bool foodFound = false; var sortedFood = new List <SortableFood>(); foreach (var food in request.board.food) { var newDist = heuristic.Calculate(ToTile(head), ToTile(food)); var pathToFood = navigator.Navigate(ToTile(head), ToTile(food)) ?? new List <Tile>(); sortedFood.Add(new SortableFood { Food = ToTile(food), Distance = (int)newDist, Neighbours = GameBoard.GetNeighbors(ToTile(food)).Where(t => !GameBoard.IsBlocked(t)).ToList() }); /* * if (newDist < dist && pathToFood.Any() && * GameBoard.GetNeighbors(ToTile(food)).Count(t => !GameBoard.IsBlocked(t)) > 1) * { * dist = (int)newDist; * foodTile = ToTile(food); * foodFound = true; * }*/ } var foodTile = SelectBestFood(sortedFood); if (foodTile != null) { var pathToFood = (navigator.Navigate(ToTile(head), foodTile.Value) ?? new List <Tile>()).ToList(); var startPath = pathToFood.FirstOrDefault(); if (pathToFood.Any() && GetMovement(startPath, head, out var foodMove)) { return(Ok(new Move { Direction = foodMove })); } } // Undvik väggar var tiles = GameBoard.GetNeighbors(new Tile(head.x, head.y)).Where(x => !GameBoard.IsBlocked(x)).ToList(); if (tiles.Count == 0) { return(Ok(new Move { Taunt = "Scheisse!!" })); } var tile = GetBestTile(tiles); if (GetMovement(tile, head, out var dir)) { return(Ok(new Move { Direction = dir })); } return(Ok(new Move())); }
public IActionResult Start([FromBody] NetSnake.Model.Request request) { GameBoard = new GameBoard(request.you, request.board); return(Ok(new Configuration())); }