コード例 #1
0
        public CoordDiff FillPreviousDirection()
        {
            CoordDiff fillDirection = Direction;

            fillDirection.Dx = -fillDirection.Dx;
            fillDirection.Dy = -fillDirection.Dy;
            fillDirection.Dz = -fillDirection.Dz;
            return(fillDirection);
        }
コード例 #2
0
            private static void TraceMove(TCoord botCoord, StraightMove m, Action <TCoord> action)
            {
                var cur = botCoord;
                var dst = cur;

                dst.Apply(m.Diff);
                var step = new CoordDiff(Math.Sign(m.Diff.Dx), Math.Sign(m.Diff.Dy), Math.Sign(m.Diff.Dz));

                do
                {
                    cur.Apply(step);
                    action(cur);
                }while (!cur.Equals(dst));
            }
コード例 #3
0
ファイル: LayerFiller.cs プロジェクト: lazy/icfpc2018
        List <Tuple <TCoord, CoordDiff> > GenerateCuts(int lineIndex, List <int> segmentsMap, int layerIndex)
        {
            List <Tuple <TCoord, CoordDiff> > res = new List <Tuple <TCoord, CoordDiff> >();

            for (int j = 1; j < segmentsMap.Count; j += 2)
            {
                var start     = segmentsMap[j - 1];
                var end       = segmentsMap[j];
                var pos       = new TCoord(lineIndex, start, layerIndex);
                var direction = new CoordDiff(0, end, 0);
                res.Add(Tuple.Create <TCoord, CoordDiff>(pos, direction));
            }

            return(res);
        }
コード例 #4
0
ファイル: LayerFiller.cs プロジェクト: lazy/icfpc2018
        List <ICommand> GenerateCommandsForSegment(TBot bot, int lineIndex, List <int> segmentsMapRaw, int direction)
        {
            List <int> segmentsMap = new List <int>(segmentsMapRaw);

            if (direction < 0)
            {
                segmentsMap.Reverse();
            }

            List <Tuple <TCoord, CoordDiff> > cuts = GenerateCuts(lineIndex, segmentsMapRaw, direction);

            var botOffset = new CoordDiff(0, 1, 0);

            var res = new List <ICommand>();

            foreach (var cut in cuts)
            {
                res.AddRange(MoveToPosition(bot, cut.Item1));
                res.AddRange(FillLine(bot, cut.Item2, botOffset));
            }
            return(res);
        }
コード例 #5
0
        private void MoveBot(TBot bot, CoordDiff diff, Volatiles volatiles)
        {
            if (EnableValidation)
            {
                var miniDiff = new CoordDiff(Math.Sign(diff.Dx), Math.Sign(diff.Dy), Math.Sign(diff.Dz));
                var current  = bot.Coord;
                var end      = bot.Coord;
                end.Apply(diff);
                while (!current.Equals(end))
                {
                    volatiles.Update(current, bot);
                    current.Apply(miniDiff);
                    if (this[current])
                    {
                        throw new InvalidStateException($"Coord {current} is occupied when moving bot {bot.Bid}");
                    }
                }

                volatiles.Update(end, bot);
            }

            bot.Coord.Apply(diff);
        }
コード例 #6
0
ファイル: LayerFiller.cs プロジェクト: lazy/icfpc2018
        List <ICommand> FillLine(TBot bot, CoordDiff direction, CoordDiff botOffset)
        {
            TCoord          x          = bot.Coord;
            List <ICommand> res        = new List <ICommand>();
            CoordDiff       fillOffset = new CoordDiff(-botOffset.Dx, -botOffset.Dy, -botOffset.Dz);

            if (direction.Dx != 0)
            {
                int dif = direction.Dx < 0 ? -1 : 1;

                while (true)
                {
                    Fill fc = new Fill();
                    fc.Diff = fillOffset;
                    res.Add(fc);
                    if (bot.Coord.X == x.X + direction.Dx + botOffset.Dx)
                    {
                        break;
                    }
                    StraightMove move = new StraightMove();
                    move.Diff = new CoordDiff(dif, 0, 0);
                    res.Add(move);
                }
            }
            if (direction.Dy != 0)
            {
                int dif = direction.Dy < 0 ? -1 : 1;

                while (true)
                {
                    Fill fc = new Fill();
                    fc.Diff = fillOffset;
                    res.Add(fc);
                    if (bot.Coord.Y == x.Y + direction.Dy + botOffset.Dy)
                    {
                        break;
                    }
                    StraightMove move = new StraightMove();
                    move.Diff = new CoordDiff(0, dif, 0);
                    res.Add(move);
                }
            }
            if (direction.Dz != 0)
            {
                int dif = direction.Dz < 0 ? -1 : 1;

                while (true)
                {
                    Fill fc = new Fill();
                    fc.Diff = fillOffset;
                    res.Add(fc);
                    if (bot.Coord.Z == x.Z + direction.Dz + botOffset.Dz)
                    {
                        break;
                    }
                    StraightMove move = new StraightMove();
                    move.Diff = new CoordDiff(0, 0, dif);
                    res.Add(move);
                }
            }

            return(res);
        }