Пример #1
0
        private void DoMove(int newRobotX, int newRobotY, Map newMap)
        {
            var newMapCell = GetCell(newRobotX, newRobotY);
            if (newMapCell == MapCell.Lambda)
            {
                newMap.LambdasGathered++;
            }
            else if (newMapCell.IsTrampoline())
            {
                var target = TrampToTarget[newMapCell];
                var targetCoords = Targets[target];
                newRobotX = targetCoords.X;
                newRobotY = targetCoords.Y;
                foreach (var pair in TrampToTarget.Where(a => a.Value == target))
                {
                    var trampolinePos = Trampolines[pair.Key];
                    newMap.field = newMap.SetCell(trampolinePos, MapCell.Empty);
                    CheckNearRocks(newMap.activeRocks, trampolinePos.X, trampolinePos.Y, newMap);
                }
            }
            else if (newMapCell == MapCell.Earth)
            {
            }
            else if (newMapCell == MapCell.Razor)
            {
                newMap.Razors++;
            }
            else if (newMapCell == MapCell.OpenedLift)
            {
                newMap.State = CheckResult.Win;
            }
            else if (newMapCell.IsRock())
            {
                var rockX = newRobotX * 2 - RobotX;
                newMap.field = newMap.SetCell(rockX, newRobotY, newMapCell);
                newMap.activeRocks.Add(new Vector(rockX, newRobotY));
            }
            newMap.field = newMap.SetCell(RobotX, RobotY, MapCell.Empty);
            if (newMapCell != MapCell.OpenedLift)
                newMap.field = newMap.SetCell(newRobotX, newRobotY, MapCell.Robot);

            CheckNearRocks(newMap.activeRocks, RobotX, RobotY, newMap);

            newMap.RobotX = newRobotX;
            newMap.RobotY = newRobotY;
        }
Пример #2
0
        private void Update(Map newMap)
        {
            var robotFailed = false;

            var activeMoves = new SortedSet<Tuple<Vector, Vector, MapCell>>(new TupleVectorComparer());
            foreach (var rockPos in activeRocks.Concat(newMap.activeRocks).Distinct())
            {
                var cell = newMap.GetCell(rockPos);
                var rockMove = TryToMoveRock(rockPos, cell, newMap);
                if (rockMove == null) continue;
                var newRockPos = rockPos.Add(rockMove);
                if (cell == MapCell.LambdaRock && newMap.GetCell(newRockPos.Sub(new Vector(0, 1))) != MapCell.Empty)
                    activeMoves.Add(Tuple.Create(rockPos, newRockPos, MapCell.Lambda));
                else
                    activeMoves.Add(Tuple.Create(rockPos, newRockPos, cell));
            }

            newMap.GrowthLeft--;
            if (newMap.GrowthLeft == 0)
            {
                newMap.GrowthLeft = newMap.Growth;
                foreach (var beardPos in newMap.Beard)
                    for (var x = -1; x <= 1; x++)
                        for (var y = -1; y <= 1; y++)
                        {
                            var newBeardPos = beardPos.Add(new Vector(x, y));
                            if (newMap.GetCell(newBeardPos) == MapCell.Empty)
                                activeMoves.Add(Tuple.Create(beardPos, newBeardPos, MapCell.Beard));
                        }
            }

            var newActiveRocks = new SortedSet<Vector>(new VectorComparer());
            foreach (var activeMove in activeMoves)
            {
                var fromPos = activeMove.Item1;
                var toPos = activeMove.Item2;
                var fromCell = newMap.GetCell(fromPos);
                var toCell = newMap.GetCell(toPos);
                if (fromCell.IsRock())
                {
                    if (!toCell.IsRock()) newActiveRocks.Add(toPos);

                    newMap.field = newMap.SetCell(toPos, activeMove.Item3);
                    newMap.field = newMap.SetCell(fromPos, MapCell.Empty);

                    robotFailed |= IsRobotKilledByRock(toPos.X, toPos.Y, newMap);
                    CheckNearRocks(newActiveRocks, fromPos.X, fromPos.Y, newMap);
                    newMap.Beard.Remove(toPos);
                }
                else if(fromCell == MapCell.Beard)
                {
                    newMap.field = newMap.SetCell(toPos, MapCell.Beard);
                    newMap.Beard.Add(toPos);
                }
            }
            newMap.activeRocks = newActiveRocks;

            if (newMap.TotalLambdaCount == newMap.LambdasGathered)
                newMap.field = newMap.SetCell(Lift, MapCell.OpenedLift);

            robotFailed |= IsRobotKilledByFlood(newMap);
            if (robotFailed)
                newMap.State = CheckResult.Fail;
        }
Пример #3
0
 private void CutBeard(Map newMap)
 {
     if (Razors == 0) return;
     newMap.Razors--;
     newMap.Beard = new HashSet<Vector>();
     foreach (var b in Beard)
     {
         if(Robot.Distance(b) > 1)
             newMap.Beard.Add(b);
         else
             newMap.field = newMap.SetCell(b, MapCell.Empty);
     }
 }