Наследование: MonoBehaviour
Пример #1
0
        static void Main(string[] args)
        {
            var mars = new Mars();

            mars.Robots = new List <Robot>()
            {
                new Robot("Robot A"),
                new Robot("Robot B")
            };


            Console.WriteLine("Gezegen uzunluğunu Belirt");
            mars.SetSurface(Console.ReadLine()); // mars gezegeninin uzunluğu belirlenir

            foreach (var robot in mars.Robots)
            {
                Console.WriteLine($"{robot.Name} Konumunu Gir");
                robot.Location = Console.ReadLine().ToLocation(); // robotun konumu belirlenir

                Console.WriteLine($"{robot.Name} Hareketlerini Gir");
                robot.Movement(Console.ReadLine()); // robot hareketleri girilir
            }

            mars.CheckRobotsCoordinat(); // gezegen için belirlenen koordinatların dışına çıkılmışsa max koordinat setlenir

            foreach (var robot in mars.Robots)
            {
                Console.WriteLine($"{robot.Name} : {robot.Location.X} - {robot.Location.Y} -  {robot.Location.Direction}");
            }

            Console.ReadLine();
        }
Пример #2
0
        public static void Main()
        {
            try
            {
                // we will randomize the start position and facing
                //(it's not specified what should be the initial location/facing)

                var rover = Mars.StartExpedition(new Map(4, 4));

                if (rover != null)
                {
                    while (true)
                    {
                        Console.WriteLine(rover.StatusString());
                        var command = Console.ReadLine();

                        var commandResult = rover.ExecuteCommand(command);
                        if (!commandResult)
                        {
                            Console.WriteLine(commandResult?.Message);
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Expedition not started. Terminating.");
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Пример #3
0
        public IActionResult Index()
        {
            DateTime birthday  = new DateTime(1991, 6, 5, 8, 26, 00);
            Equator  equator   = Sun.EquatorialCoordinate(birthday);
            Ecliptic mooquator = Moon.EclipticalCoordinate(birthday);
            Ecliptic merquator = Mercury.EclipticalCoordinate(birthday);
            Ecliptic vequator  = Venus.EclipticalCoordinate(birthday);
            Ecliptic mequator  = Mars.EclipticalCoordinate(birthday);
            Ecliptic jequator  = Jupiter.EclipticalCoordinate(birthday);
            Ecliptic sequator  = Saturn.EclipticalCoordinate(birthday);
            Ecliptic urquator  = Uranus.EclipticalCoordinate(birthday);
            Ecliptic nequator  = Neptune.EclipticalCoordinate(DateTime.Now);
            Ecliptic ecliptic  = CoordinateSystem.Equatorial2Ecliptic(equator);

            Debug.WriteLine(DateTime.Now);
            Debug.WriteLine("SUN" + ecliptic.Longitude);
            Debug.WriteLine("Moon" + mooquator.Longitude);
            Debug.WriteLine("MERC: " + merquator.Longitude);
            Debug.WriteLine("VENUS" + vequator.Longitude);
            Debug.WriteLine("Mars" + mequator.Longitude);
            Debug.WriteLine("Jup: " + jequator.Longitude);
            Debug.WriteLine("Saturn: " + sequator.Longitude);
            Debug.WriteLine("Urnuas: " + urquator.Longitude);
            Debug.WriteLine("Neptune: " + nequator.Longitude);

            return(View());
        }
Пример #4
0
        public void TestRobots()
        {
            Mars world = Mars.GetInstance().InitializeWorld(_initialization);
            var  bot1  = new MarsBot(1);
            var  bot2  = new MarsBot(2);
            var  bot3  = new MarsBot(3);

            foreach (var inst in _bot1Instructions)
            {
                bot1.ProcessInstructions(inst);
            }

            foreach (var inst in _bot2Instructions)
            {
                bot2.ProcessInstructions(inst);
            }

            foreach (var inst in _bot3Instructions)
            {
                bot3.ProcessInstructions(inst);
            }

            Assert.AreEqual(new Tuple <int, int>(1, 1), bot1.State.CurrPosition);
            Assert.AreEqual(Orientation.E, bot1.State.CurrOrientation);
            Assert.AreEqual(new Tuple <int, int>(3, 3), bot2.State.CurrPosition);
            Assert.AreEqual(Orientation.N, bot2.State.CurrOrientation);
            Assert.AreEqual(new Tuple <int, int>(2, 3), bot3.State.CurrPosition);
            Assert.AreEqual(Orientation.S, bot3.State.CurrOrientation);
        }
Пример #5
0
        public void Test_MMRMMRMRRM_Input()
        {
            Face             face            = new Face('E');
            Position         position        = new Position(3, 3);
            ILand            land            = new Mars(5, 5);
            IRover           rover           = new Rover(face, position, land);
            ICommandExecutor commandExecutor = new CommandExecutor();
            List <ICommand>  commands        = new List <ICommand>()
            {
                new Command('M'),
                new Command('M'),
                new Command('R'),
                new Command('M'),
                new Command('M'),
                new Command('R'),
                new Command('M'),
                new Command('R'),
                new Command('R'),
                new Command('M')
            };

            Discovery discovery = new Discovery(rover, commands, commandExecutor);

            Assert.Equal("5 1 E", discovery.ToString());
        }
Пример #6
0
    void Update()
    {
        Sun.Rotate(Vector3.up * Time.deltaTime * 5);

        Mercury.RotateAround(Sun.position, new Vector3(0.1f, 1, 0), 60 * Time.deltaTime);
        Mercury.Rotate(Vector3.up * 10000 / 58 * Time.deltaTime);

        Venus.RotateAround(Sun.position, new Vector3(0, 1, -0.1f), 55 * Time.deltaTime);
        Venus.Rotate(Vector3.up * 10000 / 243 * Time.deltaTime);

        Earth.RotateAround(Sun.position, Vector3.up, 50 * Time.deltaTime);
        Earth.Rotate(Vector3.up * 10000 * Time.deltaTime);
        Moon.RotateAround(Earth.position, Vector3.up, 5 * Time.deltaTime);
        Moon.Rotate(Vector3.up * 10000 / 27 * Time.deltaTime);

        Mars.RotateAround(Sun.position, new Vector3(0.2f, 1, 0), 45 * Time.deltaTime);
        Mars.Rotate(Vector3.up * 10000 * Time.deltaTime);

        Jupiter.RotateAround(Sun.position, new Vector3(-0.1f, 2, 0), 38 * Time.deltaTime);
        Jupiter.Rotate(Vector3.up * 10000 / 0.3f * Time.deltaTime);

        Saturn.RotateAround(Sun.position, new Vector3(0, 1, 0.2f), 36 * Time.deltaTime);
        Saturn.Rotate(Vector3.up * 10000 / 0.4f * Time.deltaTime);

        Uranus.RotateAround(Sun.position, new Vector3(0, 2, 0.1f), 35 * Time.deltaTime);
        Uranus.Rotate(Vector3.up * 10000 / 0.6f * Time.deltaTime);

        Neptune.RotateAround(Sun.position, new Vector3(-0.1f, 1, -0.1f), 33 * Time.deltaTime);
        Neptune.Rotate(Vector3.up * 10000 / 0.7f * Time.deltaTime);
    }
Пример #7
0
        public void MoveRobot(Mars planet, Robot robot, string command)
        {
            if (robot.IsLost)
            {
                return;
            }

            switch (command)
            {
            case "R":
                RotateRight(robot);
                break;

            case "L":
                RotateLeft(robot);
                break;

            case "F":
                MoveForward(planet, robot);
                break;

            default:
                throw new Exception("Unknown Command");
            }
        }
Пример #8
0
        public void test_rover_actions()
        {
            Mars m = new Mars();
            Rov  r = new Rov("1", "2", Directions.North, m);

            Assert.Equal(1, r.DisplayVectorPositionX());
            Assert.Equal(2, r.DisplayVectorPositionY());
            Assert.Equal(Directions.North, r.DisplayVectorPositionD());

            r.PassInstruction("F");
            Assert.Equal(1, r.DisplayVectorPositionX());
            Assert.Equal(3, r.DisplayVectorPositionY());
            Assert.Equal(Directions.North, r.DisplayVectorPositionD());

            r.PassInstruction("L");
            Assert.Equal(1, r.DisplayVectorPositionX());
            Assert.Equal(3, r.DisplayVectorPositionY());
            Assert.Equal(Directions.NorthWest, r.DisplayVectorPositionD());

            r.PassInstruction("F");
            Assert.Equal(0, r.DisplayVectorPositionX());
            Assert.Equal(4, r.DisplayVectorPositionY());
            Assert.Equal(Directions.NorthWest, r.DisplayVectorPositionD());

            r.PassInstruction("R");
            Assert.Equal(0, r.DisplayVectorPositionX());
            Assert.Equal(4, r.DisplayVectorPositionY());
            Assert.Equal(Directions.North, r.DisplayVectorPositionD());

            r.PassInstruction("F");
            Assert.Equal(0, r.DisplayVectorPositionX());
            Assert.Equal(5, r.DisplayVectorPositionY());
            Assert.Equal(Directions.North, r.DisplayVectorPositionD());
        }
Пример #9
0
        public void Rover_Rotate_Left_Check()
        {
            var rover = Mars.StartExpedition(new Map(4, 4), new MapCoordinates(0, 0), RoverFacing.North);

            Assert.IsNotNull(rover);

            var actionResult = rover.ExecuteCommand(RoverCommands.ROTATE_LEFT_CMD);

            Assert.AreEqual(actionResult.Success, true);
            Assert.AreEqual(rover.Status.Facing, RoverFacing.West);

            actionResult = rover.ExecuteCommand(RoverCommands.ROTATE_LEFT_CMD);
            Assert.AreEqual(actionResult.Success, true);
            Assert.AreEqual(rover.Status.Facing, RoverFacing.South);

            actionResult = rover.ExecuteCommand(RoverCommands.ROTATE_LEFT_CMD);
            Assert.AreEqual(actionResult.Success, true);
            Assert.AreEqual(rover.Status.Facing, RoverFacing.East);

            actionResult = rover.ExecuteCommand(RoverCommands.ROTATE_LEFT_CMD);
            Assert.AreEqual(actionResult.Success, true);
            Assert.AreEqual(rover.Status.Facing, RoverFacing.North);

            Assert.AreEqual(rover.Status.Position.AsText(), "(0,0)");
        }
Пример #10
0
        public void test_map_size()
        {
            Mars map = new Mars();

            Assert.Equal(5, map.size.X);
            Assert.Equal(5, map.size.Y);
        }
Пример #11
0
        public void GetMarsRobotsAndCommandSequences()
        {
            //arrange
            var input =
                @"50 30
13 12 N
FRRFLLFFRRFLL
";
            var mars           = new Mars(50, 30);
            var expectedRobots = new List <Robot>()
            {
                new Robot(13, 12, Orientation.north, mars)
            };
            var expectedCommandSequences = new List <List <Command> > {
                new Mocks().GetCommandSequence()
            };

            //act
            List <Robot>           actualRobots;
            List <List <Command> > actualCommandSequences;

            Input.GetRobotsAndCommandSequences(input, out actualRobots, out actualCommandSequences);

            //assert
            Assert.That(actualRobots, IsDeeplyEqual.To(expectedRobots));
            Assert.That(actualCommandSequences, IsDeeplyEqual.To(expectedCommandSequences));
        }
Пример #12
0
        public void Run()
        {
            Console.WriteLine("Running study case process...");
            Console.WriteLine("-----------------------------------");
            Console.WriteLine("Mars right and top coordinate: 5 and 5");
            var localMars = new Mars(5, 5);

            Console.WriteLine("-----------------------------------");
            Console.WriteLine("Add first rover on position: 1 2 N");
            localMars.AddRover(1, 2, Direction.N);

            Console.WriteLine("Run control command in first rover: LMLMLMLMM");
            localMars.ProcessControlCommands("LMLMLMLMM");

            Console.Write("First rover current position: ");
            Console.WriteLine(localMars.GetRoverPosition());

            Console.WriteLine("-----------------------------------");
            Console.WriteLine("Add second rover on position: 3 3 E");
            localMars.AddRover(3, 3, Direction.E, true);

            Console.WriteLine("Run control command in second rover: MMRMMRMRRM");
            localMars.ProcessControlCommands("MMRMMRMRRM");

            Console.Write("Second rover current position: ");
            Console.WriteLine(localMars.GetRoverPosition());
            Console.WriteLine("-----------------------------------");
        }
Пример #13
0
        private void LoadSolarSystem()
        {
            _sun = new Sun(DVector2.Zero, DVector2.Zero);

            var mercury = new Mercury();
            var venus   = new Venus();
            var earth   = new Earth();
            var moon    = new Moon(earth.Position, earth.Velocity);
            var mars    = new Mars();
            var jupiter = new Jupiter();
            var europa  = new Europa(jupiter.Position + new DVector2(6.64862e8, 0), jupiter.Velocity + new DVector2(0, -13740));
            var saturn  = new Saturn();

            _massiveBodies = new List <IMassiveBody>
            {
                _sun, mercury, venus, earth, moon, mars, jupiter, europa, saturn
            };

            //_spaceCrafts = SpacecraftFactory.BuildFalconHeavy(earth, ProfileDirectory);
            //_spaceCrafts = SpacecraftFactory.BuildDragonV2Abort(earth, ProfileDirectory);
            _spaceCrafts = SpacecraftFactory.BuildDragonV2Entry(earth, ProfileDirectory);
            //_spaceCrafts = SpacecraftFactory.BuildF9(earth, ProfileDirectory);
            //_spaceCrafts = SpacecraftFactory.BuildF9Dragon(earth, ProfileDirectory);

            // Initialize the spacecraft controllers
            foreach (ISpaceCraft spaceCraft in _spaceCrafts)
            {
                spaceCraft.InitializeController(ProfileDirectory, _eventManager);
            }

            // Start at nearly -Math.Pi / 2
            _strongback = new Strongback(-1.5707947, _spaceCrafts[0].TotalHeight * 0.05, earth);

            // Start downrange at ~300km
            var asds = new ASDS(-1.62026, 20, earth);

            _gravitationalBodies = new List <IGravitationalBody>
            {
                _sun, mercury, venus, earth
            };

            foreach (ISpaceCraft spaceCraft in _spaceCrafts)
            {
                _gravitationalBodies.Add(spaceCraft);
            }

            _structures = new List <StructureBase>
            {
                _strongback, //asds
            };

            _gravitationalBodies.Add(moon);
            _gravitationalBodies.Add(mars);
            _gravitationalBodies.Add(jupiter);
            _gravitationalBodies.Add(europa);
            _gravitationalBodies.Add(saturn);

            // Target the spacecraft
            _targetIndex = _gravitationalBodies.IndexOf(_spaceCrafts.FirstOrDefault());
        }
Пример #14
0
        public void Move_rover_on_Mars()
        {
            // arrange
            var mars    = new Mars(_plateau);
            var results = new List <Location>();

            // action
            var robotIds = mars.DeployRovers(_locations).ToList();

            robotIds.ForEach(x => results.Add(mars.MoveRobot(x, "M")));

            //assert
            Assert.NotNull(results);

            Assert.Equal(_locations.Count, robotIds.Count);

            Assert.Equal(_locations.Count, results.Count);

            for (var i = 0; i < _locations.Count; i++)
            {
                Assert.Equal(_locations[i].Orientation, results[i].Orientation);

                switch (_locations[i].Orientation)
                {
                case Orientation.N:
                {
                    Assert.Equal(_locations[i].X, results[i].X);

                    Assert.Equal(_locations[i].Y + 1, results[i].Y);
                }
                break;

                case Orientation.E:
                {
                    Assert.Equal(_locations[i].X + 1, results[i].X);

                    Assert.Equal(_locations[i].Y, results[i].Y);
                }
                break;

                case Orientation.S:
                {
                    Assert.Equal(_locations[i].X, results[i].X);

                    Assert.Equal(_locations[i].Y - 1, results[i].Y);
                }
                break;

                case Orientation.W:
                {
                    Assert.Equal(_locations[i].X - 1, results[i].X);

                    Assert.Equal(_locations[i].Y, results[i].Y);
                }
                break;
                }
                ;
            }
        }
Пример #15
0
 public MarsWorld(MarsRover rover, Mars mars, int n, int m)
 {
     InitializeComponent();
     _marsRover = rover;
     _mars      = mars;
     _n         = n;
     _m         = m;
 }
Пример #16
0
        public void PositionOnMars2()
        {
            var _mars    = new Mars(new Tuple <uint, uint> (100, 100));
            var result   = _mars.Size.PositionOnMars(new Tuple <int, int> (100, -1));
            var expected = new Tuple <uint, uint> (100, 100);

            Assert.AreEqual(expected, result);
        }
Пример #17
0
        static void Main(string[] args)
        {
            Mars mars = new Mars(new ConsoleInputService(), new ConsoleOutputService(), new Direction());

            mars.CreateMap();
            mars.GenerateRovers();
            mars.RunRovers();
        }
Пример #18
0
 public void RobotFellOffMars(Mars mars)
 {
     Lost = true;
     mars.lostRobots.Add(new LostRobotScent()
     {
         PreLostPositon = CurrentPosition
     });
 }
Пример #19
0
        static void Main(string[] args)
        {
            RegisterServices();

            List <string> lines = new List <string>();
            string        line;

            while ((line = Console.ReadLine()) != null)
            {
                if (string.IsNullOrEmpty(line))
                {
                    break;
                }

                lines.Add(line);
            }

            if (lines.Any())
            {
                var planetSize = lines[0].Split(' ');

                var planet = new Mars
                {
                    X = Convert.ToInt32(planetSize[0]),
                    Y = Convert.ToInt32(planetSize[1])
                };

                IServiceScope scope         = _serviceProvider.CreateScope();
                var           robotBusiness = scope.ServiceProvider.GetRequiredService <IRobotBusiness>();

                List <string> result = new List <string>();
                for (int i = 1; i < lines.Count;)
                {
                    var robotCoordinates = lines[i].Split(' ');

                    var robot = new Robot
                    {
                        X         = Convert.ToInt32(robotCoordinates[0]),
                        Y         = Convert.ToInt32(robotCoordinates[1]),
                        Direction = robotCoordinates[2]
                    };

                    foreach (var command in lines[i + 1])
                    {
                        robotBusiness.MoveRobot(planet, robot, command.ToString());
                    }

                    result.Add(robot.PrintLocation());

                    i += 2;
                }

                result.ForEach(x => Console.WriteLine(x));
            }


            DisposeServices();
        }
Пример #20
0
 public void OnButtonPressed(VirtualButtonBehaviour vb)
 {
     if (vb.VirtualButtonName == "previewvb")
     {
         Sun.SetActive(false);
         Mercury.SetActive(false);
         Venus.SetActive(false);
         Earth.SetActive(false);
         Moon.SetActive(false);
         Mars.SetActive(false);
         Sun1.SetActive(true);
         Mercury1.SetActive(true);
         Venus1.SetActive(true);
         Earth1.SetActive(true);
         Moon1.SetActive(true);
         Mars1.SetActive(true);
         videoplane.SetActive(false);
     }
     else if (vb.VirtualButtonName == "animationvb")
     {
         UnityEngine.Debug.Log("animationvb Button pressed");
         Sun.SetActive(true);
         Mercury.SetActive(true);
         Venus.SetActive(true);
         Earth.SetActive(true);
         Moon.SetActive(true);
         Mars.SetActive(true);
         Sun1.SetActive(false);
         Mercury1.SetActive(false);
         Venus1.SetActive(false);
         Earth1.SetActive(false);
         Moon1.SetActive(false);
         Mars1.SetActive(false);
         videoplane.SetActive(false);
     }
     else if (vb.VirtualButtonName == "videovb")
     {
         UnityEngine.Debug.Log("Traveller Button pressed");
         Sun.SetActive(false);
         Mercury.SetActive(false);
         Venus.SetActive(false);
         Earth.SetActive(false);
         Moon.SetActive(false);
         Mars.SetActive(false);
         Sun1.SetActive(false);
         Mercury1.SetActive(false);
         Venus1.SetActive(false);
         Earth1.SetActive(false);
         Moon1.SetActive(false);
         Mars1.SetActive(false);
         videoplane.SetActive(true);
     }
     else
     {
         throw new UnityException(vb.VirtualButtonName + "Virtual Button not supported");
     }
 }
Пример #21
0
        public void Test_to_check_max_x_capacity()
        {
            Mars mars = new Mars(new Coordinate()
            {
                x = 15, y = 20
            });

            mars.mapSize.x.Should().Be(15);
        }
Пример #22
0
        public void Rover_PositionDisplay_Check()
        {
            var rover = Mars.StartExpedition(new Map(4, 4), new MapCoordinates(1, 1), RoverFacing.North);

            Assert.IsNotNull(rover);
            Assert.AreEqual(rover.Status.Position.X, 1);
            Assert.AreEqual(rover.Status.Position.Y, 1);
            Assert.AreEqual(rover.Status.Position.AsText(), "(1,1)");
        }
Пример #23
0
 private void image3_Tap(object sender, System.Windows.Input.GestureEventArgs e)
 {
     if (i == 1)
     {
         Mars.Begin();
         i = 2;
         PresentTheAttributes(3);
     }
 }
Пример #24
0
        public void Mars_CalculateOutOfBoundaryHorizontal()
        {
            Mars mars = new Mars(10, 10);

            Position position = mars.CalculateOutOfBoundaryPosition(new Position(10, 5));

            Assert.AreEqual(0, position.X);
            Assert.AreEqual(5, position.Y);
        }
Пример #25
0
        public void Mars_CalculateUnderBoundaryBoth()
        {
            Mars mars = new Mars(10, 10);

            Position position = mars.CalculateOutOfBoundaryPosition(new Position(-4, -56));

            Assert.AreEqual(6, position.X);
            Assert.AreEqual(4, position.Y);
        }
Пример #26
0
        public void Mars_CalculateUnderBoundaryVertically()
        {
            Mars mars = new Mars(10, 10);

            Position position = mars.CalculateOutOfBoundaryPosition(new Position(5, -1));

            Assert.AreEqual(5, position.X);
            Assert.AreEqual(9, position.Y);
        }
Пример #27
0
 public MarsBot(int id)
 {
     ID     = id;
     Active = true;
     State  = new State
     {
         CurrPosition = new Tuple <int, int>(0, 0)
     };
     _world = Mars.GetInstance();
 }
Пример #28
0
 private void ProcessRobotLost(Mars mars, Robot robot)
 {
     // if a robot is going to be lost we fisrt need to check for previous lost robots.
     // If we had a robot lost in the same position the previous robots lost scent saves
     // this robot as it does not process the command.
     if (!mars.HasRobotBeenLostFromSamePosition(robot))
     {
         robot.RobotFellOffMars(mars);
     }
 }
Пример #29
0
        public void Move_invalid_location_rover_on_Mars()
        {
            // arrange
            var mars = new Mars(_plateau);

            //assert
            Assert.Throws <InvalidOperationException>(() => mars.DeployRovers(new List <Location> {
                new Location(1, 1000, Orientation.N)
            }));
        }
Пример #30
0
 void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
     }
     else
     {
         Destroy(this.gameObject);
     }
 }