Exemple #1
0
        public static bool IsGrounded(this Matrix m)
        {
            var clusters = new CoordClusters();

            for (int y = 0; y < m.R; y++)
            {
                for (int x = 0; x < m.R; x++)
                {
                    for (int z = 0; z < m.R; z++)
                    {
                        if (m[x, y, z] == Voxel.Void)
                        {
                            continue;
                        }
                        clusters.Add(Coord.Of(x, y, z));
                        if (x > 0 && m[x - 1, y, z] == Voxel.Full)
                        {
                            clusters.Unite(Coord.Of(x, y, z), Coord.Of(x - 1, y, z));
                        }
                        if (y > 0 && m[x, y - 1, z] == Voxel.Full)
                        {
                            clusters.Unite(Coord.Of(x, y, z), Coord.Of(x, y - 1, z));
                        }
                        if (z > 0 && m[x, y, z - 1] == Voxel.Full)
                        {
                            clusters.Unite(Coord.Of(x, y, z), Coord.Of(x, y, z - 1));
                        }
                    }
                }
            }

            return(clusters.Count == 1);
        }
Exemple #2
0
        private void Prepare()
        {
            var coords = new List <int>();

            for (int i = R - 1; i > 0; i -= 31)
            {
                coords.Add(i);
                coords.Add(Math.Max(i - 30, 0));
            }

            int n = coords.Count;

            var dests = new List <Coord>()
            {
                Coord.Of(0, MaxY + 1, 0),
                Coord.Of(coords[0], MaxY + 1, 30),
            };

            for (int i = 1; i < n; i++)
            {
                dests.Add(Coord.Of(coords[i - 0], MaxY + 1, 30));
                dests.Add(Coord.Of(coords[i - 1], MaxY + 1, 0));
            }

            LocateBots(dests);
        }
Exemple #3
0
 public IEnumerable <Coord> GetMembers()
 {
     for (int x = MinX; x <= MaxX; x++)
     {
         for (int y = MinY; y <= MaxY; y++)
         {
             for (int z = MinZ; z <= MaxZ; z++)
             {
                 yield return(Coord.Of(x, y, z));
             }
         }
     }
 }
Exemple #4
0
        private void Prepare()
        {
            var coords = new List <int>();

            for (int i = R - 1; i > 0; i -= 31)
            {
                coords.Add(i);
                coords.Add(Math.Max(i - 30, 0));
            }

            int n = coords.Count;

            var upper = new List <Coord>();

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < i; j++)
                {
                    upper.Add(Coord.Of(coords[i], MaxY + 1, coords[j]));
                }
            }
            upper.Sort((c1, c2) => {
                int n1 = c1.X + c1.Z;
                int n2 = c2.X + c2.Z;
                return(-Comparer <Int32> .Default.Compare(n1, n2));
            });

            var dests = new List <Coord>();

            dests.Add(Coord.Of(0, MaxY + 1, 0));

            for (int i = 0; i <= n - 2; i++)
            {
                dests.Add(Coord.Of(coords[i], MaxY + 1, coords[i]));
            }
            foreach (Coord c in upper)
            {
                dests.Add(c); dests.Add(Coord.Of(c.Z, c.Y, c.X));
            }

            LocateBots(dests);
        }
Exemple #5
0
        private void Inspect()
        {
            mHarmonics = new List <Harmonics>()
            {
                Low
            };

            var clusters = new CoordClusters();

            for (int y = MinY; y <= MaxY; y++)
            {
                for (int x = MinX; x <= MaxX; x++)
                {
                    for (int z = MinZ; z <= MaxZ; z++)
                    {
                        if (S.Matrix[x, y, z] == Voxel.Void)
                        {
                            continue;
                        }
                        Coord c = Coord.Of(x, y, z);
                        clusters.Add(c);
                        if (x > MinX && S.Matrix[x - 1, y, z] == Voxel.Full)
                        {
                            clusters.Unite(c, Coord.Of(x - 1, y, z));
                        }
                        if (y > MinY && S.Matrix[x, y - 1, z] == Voxel.Full)
                        {
                            clusters.Unite(c, Coord.Of(x, y - 1, z));
                        }
                        if (z > MinZ && S.Matrix[x, y, z - 1] == Voxel.Full)
                        {
                            clusters.Unite(c, Coord.Of(x, y, z - 1));
                        }
                    }
                }
                mHarmonics.Add(clusters.Count == 1 ? Low : High);
            }
        }
Exemple #6
0
        private static void LocateBots(State s)
        {
            var commands = new List <Command>();
            int r        = s.Matrix.R;

            while (s.Bots[0].Pos.Y < r - 1)
            {
                int dy = r - 1 - s.Bots[0].Pos.Y;
                s.DoTurn(new [] { Commands.SMove(Delta.LinearY(Math.Min(dy, 15))) });
            }

            var dests = new List <Coord>();

            {
                int[] coords = { r - 1, r - 31, r - 32, r - 62, r - 63, 0 };

                var upper = new List <Coord>();

                for (int i = 0; i < 6; i++)
                {
                    for (int j = 0; j < i; j++)
                    {
                        upper.Add(Coord.Of(coords[i], r - 1, coords[j]));
                    }
                }
                upper.Sort((c1, c2) => {
                    int n1 = c1.X + c1.Z;
                    int n2 = c2.X + c2.Z;
                    return(-Comparer <Int32> .Default.Compare(n1, n2));
                });

                dests.Add(Coord.Of(0, r - 1, 0));

                for (int i = 0; i <= 4; i++)
                {
                    dests.Add(Coord.Of(coords[i], r - 1, coords[i]));
                }
                foreach (Coord c in upper)
                {
                    dests.Add(c); dests.Add(Coord.Of(c.Z, c.Y, c.X));
                }
            }

            while (true)
            {
                commands.Clear();

                if (s.Bots.Count < dests.Count)
                {
                    int dx = (s.Bots.Count % 2 == 1) ? 1 : 0;
                    int dz = (s.Bots.Count % 2 == 1) ? 0 : 1;
                    commands.Add(Commands.Fission(Delta.Of(dx, 0, dz), 0));
                }
                else
                {
                    commands.Add(Commands.Wait());
                }

                for (int i = 1; i < s.Bots.Count; i++)
                {
                    int dx = dests[i].X - s.Bots[i].Pos.X;
                    int dz = dests[i].Z - s.Bots[i].Pos.Z;
                    if (dx > 0 && (i % 2 == 1 || dz == 0))
                    {
                        commands.Add(Commands.SMove(Delta.LinearX(Math.Min(dx, 15))));
                        continue;
                    }
                    if (dz > 0 && (i % 2 == 0 || dx == 0))
                    {
                        commands.Add(Commands.SMove(Delta.LinearZ(Math.Min(dz, 15))));
                        continue;
                    }
                    commands.Add(Commands.Wait());
                }

                if (IsNoop(commands))
                {
                    break;
                }
                s.DoTurn(commands);
            }
        }
Exemple #7
0
 public static Coord operator+(Coord c, Delta d)
 {
     return(Coord.Of(c.X + d.DX, c.Y + d.DY, c.Z + d.DZ));
 }