Ejemplo n.º 1
0
        private (List <Vec>, bool) BfsSmall(Vec v)
        {
            var result = new List <Vec>();

            used[v] = timer;
            int ql = 0, qr = 0;

            queue[qr++] = v;

            while (ql < qr && result.Count < 1000)
            {
                v = queue[ql++];
                result.Add(v);

                foreach (var u in v.GetMNeighbours(toFill))
                {
                    if (used[u] != timer && !filled[u])
                    {
                        used[u]     = timer;
                        queue[qr++] = u;
                    }
                }
            }

            return(result, ql == qr);
        }
        private bool Check(Vec cell, Vec bot)
        {
            filled[cell] = true;

            var toCheck = cell.GetMNeighbours(filled).Where(c => !filled[c]).ToList();

            return(toCheck.All(c => new PathFinderNeighbours(filled, c, Vec.Zero).TryFindPath()));
        }
Ejemplo n.º 3
0
        private void Bfs(Vec v)
        {
            timer++;
            used[v] = timer;
            int ql = 0, qr = 0;

            queue[qr++] = v;

            while (ql < qr)
            {
                v = queue[ql++];

                foreach (var u in v.GetMNeighbours(toFill))
                {
                    if (used[u] != timer && !filled[u])
                    {
                        used[u]     = timer;
                        queue[qr++] = u;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private bool Check(Vec cell, List <Vec> bots)
        {
            filled[cell] = true;

            int comps   = 0;
            var toCheck = cell.GetMNeighbours(toFill).Where(c => !filled[c]).ToList();

            var botLocations = new HashSet <Vec>(bots);

            timer++;
            foreach (var v in toCheck)
            {
                if (used[v] == timer)
                {
                    continue;
                }

                var(cells, finished) = BfsSmall(v);
                comps++;

                if (!finished) //TODO
                {
                    continue;
                }

                if (cells.Any(c => c == Vec.Zero))
                {
                    continue;
                }

                if (cells.Any(c => !filled[v] && toFill[v] || botLocations.Contains(v)))
                {
                    return(false);
                }
            }

            if (comps == 1)
            {
                return(true);
            }

            Bfs(Vec.Zero);

            var result = true;

            for (int x = 0; x < n; x++)
            {
                for (int y = 0; y < n; y++)
                {
                    for (int z = 0; z < n; z++)
                    {
                        var v = new Vec(x, y, z);
                        if (used[v] == timer)
                        {
                            continue;
                        }
                        if (!filled[v] && toFill[v] || botLocations.Contains(v))
                        {
                            result = false;
                        }
                    }
                }
            }
            return(result);
        }