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