예제 #1
0
 private void Move(ScratchRover rover)
 {
     if (PreviousX.Count > 4)
     {
         PreviousX.RemoveAt(PreviousX.Count - 1);
     }
     PreviousX.Insert(0, PosX);
     if (PreviousY.Count > 4)
     {
         PreviousY.RemoveAt(PreviousY.Count - 1);
     }
     PreviousY.Insert(0, PosY);
     if (moveDir == Direction.Up)
     {
         PosY -= 1; // Reversed for Scratch
     }
     else if (moveDir == Direction.Right)
     {
         PosX += 1;
     }
     else if (moveDir == Direction.Down)
     {
         PosY += 1; // Reversed for scratch
     }
     else
     {
         PosX -= 1;
     }
     rover.Move(moveDir);
 }
예제 #2
0
        public Boolean Step(ScratchRover rover)
        {
            if (rover == null)
            {
                throw new ArgumentNullException(nameof(rover));
            }

            if (rover.CollectSample())
            {
                return(true);
            }
            if (rover.ProcessSamples())
            {
                return(true);
            }
            if (rover.Transmit())
            {
                return(true);
            }

            Int32 num = _random.Next(0, 4);

            if (num == 0)
            {
                rover.Move(Direction.Up);
            }
            else if (num == 1)
            {
                rover.Move(Direction.Right);
            }
            else if (num == 2)
            {
                rover.Move(Direction.Down);
            }
            else if (num == 3)
            {
                rover.Move(Direction.Left);
            }

            if (rover.IsHalted)
            {
                return(true);
            }

            return(rover.CollectPower());
        }
예제 #3
0
 private void Move(ScratchRover rover)
 {
     if (_moveDir == Direction.Up)
     {
         if (_adjacentSquares[0] != TerrainType.Impassable)
         {
             _posY -= 1; // Reversed for Scratch
         }
         else
         {
             throw new InvalidOperationException();
         }
     }
     else if (_moveDir == Direction.Right)
     {
         if (_adjacentSquares[1] != TerrainType.Impassable)
         {
             _posX += 1;
         }
         else
         {
             throw new InvalidOperationException();
         }
     }
     else if (_moveDir == Direction.Down)
     {
         if (_adjacentSquares[2] != TerrainType.Impassable)
         {
             _posY += 1; // Reversed for scratch
         }
         else
         {
             throw new InvalidOperationException();
         }
     }
     else if (_moveDir == Direction.Left)
     {
         if (_adjacentSquares[3] != TerrainType.Impassable)
         {
             _posX -= 1;
         }
         else
         {
             throw new InvalidOperationException();
         }
     }
     rover.Move(_moveDir);
 }
예제 #4
0
        public Boolean Step(ScratchRover rover)
        {
            if (rover == null)
            {
                throw new ArgumentNullException(nameof(rover));
            }

            Direction smoothSquare = Direction.None;

            SenseAdjacentSquares(rover);
            for (Int32 i = 0; i < Direction.DirectionCount; i++)
            {
                if (adjacentSquares[i] == TerrainType.Smooth)
                {
                    smoothSquare = (Direction)i;
                    break;
                }
            }

            if (rover.Power < 30 || (smoothSquare == Direction.None && adjacentSquares[4] == TerrainType.Smooth))
            {
                if (rover.Power < 51 * rover.MovesLeft)
                {
                    rover.CollectPower();
                }
            }

            if (rover.MovesLeft < 3)
            {
                if (rover.MovesLeft == 2)
                {
                    rover.ProcessSamples();
                    rover.Transmit();
                    return(true);
                }
                rover.Transmit();
            }
            if (rover.Power < 41)
            {
                if (rover.Power > 10)
                {
                    rover.CollectPower();
                }
                if (rover.Power < 41)
                {
                    rover.Transmit();
                }
            }
            if (adjacentSquares[4] == TerrainType.Smooth || adjacentSquares[4] == TerrainType.Rough)
            {
                rover.CollectSample();
                if (rover.SamplesCollected >= 3)
                {
                    rover.ProcessSamples();
                }
            }
            if (adjacentSquares.Contains(TerrainType.Smooth))
            {
                if (adjacentSquares[0] == TerrainType.Smooth)
                {
                    rover.Move(Direction.Up);
                }
                else if (adjacentSquares[1] == TerrainType.Smooth)
                {
                    rover.Move(Direction.Right);
                }
                else if (adjacentSquares[2] == TerrainType.Smooth)
                {
                    rover.Move(Direction.Down);
                }
                else if (adjacentSquares[3] == TerrainType.Smooth)
                {
                    rover.Move(Direction.Left);
                }
            }
            else
            {
                Int32 num = _random.Next(0, 4);
                if (num == 0)
                {
                    rover.Move(Direction.Up);
                }
                else if (num == 1)
                {
                    rover.Move(Direction.Right);
                }
                else if (num == 2)
                {
                    rover.Move(Direction.Down);
                }
                else if (num == 3)
                {
                    rover.Move(Direction.Left);
                }
            }

            return(false);
        }