private void Check(HexTile t, HexTile test)
        {
            int match = 0;

            // Skip checking already dupes with others.
            if (test.DupeWith > 0)
            {
                return;
            }

            if (!t.Equals(test) && t.ImageUrl == test.ImageUrl)
            {
                if (t.Id < test.Id)
                {
                    t.DupeWith  = test.Id;
                    t.ImageDupe = true;
                }
                else
                {
                    test.DupeWith  = t.Id;
                    test.ImageDupe = true;
                }
            }

            for (int i = 0; i < 6; i++)
            {
                if (t.Equals(test) || test.Nodes[i].HexTiles.All(s => s.Symbol == Symbol.Blank))
                {
                    continue;
                }

                for (int j = 0; j < 6; j++)
                {
                    if (t.Nodes[j].HexTiles.SequenceEqual(test.Nodes[i].HexTiles))
                    {
                        match++;
                    }
                }
            }

            if (match > 1)
            {
                if (t.Id < test.Id)
                {
                    t.DupeWith = test.Id;
                    t.NodeDupe = true;
                }
                else
                {
                    test.DupeWith = t.Id;
                    test.NodeDupe = true;
                }
            }
        }
Beispiel #2
0
 public bool EvaluationPath(HexTilePath hexTilePath)
 {
     if (lastTile.Equals(hexTilePath.lastTile) && costOfPath <= hexTilePath.costOfPath)
     {
         return(true);
     }
     return(false);
 }
Beispiel #3
0
    // A* Search based simple path
    public List <HexTile> SimplePath(HexTile start, HexTile goal)
    {
        List <HexTile> path = new List <HexTile>();
        Dictionary <HexTile, HexTile> cameFrom  = new Dictionary <HexTile, HexTile>();
        Dictionary <HexTile, int>     costSoFar = new Dictionary <HexTile, int>();
        PriorityQueue <HexTile>       frontier  = new PriorityQueue <HexTile>();

        frontier.Enqueue(start, 0);

        cameFrom[start]  = start;
        costSoFar[start] = 0;

        while (frontier.Count > 0)
        {
            HexTile current = frontier.Dequeue();

            if (current.Equals(goal))
            {
                break;
            }

            foreach (HexTile next in Neighbors(current))
            {
                int newCost = costSoFar[current] + Array.Find(LevelMap.TerrainProperties, property => property.Type == next.Type).Cost;
                if (!costSoFar.ContainsKey(next) || newCost < costSoFar[next])
                {
                    costSoFar[next] = newCost;
                    int priority = newCost + HeuristicHexDistance(next, goal);
                    frontier.Enqueue(next, priority);
                    cameFrom[next] = current;
                }
            }
        }

        HexTile RevCurrent = goal;

        path.Add(goal);
        path.Add(cameFrom[RevCurrent]);
        while (RevCurrent != start)
        {
            RevCurrent = cameFrom[RevCurrent];
            path.Add(RevCurrent);
        }
        path.Remove(start);
        path.Reverse();
        return(path);
    }