Example #1
0
    public bool ShowRangeForAttack(Character c)
    {
        var startTile    = Tiles.FirstOrDefault(t => t.Coordinate == c.Coordinate);
        var tilesInRange = Tiles.Where(t => ((t.Coordinate.x <= c.Coordinate.x + c.Weapon.Range) && (t.Coordinate.x >= c.Coordinate.x - c.Weapon.Range)) &&
                                       ((t.Coordinate.y <= c.Coordinate.y + c.Weapon.Range) && (t.Coordinate.y >= c.Coordinate.y - c.Weapon.Range))).ToList();

        var dijks = Dijsktra.GetDistancesWithoutCost(tilesInRange, startTile);

        foreach (var dijk in dijks)
        {
            if (dijk.Distance > c.Weapon.Range)
            {
                continue;
            }
            if (dijk.t.Coordinate == c.Coordinate)
            {
                continue;
            }
            //if (!Personajes.Where(p => p.Team != c.Team).Any(p => p.Coordinate == tile.Coordinate))
            //        continue;
            GameObject newObject = GameObject.Instantiate(MovementTile) as GameObject;
            newObject.transform.position = dijk.t.Coordinate;
            newObject.GetComponent <SpriteRenderer>().color = Color.red;
            tilesForAttack.Add(newObject);
            lastDijkstraSearchForAttack.Add(dijk);
        }
        return(true);
    }
Example #2
0
    public bool ShowRange(Character c)
    {
        var startTile       = Tiles.FirstOrDefault(t => t.Coordinate == c.Coordinate);
        var maxRangeOfTiles = Tiles.Where(t => ((t.Coordinate.x <= c.Coordinate.x + c.Stats.Movement) && (t.Coordinate.x >= c.Coordinate.x - c.Stats.Movement)) &&
                                          ((t.Coordinate.y <= c.Coordinate.y + c.Stats.Movement) && (t.Coordinate.y >= c.Coordinate.y - c.Stats.Movement))).ToList();

        var blockedTiles = Tiles.Where(t => Personajes.Any(p => p.Coordinate == t.Coordinate && p != c)).ToList();

        var dijks = Dijsktra.GetDistances(maxRangeOfTiles, startTile, blockedTiles);

        foreach (var dijk in dijks)
        {
            if (dijk.Distance > c.Stats.Movement)
            {
                continue;
            }

            //if (Personajes.Where(p => p.Team != c.Team).Any(p => p.Coordinate == dijk.t.Coordinate))
            if (Personajes.Where(p => p != c).Any(p => p.Coordinate == dijk.t.Coordinate))
            {
                continue;
            }

            GameObject newObject = GameObject.Instantiate(MovementTile) as GameObject;
            newObject.transform.position = dijk.t.Coordinate;
            tilesForMovement.Add(newObject);
            lastDijkstraSearch.Add(dijk);
        }

        return(true);
    }
        private void DoDijkstra(DijkstraPoint dest)
        {
            var route = Dijsktra.FindShortestPath(
                map, map.CurrentPosition, dest, UpdateColor);

            route = route.Reverse();
            DisplayRoute(route.Skip(1));
            WalkRoute(route.Take(route.Count() - 1));
            UpdatePointColor(route.Last(), Color.Red);
            map.CurrentPosition = route.Last();
            ResetMap();
        }
Example #4
0
    // Find path a->b on graph g
    private static void FindPath(Graph g, int a, int b)
    {
        Node start = new Node(a);
        Node goal  = new Node(b);

        Pathfinder finder = new Dijsktra();  // ***** CHANGE TO YOUR SEARCH CLASS *****

        finder.SetGraph(g);
        List <Node> path = finder.FindPath(start, goal);

        if (path != null)
        {
            WritePath(path);
        }
        else
        {
            Console.WriteLine("No path found.");
        }
    }
        static void Main(string[] args)
        {
            Vertice v0 = new Vertice("V0");
            Vertice v1 = new Vertice("V1");
            Vertice v2 = new Vertice("V2");
            Vertice v3 = new Vertice("V3");
            Vertice v4 = new Vertice("V4");
            Vertice v5 = new Vertice("V5");

            v0.AddIntercessoes(new Intercessao(v0, 0), new Intercessao(v1, 10), new Intercessao(v2, 5));
            v1.AddIntercessoes(new Intercessao(v0, 10), new Intercessao(v2, 3), new Intercessao(v3, 1));
            v2.AddIntercessoes(new Intercessao(v0, 5), new Intercessao(v1, 3), new Intercessao(v3, 8), new Intercessao(v4, 2));
            v3.AddIntercessoes(new Intercessao(v1, 1), new Intercessao(v2, 8), new Intercessao(v4, 4), new Intercessao(v5, 4));
            v4.AddIntercessoes(new Intercessao(v2, 2), new Intercessao(v3, 4), new Intercessao(v5, 6));
            v5.AddIntercessoes(new Intercessao(v3, 4), new Intercessao(v4, 6));

            Dijsktra dijsktra = new Dijsktra(v0, v1, v2, v3, v4, v5);

            dijsktra.Processar();
        }
Example #6
0
 private static void AddEdge(Graph g, Node a, Node b)
 {
     AddEdge(g, a, b, Dijsktra.Distance(a, b));
 }