Пример #1
0
    public static List <HexPos> GetPath(HexPos start, HexPos end, HexCubMap map, Occupation criteria)
    {
        List <HexPos>         path      = new List <HexPos>();
        List <List <HexPos> > floodFill = GetFloodFillUntil(start, end, map, criteria);
        int n = floodFill.Count;

        //If no end in sight return empty path
        if (n == 0 || !floodFill[n].Contains(end))
        {
            return(path);
        }

        path.Add(end);
        n--;
        while (n > 0)
        {
            HexPos nextPos = FirstNeighbour(path[path.Count - 1], floodFill[n]);
            if (nextPos == null)
            {
                path.Clear();
                return(path);
            }
            n--;
        }
        path.Add(start);

        path.Reverse();
        return(path);
    }
Пример #2
0
    protected override void ApplyOn(HexCubMap map, Tile tile)
    {
        Dictionary <HexPos, List <HexPos> > positions = PlacementRule.GetMeristemProximateList(map, Occupation.Any, 1, maxDistance);

        foreach (KeyValuePair <HexPos, List <HexPos> > data in positions)
        {
            Emit(data.Value.Where(e => e.isFree).ToList(), data.Key);
        }
    }
Пример #3
0
 public static IEnumerable <HexPos> GetMeristems(HexCubMap map)
 {
     foreach (HexPos pos in map.OccupiedPositions())
     {
         if (pos.occupant.tileType == TileType.Meristem)
         {
             yield return(pos);
         }
     }
 }
Пример #4
0
 public static bool BordersRoot(HexPos pos, HexCubMap map)
 {
     foreach (HexPos neighbour in GetNeighbours(pos.cubePos, map))
     {
         if (neighbour != null && !neighbour.isFree && neighbour.occupant.tileType == TileType.Root)
         {
             return(true);
         }
     }
     return(false);
 }
Пример #5
0
 public static IEnumerable <HexPos> GetNeighbours(Vector3 pos, HexCubMap map)
 {
     foreach (Vector3 dir in directions)
     {
         HexPos hex = map.GetHexPos(dir + pos);
         if (hex != null && hex.enabled)
         {
             yield return(hex);
         }
     }
 }
Пример #6
0
    static public bool isMeristemPosition(HexCubMap map, Vector3 pos)
    {
        Tile tile = map.GetHexPos(pos).occupant;

        if (tile)
        {
            return(tile.tileType == TileType.Meristem);
        }
        else
        {
            return(false);
        }
    }
Пример #7
0
    public static List <HexPos> RootNeighboursAtMeristemDistance(HexCubMap map, int requiredDist)
    {
        List <HexPos> meristems = GetMeristems(map).ToList();
        List <HexPos> valid     = new List <HexPos>();

        foreach (HexPos free in map.FreePositions())
        {
            if (BordersRoot(free, map) && minDistance(free, meristems) >= requiredDist)
            {
                valid.Add(free);
            }
        }
        return(valid);
    }
Пример #8
0
    public static List <List <HexPos> > GetFloodFillUntil(HexPos start, HexPos end, HexCubMap map, Occupation criteria)
    {
        HashSet <HexPos>      visited = new HashSet <HexPos>();
        List <List <HexPos> > fringes = new List <List <HexPos> >();

        fringes.Add(new List <HexPos>()
        {
            start
        });

        int k = 0;

        while (true)
        {
            fringes.Add(new List <HexPos> ());
            k++;
            for (int i = 0, l = fringes[k - 1].Count; i < l; i++)
            {
                foreach (HexPos neighbour in GetNeighbours(fringes[k - 1][i].cubePos, map))
                {
                    if (visited.Contains(neighbour))
                    {
                        continue;
                    }
                    visited.Add(neighbour);
                    if (criteria == Occupation.Any || criteria == Occupation.Free && neighbour.isFree || criteria == Occupation.Occupied && !neighbour.isFree || neighbour == end)
                    {
                        fringes[k].Add(neighbour);
                    }
                    if (neighbour == end)
                    {
                        return(fringes);
                    }
                }
            }
            if (fringes [k].Count == 0)
            {
                fringes.RemoveAt(k);
                return(fringes);
            }
        }
    }
Пример #9
0
    protected override void ApplyOn(HexCubMap map, Tile tile)
    {
        List <HexPos> meristems  = GetMeristems(map).ToList();
        List <HexPos> candidates = new List <HexPos>();

        for (int i = 0, l = meristems.Count; i < l; i++)
        {
            foreach (HexPos neighbour in GetNeighbours(meristems[i].cubePos, map))
            {
                if (neighbour.isFree)
                {
                    if (CountNeighboursOfTypes(neighbour.cubePos, map, TileType.Meristem, TileType.Root, TileType.RootShoot) == 1)
                    {
                        candidates.Add(neighbour);
                    }
                }
            }
            Emit(candidates, meristems[i]);
            candidates.Clear();
        }
    }
Пример #10
0
    public static Dictionary <HexPos, List <HexPos> > GetMeristemProximateList(HexCubMap map, Occupation occupation, int min = 0, int max = 2)
    {
        Dictionary <HexPos, List <HexPos> > dict = new Dictionary <HexPos, List <HexPos> >();
        bool       isLastFreeMode  = occupation == Occupation.LastFree;
        Occupation floodOccupation = isLastFreeMode ? Occupation.Occupied : occupation;

        //Will actually look one extra in all cases in this mode.
        if (isLastFreeMode)
        {
            max--;
        }

        foreach (HexPos meristem in GetMeristems(map))
        {
            dict[meristem] = new List <HexPos>();
            List <List <HexPos> > flood = GetFloodFillUntil(meristem, max, map, floodOccupation);
            for (int i = min; i < max; i++)
            {
                if (isLastFreeMode)
                {
                    for (int j = 0, l = flood[i].Count; j < l; j++)
                    {
                        foreach (HexPos neighbour in GetNeighbours(flood[i][j].cubePos, map))
                        {
                            if (neighbour.isFree && !dict[meristem].Contains(neighbour))
                            {
                                dict[meristem].Add(neighbour);
                            }
                        }
                    }
                }
                else
                {
                    dict[meristem].AddRange(flood[i]);
                }
            }
        }

        return(dict);
    }
Пример #11
0
    public static int CountNeighboursOfTypes(Vector3 pos, HexCubMap map, params TileType[] types)
    {
        int n = 0;

        foreach (HexPos neighbour in GetNeighbours(pos, map))
        {
            if (neighbour.isFree)
            {
                continue;
            }

            for (int i = 0; i < types.Length; i++)
            {
                if (types[i] == neighbour.occupant.tileType)
                {
                    n++;
                    break;
                }
            }
        }
        return(n);
    }
Пример #12
0
    protected List <HexPos> PermissableHexPositions(
        HexCubMap map,
        int maxDistance,
        System.Func <HexPos, HexPos, HexCubMap, bool> evalFunc)
    {
        HexPos[]      free        = (HexPos[])map.FreePositions();
        HexPos[]      occupied    = (HexPos[])map.OccupiedPositions();
        List <HexPos> permissable = new List <HexPos> ();

        for (int i = 0; i < free.Length; i++)
        {
            for (int j = 0; j < occupied.Length; i++)
            {
                if (evalFunc(free [i], occupied [j], map))
                {
                    permissable.Add(free [i]);
                    break;
                }
            }
        }
        return(permissable);
    }
Пример #13
0
    protected override void ApplyOn(HexCubMap map, Tile tile)
    {
        List <HexPos> candidates = RootNeighboursAtMeristemDistance(map, minDistToOther);

        Emit(candidates);
    }
Пример #14
0
 protected abstract void ApplyOn(HexCubMap map, Tile tile);
Пример #15
0
 public static bool proximate(HexPos a, HexPos b, HexCubMap map)
 {
     return(distance(a.cubePos, b.cubePos) == 2);
 }