private static MapForNN CreateMap(int size, List <MapCoordConverter> coordList, PlayingMap pMap, Cordinates point) { var map = new MapForNN(size); foreach (var c in pMap.Barriers) { var coord = coordList.Where(x => x.PMapCoord == c).ToArray(); if (coord.Length > 0) { map.Map[coord[0].NNMapCoord.X, coord[0].NNMapCoord.Y] = ObjectTypes.Barrier; } } foreach (var c in pMap.Food.FoodCordinates) { var coord = coordList.Where(x => x.PMapCoord == c).ToArray(); if (coord.Length > 0) { map.Map[coord[0].NNMapCoord.X, coord[0].NNMapCoord.Y] = ObjectTypes.Food; } } foreach (var snake in pMap.Snake) { foreach (var c in snake.Cordinates) { var coord = coordList.Where(x => x.PMapCoord == c).ToArray(); if (coord.Length > 0) { map.Map[coord[0].NNMapCoord.X, coord[0].NNMapCoord.Y] = ObjectTypes.Snake; } } } FindNearestFood(ref map, pMap, point); return(map); }
private static void FindNearestFood(ref MapForNN map, PlayingMap pMap, Cordinates point) { Cordinates nearFood = pMap.Food.FoodCordinates[0]; double minDist = Math.Sqrt( Math.Pow(point.X - (pMap.Food.FoodCordinates[0].X), 2) + Math.Pow(point.Y - (pMap.Food.FoodCordinates[0].Y), 2));; for (int xFactor = -1; xFactor <= 1; xFactor++) { for (int yFactor = -1; yFactor <= 1; yFactor++) { CheckOtherSide(pMap, xFactor, yFactor, point, ref minDist, ref nearFood); } } if (point.X < nearFood.X) { map.NearestFoodHorizontal = SnakePathway.Right; } else if (point.X > nearFood.X) { map.NearestFoodHorizontal = SnakePathway.Left; } else { map.NearestFoodHorizontal = null; } if (point.Y < nearFood.Y) { map.NearestFoodVertical = SnakePathway.Down; } else if (point.Y > nearFood.Y) { map.NearestFoodVertical = SnakePathway.Up; } else { map.NearestFoodVertical = null; } }