Esempio n. 1
0
        public static Map FromJson(JObject json, string playerId)
        {
            int width  = (int)json["width"];
            int height = (int)json["height"];
            int tick   = (int)json["worldTick"];

            var snakes = json["snakeInfos"].Select(token =>
            {
                string name   = (string)token["name"];
                string id     = (string)token["id"];
                int points    = (int)token["points"];
                var positions = token["positions"].Select(i => MapCoordinate.FromIndex((int)i, width));
                return(new SnakePlayer(id, name, points, positions));
            }).ToList();

            var mySnake = snakes.FirstOrDefault(s => s.Id.Equals(playerId));

            var foods     = json["foodPositions"].Select(i => MapCoordinate.FromIndex((int)i, width));
            var obstacles = json["obstaclePositions"].Select(i => MapCoordinate.FromIndex((int)i, width));

            return(new Map(width, height, tick, mySnake, snakes, foods, obstacles));
        }
Esempio n. 2
0
 public static IEnumerable <MapCoordinate> Neighbours(this MapCoordinate mapCoordinate)
 {
     return(mapCoordinate.NeighboursOfDistance(1));
 }
Esempio n. 3
0
 public bool IsObstace(MapCoordinate coordinate)
 {
     return(ObstaclePositions.Contains(coordinate));
 }
Esempio n. 4
0
 public bool IsFood(MapCoordinate coordinate)
 {
     return(FoodPositions.Contains(coordinate));
 }
Esempio n. 5
0
 protected bool Equals(MapCoordinate other)
 {
     return(X == other.X && Y == other.Y);
 }
Esempio n. 6
0
 public bool IsSnake(MapCoordinate coordinate)
 {
     return(SnakeParts.Contains(coordinate));
 }
Esempio n. 7
0
 public int GetManhattanDistanceTo(MapCoordinate other)
 {
     return(Math.Abs(X - other.X) + Math.Abs(Y - other.Y));
 }
Esempio n. 8
0
 public double GetAreaDistanceTo(MapCoordinate other)
 {
     return((Math.Abs(X - other.X) + 1) * (Math.Abs(Y - other.Y) + 1));
 }
Esempio n. 9
0
 public bool IsSafe(MapCoordinate mapCoordinate) => this[mapCoordinate].IsSafe();
Esempio n. 10
0
 public bool IsDanger(MapCoordinate mapCoordinate) => this[mapCoordinate].IsDanger();
Esempio n. 11
0
 public TileType this[MapCoordinate mapCoordinate] => TileGrid.ContainsKey(mapCoordinate) ? TileGrid[mapCoordinate] : TileType.OutOfBounds;
Esempio n. 12
0
 public bool IsFood(MapCoordinate coordinate)
 {
     return(this[coordinate] == TileType.Food);
 }
Esempio n. 13
0
 public bool IsObstacle(MapCoordinate coordinate)
 {
     return(this[coordinate] == TileType.Obstacle);
 }