Beispiel #1
0
        public void TestRobotPlace()
        {
            const string cmd         = "PLACE 1,2,NORTH";
            var          moveOutcome = _robot.Action(cmd);

            moveOutcome.ShouldNotBeNull();
            moveOutcome.Result.ShouldBe(OutcomeStatus.Success);
            _mockExecutor.Received().ExecuteCommand(cmd);
        }
Beispiel #2
0
 public void AndWhenTheRobotMovesForwardFourSpaces()
 {
     moveOutcome = Robot.Action(RobotCommands.Move); //1,1,NORTH
     moveOutcome = Robot.Action(RobotCommands.Move); //1,2,NORTH
     moveOutcome = Robot.Action(RobotCommands.Move); //1,3,NORTH
     moveOutcome = Robot.Action(RobotCommands.Move); //1,4,NORTH
 }
        public void Then_the_position_report_is_2_3_EAST()
        {
            var outcome        = Robot.Action(RobotCommands.Report) as ReportOutcome;
            var positionReport = outcome?.PositionReport;

            positionReport.ShouldNotBeNull();
            outcome.Message.ShouldBe("2,3,EAST");
        }
Beispiel #4
0
        public void Then_the_robot_should_be_at_4_4_EAST()
        {
            var outcome = Robot.Action(RobotCommands.Report) as ReportOutcome;

            outcome.ShouldNotBeNull();
            outcome.Message.ShouldBe("4,4,EAST");

            var positionReport = outcome?.PositionReport;

            positionReport.Orientation.ShouldBe(Orientation.EAST);
            positionReport.PositionX.ShouldBe(4);
            positionReport.PositionY.ShouldBe(4);
        }
Beispiel #5
0
        public void AndThenTheRobotCanContinueToMove()
        {
            Robot.Action(RobotCommands.TurnLeft);
            Robot.Action(RobotCommands.TurnLeft);
            Robot.Action(RobotCommands.Move);
            Robot.Action(RobotCommands.Move);

            var positionReport = GetPositionReport();

            positionReport.ShouldNotBeNull();
            positionReport.Orientation.ShouldBe(Orientation.NORTH);
            positionReport.PositionX.ShouldBe(0);
            positionReport.PositionY.ShouldBe(2);
            positionReport.ToString().ShouldBe("0,2,NORTH");
        }
Beispiel #6
0
        void NextStep(object sender, EventArgs e)
        {
            ManySteps++;

            byte command = Utils.PrepereCommand((byte)Steps, StepsDirection - Direction);

            try
            {
                Utils.ParseResponse(Robot.Action(command), out Energy, out Distance);

                Position  = Vector.FromPolar(StepsDirection).Multiply(Steps).Add(Position);
                Direction = Utils.To360Deg(StepsDirection);
                AfterSelectAim(NextTarget());

                Ai.OnMove(Position, Distance);
                GameMap.GoRobot(Position, Direction);

                UpdateInfoTable();

                if (Distance == 0)
                {
                    OpenDialog(new Winner(ResetWindow, Position, ManySteps, Energy));
                }
                else if (Energy == 0)
                {
                    OpenDialog(new BatteryDead(ResetWindow));
                }
            }
            catch (BatteryException)
            {
                OpenDialog(new BatteryDead(ResetWindow));
            }
            catch (Exception err)
            {
                OpenDialog(new Fail(ResetWindow, err.Message));
            }
        }
Beispiel #7
0
 public void AndWhenTheRobotTurnsToTheLeft()
 {
     moveOutcome = Robot.Action(RobotCommands.TurnLeft); //1,0,NORTH
 }
Beispiel #8
0
 public void WhenTheRobotMovesForwardOneSpace()
 {
     moveOutcome = Robot.Action(RobotCommands.Move); //1,0,EAST
 }
Beispiel #9
0
 public void AndGivenTheRobotHasBeenPlacedOnTheTable()
 {
     Robot.Action("PLACE 0,0,EAST");
 }
Beispiel #10
0
 public void WhenTheRobotReceivesAMoveCommand()
 {
     moveOutcome = Robot.Action(RobotCommands.Move);
 }
Beispiel #11
0
 public void AndGivenTheRobotHasBeenPlacedOnTheEdgeOfTheTable()
 {
     Robot.Action("PLACE 0,0,SOUTH");
 }
Beispiel #12
0
        protected PositionReport GetPositionReport()
        {
            var outcome = Robot.Action(RobotCommands.Report) as ReportOutcome;

            return(outcome?.PositionReport);
        }
 public void WhenTheRobotReceivesAPlaceCommandWithOutOfBoundsPosition()
 {
     moveOutcome = Robot.Action("PLACE 1,7,EAST");
 }
Beispiel #14
0
 public void AndWhenTheRobotMovesForwardThreeSpaces()
 {
     moveOutcome = Robot.Action(RobotCommands.Move); //1,4,EAST
     moveOutcome = Robot.Action(RobotCommands.Move); //2,4,EAST
     moveOutcome = Robot.Action(RobotCommands.Move); //3,4,EAST
 }
 public void WhenTheRobotReportCommandIsInvoked()
 {
     Robot.Action(RobotCommands.Report);
 }
 public void WhenTheRobotTurnsLeft()
 {
     Robot.Action(RobotCommands.TurnLeft);
 }
 public void AndWhenTheRobotReceivesAPlaceCommand()
 {
     moveOutcome = Robot.Action("PLACE 4,4,WEST");
 }
 public void AndWhenTheRobotReceivesATurnCommand()
 {
     moveOutcome = Robot.Action(RobotCommands.TurnLeft);
 }
Beispiel #19
0
        static void Main(string[] args)
        {
            Console.WriteLine("Program Robot Marsjański - wersja tekstowa");
            Console.WriteLine();
            Console.WriteLine("INSTRUKCJA");
            Console.WriteLine();
            Console.WriteLine("Podaj komendę: 'kroki kierunek' (np: 10 1)");
            Console.WriteLine("0 - do przodu");
            Console.WriteLine("1 - w lewo");
            Console.WriteLine("2 - w prawo");
            Console.WriteLine("3 - wstecz");
            Console.WriteLine();
            Console.WriteLine("komenda 'a' - użyj bota");
            Console.WriteLine("'enter' dalej");
            Console.WriteLine("'spacja' anuluj");

            while (Console.Read() != ' ')
            {
                Console.ReadLine();
                Console.Clear();

                RobotAIController ai = new RobotAIController();

                Vector target = Vector.FromPolar(Rand.NextDouble() * 2 * Math.PI, Rand.Next(0, 65));

                Robot robot = new Robot(target.X, target.Y, 150);

                // Console.WriteLine(target);

                bool targetComplete = false;

                try
                {
                    do
                    {
                        Console.Write("Ruch: ");
                        string command = Console.ReadLine();

                        string[] commands = command.Split(' ').ToArray();

                        Vector pos;

                        byte steps;
                        int  direction;

                        if (commands[0] == "a")
                        {
                            pos = ai.PredictMove();

                            int[] tmp = ai.MoveCommand(pos);

                            steps     = (byte)tmp[0];
                            direction = tmp[1];
                            Console.WriteLine($"AI: s: {steps} D: {direction} pos: {pos}");
                        }
                        else
                        {
                            steps = Convert.ToByte(commands[0]);

                            direction = commands.Length == 1 ? 0 : Convert.ToInt32(commands[1]);
                        }

                        switch (direction)
                        {
                        case 1:
                            pos = ai.PositionFrom(steps, 90);
                            break;

                        case 2:
                            pos = ai.PositionFrom(steps, -90);
                            break;

                        case 3:
                            pos = ai.PositionFrom(steps, 180);
                            break;

                        default:
                            pos = ai.PositionFrom(steps, 0);
                            break;
                        }

                        if (commands[0] != "a")
                        {
                            Console.WriteLine($"U: s: {steps} D: {direction} pos: {pos}");
                        }

                        byte action = Utils.PrepereCommand(steps, (byte)direction);

                        short response = robot.Action(action);

                        int accumulator;
                        int distance;

                        Utils.ParseResponse(response, out accumulator, out distance);

                        ai.OnMove(pos, distance);

                        targetComplete = distance == 0;

                        Console.WriteLine(ResponseToString(accumulator, distance));

                        if (targetComplete)
                        {
                            Console.WriteLine($"Osiągnięto cel !!! {target}");
                        }
                    } while (!targetComplete);
                }
                catch (Exception err)
                {
                    Console.WriteLine(err.Message);
                }
                Console.WriteLine();
                Console.WriteLine("Nie ma siły powtarzamy misje");
            }

            Console.WriteLine("Robot spełnił swoje zadanie, dziękujemy panie kapitanie");
            Console.WriteLine("Kamil Mikołajczuk @ 2018");
            Console.ReadKey();
        }
Beispiel #20
0
 public void AndWhenTheRobotTurnsToTheRight()
 {
     moveOutcome = Robot.Action(RobotCommands.TurnRight); //1,4,EAST
 }
 public void WhenTheRobotMoveOneSpace()
 {
     Robot.Action(RobotCommands.Move);
 }
 public void WhenTheRobotReceivesAPlaceCommand()
 {
     moveOutcome = Robot.Action("PLACE 1,2,EAST");
 }
Beispiel #23
0
 public void WhenTheRobotReceivesAnInvalidCommand()
 {
     moveOutcome = Robot.Action("10 PRINT \"Hello world\"; 20 GOTO 10;");
 }