Ejemplo n.º 1
0
 private static string[] GetTargets(Vector from, Map map)
 {
     Console.WriteLine(map.ToString());
     var waveRun = new WaveRun(map, from);
     Tuple<Vector, Stack<RobotMove>>[] targets = waveRun.EnumerateTargets((lmap, pos, stepNumber) => lmap.GetCell(pos) == MapCell.Lambda).ToArray();
     string[] formattedTargets = targets.Select(FormatTarget).ToArray();
     foreach (var target in formattedTargets)
         Console.WriteLine(target);
     return formattedTargets;
 }
Ejemplo n.º 2
0
 public void Draw(Map map, IDrawer drawer)
 {
     var waveRun = new WaveRun(map, map.Robot);
     var first = true;
     drawer.AddStyle("target", "Gold");
     drawer.AddStyle("firstTarget", "Fuchsia");
     Tuple<Vector, Stack<RobotMove>> firstTarget = null;
     foreach (var target in waveRun.EnumerateTargets((lmap, pos, stepNumber) => lmap.GetCell(pos) == MapCell.Lambda))
     {
         if (first) firstTarget = target;
         var style = first ? "firstTarget" : "target";
         first = false;
         drawer.DrawTarget(map, style, target);
     }
     if (waveRun.Lift != null)
     {
         drawer.DrawTarget(map, "target", waveRun.Lift);
     }
     if (firstTarget != null)
         drawer.DrawTarget(map, "firstTarget", firstTarget);
 }
Ejemplo n.º 3
0
        private RobotMove FindMovableRock(Map map)
        {
            var left = new Vector(-1, 0);
            var right = new Vector(1, 0);
            var up = new Vector(0, 1);

            var leftRobot = map.Robot.Add(left);
            var rightRobot = map.Robot.Add(right);
            var upRobot = map.Robot.Add(up);

            var leftCheck = map.GetCell(leftRobot) != MapCell.Wall && map.IsSafeMove(map.Robot, map.Robot.Add(left), 1, map.WaterproofLeft);
            var rightCheck = map.GetCell(rightRobot) != MapCell.Wall && map.IsSafeMove(map.Robot, map.Robot.Add(right), 1, map.WaterproofLeft);

            if (map.GetCell(leftRobot).IsRock() && map.GetCell(leftRobot.Add(left)) == MapCell.Empty && leftCheck)
                return RobotMove.Left;
            if (map.GetCell(rightRobot).IsRock() && map.GetCell(rightRobot.Add(right)) == MapCell.Empty && rightCheck)
                return RobotMove.Right;

            if (map.GetCell(upRobot).IsRock() && map.GetCell(leftRobot).IsMovable() && leftCheck)
                return RobotMove.Left;
            if (map.GetCell(upRobot).IsRock() && map.GetCell(rightRobot).IsMovable() && rightCheck)
                return RobotMove.Right;

            var waveRun = new WaveRun(map, map.Robot);
            moveRockTarget = waveRun.EnumerateTargets(
                (lmap, position, used) =>
                    {
                        if (lmap.GetCell(position.Add(up)).IsRock() && (lmap.GetCell(position.Add(left)).IsMovable() || lmap.GetCell(position.Add(right)).IsMovable()))
                            return true;
                        if (lmap.GetCell(position).IsMovable() && lmap.GetCell(position.Add(left)).IsRock() && lmap.GetCell(position.Add(left).Add(left)).IsRockMovable())
                            return true;
                        if (lmap.GetCell(position).IsMovable() && lmap.GetCell(position.Add(right)).IsRock() && lmap.GetCell(position.Add(right).Add(right)).IsRockMovable())
                            return true;
                        if (lmap.GetCell(position) == MapCell.Earth && lmap.GetCell(position.Add(right)).IsRock()
                                && lmap.GetCell(position.Add(right).Add(right)) != MapCell.Wall && !lmap.GetCell(position.Add(right).Add(right)).IsRock())
                            return true;
                        if (lmap.GetCell(position) == MapCell.Earth && lmap.GetCell(position.Add(left)).IsRock()
                                && lmap.GetCell(position.Add(right).Add(right)) != MapCell.Wall && !lmap.GetCell(position.Add(right).Add(right)).IsRock())
                            return true;
                        return false;
                    }).FirstOrDefault();

            if(moveRockTarget == null)
                return RobotMove.Abort;

            return moveRockTarget.Item2.Any() ? moveRockTarget.Item2.Peek() : RobotMove.Abort;
        }
Ejemplo n.º 4
0
 private RobotMove FindSafePlace(Map map)
 {
     //			if (map.IsSafeMove(map.Robot, map.Robot.Add(new Vector(0, 1)), 1, map.WaterproofLeft)) return RobotMove.Up;
     if(map.IsSafeMove(map.Robot, map.Robot, 1, map.WaterproofLeft)) return RobotMove.Wait;
     var waveRun = new WaveRun(map, map.Robot);
     Tuple<Vector, Stack<RobotMove>> target = waveRun.EnumerateTargets((lmap, position, stepNumber) => true).FirstOrDefault();
     if(target == null)
         return RobotMove.Abort;
     return target.Item2.Any() ? target.Item2.Peek() : RobotMove.Wait;
 }
Ejemplo n.º 5
0
        private Tuple<Vector, Stack<RobotMove>> FindBestTarget(Map map, bool checkBestIsNotBad = true)
        {
            var waveRun = new WaveRun(map, map.Robot, checkBestIsNotBad ? 400000 : 1000);
            Tuple<Vector, Stack<RobotMove>> result = null;

            if(checkBestIsNotBad)
            {
                var orderedMoves = waveRun
                    .EnumerateTargets((lmap, pos, stepNumber) => lmap.GetCell(pos) == MapCell.Lambda
                        || (lmap.LambdasGathered != lmap.TotalLambdaCount && lmap.GetCell(pos) == MapCell.Razor))
                    .Where(tuple => specialTargetType != SpecialTargetType.Banned || specialTarget == null || (tuple.Item1.X != specialTarget.X && tuple.Item1.Y != specialTarget.Y))
                    .Take(9)
                    .OrderBy(t => CalculateTargetBadness(t, map)).ToArray();
                result = orderedMoves.FirstOrDefault();
            }
            else result = waveRun.EnumerateTargets((lmap, pos, stepNumber) => lmap.GetCell(pos) == MapCell.Lambda
                || (lmap.LambdasGathered != lmap.TotalLambdaCount && lmap.GetCell(pos) == MapCell.Razor)).FirstOrDefault();
            if(result != null) return result;
            if(waveRun.Lift != null && map.GetCell(waveRun.Lift.Item1) == MapCell.OpenedLift)
                return waveRun.Lift;
            return null;
        }