예제 #1
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());
        }
예제 #2
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);
        }
예제 #3
0
        public Boolean Step(ScratchRover rover)
        {
            // Sense nearby and find a path and anything else free
            SenseAdjacentSquares(rover);
            if (_mapDirty == true || path.Count == 0)
            {
                do
                {
                    AnalyzeTerrain(_posX, _posY);

                    roughTerrainDistMultiplier = 70.0 * rover.MovesLeft / rover.Power; // Optimization target
                    if (roughTerrainDistMultiplier > 3)
                    {
                        roughTerrainDistMultiplier = 3; // Optimization target
                    }
                    else if (roughTerrainDistMultiplier < 1)
                    {
                        roughTerrainDistMultiplier = 1;
                    }

                    ScratchDijkstras pathFinder = new ScratchDijkstras(_mappedTerrain);
                    path = pathFinder.BeginSolve(_posX, _posY, roughTerrainDistMultiplier);
                    if (path.Count < 1)
                    {
                        if (pathFinder.destinationIndex == -1)
                        {
                            return(true); // We have no more squares to go to.
                        }
                        // Found an unreachable square
                        _mappedTerrain[pathFinder.destinationIndex] = TerrainType.Impassable;
                    }
                } while (path.Count == 0);
            }
            _moveDir = path[0];
            path.RemoveAt(0);

            // Collect samples and power, move, process, and transmit - anything needing power or moves
            if (rover.MovesLeft < 5)
            {
                if (rover.MovesLeft == 4)
                {
                    rover.CollectPower();
                    if (rover.Power > 40 && _adjacentSquares[4] == TerrainType.Smooth)
                    {
                        rover.CollectSample();
                        rover.ProcessSamples();
                    }
                    else if (rover.Power > 30)
                    {
                        rover.ProcessSamples();
                    }
                }
                else if (rover.MovesLeft == 3)
                {
                    if (rover.Power > 40 && _adjacentSquares[4] == TerrainType.Smooth)
                    {
                        rover.CollectSample();
                    }
                    else
                    {
                        rover.CollectPower();
                    }
                    if (rover.Power > 30)
                    {
                        rover.ProcessSamples();
                    }
                }
                else if (rover.MovesLeft == 2)
                {
                    if (rover.Power > 30)
                    {
                        rover.ProcessSamples();
                    }
                }
                rover.Transmit();
                return(true); // Out of moves, end simulation
            }

            if (rover.Power < 101)
            {
                if (rover.Power < 11)
                {
                    if (_potentialPower[0] + rover.Power < 11)
                    {
                        rover.Transmit();
                    }
                    else
                    {
                        rover.CollectPower();
                    }
                }

                if (rover.Power < 101)
                {
                    _lowPower = true;
                }


                if (rover.Power < 51)
                {
                    if (rover.Power > 10 && _adjacentSquares[4] == TerrainType.Smooth)
                    {
                        rover.CollectPower();
                    }
                    if (rover.Power < 51)
                    {
                        rover.Transmit();
                    }
                }
            }

            if ((rover.Power + _potentialPower[1]) / rover.MovesLeft > 70)
            {
                _lowPower = false;
            }

            if (_potentialPower[0] > 0)
            {
                if (rover.Power < 30 || _potentialPower[1] == 0)
                {
                    if (rover.Power / rover.MovesLeft < 51)
                    {
                        rover.CollectPower();
                    }
                }
            }

            if (_adjacentSquares[4] == TerrainType.Smooth || _adjacentSquares[4] == TerrainType.Rough)
            {
                if (!(_lowPower && _potentialPower[1] > 0))
                {
                    rover.CollectSample();
                    if (rover.SamplesCollected >= 3 && rover.Power > 40)
                    {
                        rover.ProcessSamples();
                    }
                }
            }

            Move(rover);

            return(rover.MovesLeft == 0 || rover.Power == 0);
        }
예제 #4
0
        public Boolean Step(ScratchRover rover)
        {
            Direction SmoothSquare = Direction.None;

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

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

            if (rover.MovesLeft < 3)
            {
                if (rover.MovesLeft == 2)
                {
                    rover.ProcessSamples();
                }
                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 (SmoothSquare != Direction.None)
            {
                moveDir = SmoothSquare;
            }
            else
            {
                moveDir = Direction.None;
                for (Int32 i = 0; i < 5; i++)
                {
                    if (adjacentSquares[i] == TerrainType.Rough)
                    {
                        moveDir     = (Direction)i;
                        destination = Direction.None;
                        break;
                    }
                }
                if (moveDir == Direction.None)
                {
                    if (destination == Direction.None)
                    {
                        SetDestination();
                    }
                    if (adjacentSquares[(Int32)destination] != TerrainType.Impassable)
                    {
                        moveDir = destination;
                    }
                    else
                    {
                        FindOpenSquare();
                    }
                }
            }
            CheckStuck();
            Move(rover);

            return(rover.MovesLeft == 0 || rover.Power == 0);
        }