Beispiel #1
0
        public static TurnResult Turn(DirectionEnum direction, int acceleration)
        {
            var turnResult = client.Put(new SetStep
            {
                SessionId    = SessionId,
                Direction    = direction.ToString(),
                Acceleration = acceleration
            });

            CurrentMap.Update(turnResult.VisibleCells);
            Status       = turnResult.Status;
            Heading      = turnResult.Heading;
            CurrentCell  = CurrentMap.GetCell(turnResult.Location);
            CurrentSpeed = turnResult.Speed;
            if (GoneCells.ContainsKey(CurrentCell.Item1.vector3))
            {
                GoneCells[CurrentCell.Item1.vector3]++;
            }
            else
            {
                GoneCells[CurrentCell.Item1.vector3] = 1;
            }

            if (isVisualize)
            {
                visual.Get(new GetSession {
                    SessionId = SessionId
                });
            }

            Console.WriteLine($"Direction: {direction}, Acceleration: {acceleration}");
            return(turnResult);
        }
        /// <summary>
        /// this gets called automatically when we try and output to, or input from, a pin
        /// </summary>
        /// <param name="pin"></param>
        /// <param name="direction"></param>
        private void SetupPin(PinEnum pin, DirectionEnum direction)
        {
            //unexport if it we're using it already
            if (_outExported.Contains(pin) || _inExported.Contains(pin))
            {
                UnexportPin(pin);
            }

            //export
            File.WriteAllText(GPIO_PATH + "export", GetPinNumber(pin));

            Debug.WriteLine("exporting pin " + pin + " as " + direction);

            // set i/o direction
            File.WriteAllText(GPIO_PATH + pin + "/direction", direction.ToString().ToLower());

            //record the fact that we've setup that pin
            if (direction == DirectionEnum.OUT)
            {
                _outExported.Add(pin);
            }
            else
            {
                _inExported.Add(pin);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 防守
        /// </summary>
        public virtual TanksAction Defend()
        {
            DirectionEnum direction = DirectionEnum.LEFT;
            Random        random    = new Random(4);

            switch (random.Next())
            {
            case 0:
                direction = DirectionEnum.LEFT; break;

            case 1: direction = DirectionEnum.UP; break;

            case 2: direction = DirectionEnum.RIGHT; break;

            case 3: direction = DirectionEnum.DOWN; break;
            }
            return(new TanksAction()
            {
                UseGlod = IsGod,
                Length = this.TankInfo.SheCheng,
                Direction = direction.ToString(),
                TId = this.TankInfo.TId,
                ActionType = ActionTypeEnum.FIRE.ToString()
            });
        }
Beispiel #4
0
        /// <summary>
        /// Export the GPIO setting the direction. This creates the /sys/class/gpio/gpioXX directory.
        /// </summary>
        /// <param name="pin">The GPIO pin</param>
        /// <param name="direction"></param>
        private static void ExportPin(GPIOPins pin, DirectionEnum direction)
        {
            // If the pin is already exported, check it's in the proper direction
            if (_exportedPins.Keys.Contains((int)pin))
                // If the direction matches, return out of the function. If not, change the direction
                if (_exportedPins[(int)pin] == direction)
                    return;
                else
                {
                    // Set the direction on the pin and update the exported list
                    File.WriteAllText(GPIO_PATH + "gpio" + GetGPIONumber(pin) + "/direction", direction.ToString().ToLower());
                    _exportedPins[(int)pin] = direction;
                    return;
                }

            if (!Directory.Exists(GPIO_PATH + "gpio" + GetGPIONumber(pin)))
            {
                Debug.WriteLine("Exporting " + GetGPIONumber(pin));
                //export
                File.WriteAllText(GPIO_PATH + "export", GetGPIONumber(pin));
            }

            // set i/o direction
            Debug.WriteLine("Setting direction on pin " + pin + "/gpio " + (int)pin + " as " + direction);
            File.WriteAllText(GPIO_PATH + "gpio" + GetGPIONumber(pin) + "/direction", direction.ToString().ToLower());

            // Update the list of exported pins
            _exportedPins[(int)pin] = direction;
        }
Beispiel #5
0
        public void WhenRobotMoves_RobotIsAtCorrectPosition(DirectionEnum initalDirection, int x, int y, int newX, int newY)
        {
            var mdMock           = new Mock <IMessageDisplayer>();
            var messageDisplayer = mdMock.Object;
            var board            = new Board(5, 5);
            var robot            = new RobotProject.Robot();
            var game             = new RobotGame(board, robot, messageDisplayer);


            game.ProcessCommand($"PLACE {x} {y} {DirectionEnum.North.ToString().ToUpper()}");
            game.ProcessCommand($"MOVE");
            game.ProcessCommand($"REPORT");

            mdMock.Verify(m => m.DisplayMessage($"Output: {newX}, {newY}, { initalDirection.ToString()}"), Times.AtMostOnce());
        }
        /// <summary>
        /// this gets called automatically when we try and output to, or input from, a pin
        /// </summary>
        /// <param name="pin"></param>
        /// <param name="direction"></param>
        private void SetupPin(PinEnum pin, DirectionEnum direction)
        {
            //unexport if it we're using it already
            if (_outExported.Contains(pin) || _inExported.Contains(pin)) UnexportPin(pin);

            //export
            File.WriteAllText(GPIO_PATH + "export", GetPinNumber(pin));

            Debug.WriteLine("exporting pin " + pin + " as " + direction);

            // set i/o direction
            File.WriteAllText(GPIO_PATH + pin + "/direction", direction.ToString().ToLower());

            //record the fact that we've setup that pin
            if (direction == DirectionEnum.OUT)
                _outExported.Add(pin);
            else
                _inExported.Add(pin);
        }
Beispiel #7
0
        public Vector2 ToVector()
        {
            Vector2 ret       = new Vector2(0, 0);
            string  _tostring = direction.ToString();

            if (_tostring.Contains("Right"))
            {
                ret += Vector2.right;
            }
            if (_tostring.Contains("Left"))
            {
                ret += Vector2.left;
            }
            if (_tostring.Contains("Up"))
            {
                ret += Vector2.up;
            }
            if (_tostring.Contains("Down"))
            {
                ret += Vector2.down;
            }

            return(ret);
        }
Beispiel #8
0
 public override string ToString()
 {
     return(SystemEnum.ToString());
 }
Beispiel #9
0
        /// <summary>
        /// Rover move start process function
        /// </summary>
        /// <param name="coords"></param>
        /// <param name="directMoves"></param>
        public BaseOutputModel StartMoveOrientation(CoordinateModel coordInput, string orientations, PlateauModel plateauInput, DirectionEnum directionEnum = DirectionEnum.N)
        {
            var output = new BaseOutputModel {
                Success = true
            };

            XCoord         = coordInput.XCoord;
            YCoord         = coordInput.YCoord;
            RoverDirection = directionEnum;

            #region Control

            if (!PlateauCoordControl(plateauInput))
            {
                output.Error   = "!Coordinate Error: You coordinates ( " + XCoord + " , " + YCoord + " )" + ". Coordinates exceed plateu areas. You Plateaus: W => " + plateauInput.Width + " H=>" + plateauInput.Height + ". Please try again.";
                output.Success = false;
                return(output);
            }

            #endregion

            #region Move Function

            foreach (var orientation in orientations)
            {
                if (orientation == (char)MoveOrientationEnum.Left)
                {
                    LeftOrientation();
                }
                else if (orientation == (char)MoveOrientationEnum.Right)
                {
                    RightOrientation();
                }
                else if (orientation == (char)MoveOrientationEnum.Move)
                {
                    MoveOrientation();
                }
                else
                {
                    output.Error   = "Error : Unknown orientation you orientation " + orientation + " Orientation chracters (L,R,M). Please try again.";
                    output.Success = false;
                    return(output);
                }
            }
            #endregion

            output.Result = "XCoord : " + XCoord + " YCoord : " + YCoord + " Direction : " + RoverDirection.ToString();
            return(output);
        }
Beispiel #10
0
        /// <summary>
        /// Export the GPIO setting the direction. This creates the /sys/class/gpio/gpioXX directory.
        /// </summary>
        /// <param name="pin">The GPIO pin</param>
        /// <param name="direction"></param>
        private static void ExportPin(GPIOPins pin, DirectionEnum direction)
        {
            // If the pin is already exported, check it's in the proper direction
            if (_exportedPins.Keys.Contains((int)pin))
            {
                // If the direction matches, return out of the function. If not, change the direction
                if (_exportedPins[(int)pin] == direction)
                {
                    return;
                }
                else
                {
                    // Set the direction on the pin and update the exported list
                    File.WriteAllText(GPIO_PATH + "gpio" + GetGPIONumber(pin) + "/direction", direction.ToString().ToLower());
                    _exportedPins[(int)pin] = direction;
                    return;
                }
            }

            if (!Directory.Exists(GPIO_PATH + "gpio" + GetGPIONumber(pin)))
            {
                Debug.WriteLine("Exporting " + GetGPIONumber(pin));
                //export
                File.WriteAllText(GPIO_PATH + "export", GetGPIONumber(pin));
            }

            // set i/o direction
            Debug.WriteLine("Setting direction on pin " + pin + "/gpio " + (int)pin + " as " + direction);
            File.WriteAllText(GPIO_PATH + "gpio" + GetGPIONumber(pin) + "/direction", direction.ToString().ToLower());

            // Update the list of exported pins
            _exportedPins[(int)pin] = direction;
        }
Beispiel #11
0
 public static string ToString(DirectionEnum dircetion)
 {
     return(dircetion.ToString().ToLower());
 }
 public override string ToString()
 {
     return(direction.ToString());
 }