Esempio n. 1
0
 /// <summary>
 /// デフォルト通信設定
 /// </summary>
 public void SetDefaultCommnicationSetting()
 {
     _comPort     = ComPortSettingDatas.DEFAULT_COM_PORT_NUM;
     _baudrate    = ComPortSettingDatas.DEFAULT_BAUDRATE;
     _parity      = ComPortSettingDatas.DEFAULT_PARITY;
     _dataBit     = ComPortSettingDatas.DEFAULT_DATA_BIT;
     _stopBit     = ComPortSettingDatas.DEFAULT_STOP_BIT;
     _flowControl = ComPortSettingDatas.DEFAULT_FLOW_CONTROL;
 }
Esempio n. 2
0
 /// <summary>
 ///     Generates random number within range with an even or odd parity
 /// </summary>
 /// <param name="min">inclusive minimum value</param>
 /// <param name="max">inclusive maximum value</param>
 /// <param name="parity">Even or Odd parity</param>
 /// <returns></returns>
 public static int GetParityRandom(int min, int max, ParityEnum parity)
 {
     if (parity == ParityEnum.Even)
     {
         var num = _random.Next(min, max);
         return((num % 2 != 0) & (num < max) ? num + 1 : (num % 2 != 0) & (num > min) ? num - 1 : num);
     }
     else
     {
         var num = _random.Next(min, max);
         return((num % 2 == 0) & (num < max) ? num + 1 : (num % 2 == 0) & (num > min) ? num - 1 : num);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Returns a TriangleEnum representing the triangle (within the current slice, either
        /// top or bottom, that the point belongs to).
        /// </summary>
        /// <param name="withinSlice">A point on the x-z cartesian plane, relative to the top-left
        /// of the current slice.</param>
        /// <param name="parity">The "parity" of the slice, indicating wither the border seaparting
        /// the two triangles within the slice goes from top-left to bottom-right (ODD) or
        /// bottom-left to top-right (EVEN).</param>
        /// <returns>A TriangleEnum representing the triangle (within the current slice, either
        /// top or bottom, that the point belongs to).</returns>
        private TriangleEnum WhichTriangle(Vec2D withinSlice, ParityEnum parity)
        {
            float xFraction = withinSlice.x / Slice.x;
            float yBorder   = 0f;

            if (parity == ParityEnum.Even)
            {
                // When parity is even, the border is bottom-left to top-right.
                yBorder = Slice.y * xFraction;
            }
            else
            {
                // When parity is odd, the border is top-left to bottom-right.
                yBorder = Slice.y * (1f - xFraction);
            }

            return((withinSlice.y < yBorder) ? TriangleEnum.Top : TriangleEnum.Bottom);
        }
Esempio n. 4
0
        PointToDirectionInHex(Vec2D point)
        {
            AxialHexCoord axial = PointToCubic(point).ToAxial();
            //AxialHexCoord axial = PointToAxial( point );

            Vec2D center      = AxialToPoint(axial);
            Vec2D topLeft     = center - new Vec2D(0.5f * SQRT_3 * HexRadius, HexRadius);
            Vec2D fromTopLeft = point - topLeft;

            int hSlice = (int)Math.Floor(fromTopLeft.x / Slice.x);
            int vSlice = (int)Math.Floor(fromTopLeft.y / Slice.y);

            Vec2D withinSlice = new Vec2D(
                fromTopLeft.x % Slice.x,
                fromTopLeft.y % Slice.y
                );

            ParityEnum parity = ParityEnum.Even;

            if (((hSlice & 1) + (vSlice & 1)) == 1)
            {
                // One of the two dimensions is odd, otherwise parity is even by default.
                parity = ParityEnum.Odd;
            }

            //
            // Debugging output associated with a horrible bug in PointToCubic()
            //
            //Console.WriteLine( "Point: x: " + point.x + ", y: " + point.y );
            //Console.WriteLine( "Axial: q: " + axial.q + ", r: " + axial.r );
            //Console.WriteLine( "Center: x: " + center.x + ", y: " + center.y );
            //Console.WriteLine( "Top Left: x: " + topLeft.x + ", y: " + topLeft.y );
            //Console.WriteLine( "From Top Left: x: " + fromTopLeft.x + ", y: " + fromTopLeft.y );
            //Console.WriteLine( "Slice: x: " + Slice.x + ", y: " + Slice.y );
            //Console.WriteLine( "Slice Index: x: " + hSlice + ", y: " + vSlice );
            //Console.WriteLine( "Within Slice: x: " + withinSlice.x + ", y: " + withinSlice.y );
            //Console.WriteLine( "Parity: " + parity );

            // Compute and return the triangle by which the point is contained.
            bool          isInvalid = false;
            DirectionEnum direction = DirectionEnum.E;
            TriangleEnum  triangle  = WhichTriangle(withinSlice, parity);


            if (hSlice == 0)
            {
                switch (vSlice)
                {
                case 0:
                    if (triangle == TriangleEnum.Bottom)
                    {
                        direction = DirectionEnum.NW;
                    }
                    else
                    {
                        isInvalid = true;
                    }
                    break;

                case 1:
                    direction = (triangle == TriangleEnum.Top) ? DirectionEnum.NW : DirectionEnum.W;
                    break;

                case 2:
                    direction = (triangle == TriangleEnum.Top) ? DirectionEnum.W  : DirectionEnum.SW;
                    break;

                case 3:
                    if (triangle == TriangleEnum.Top)
                    {
                        direction = DirectionEnum.SW;
                    }
                    else
                    {
                        isInvalid = true;
                    }
                    break;

                default:
                    isInvalid = true;
                    break;
                }
            }
            else             // hSlice == 1
            {
                switch (vSlice)
                {
                case 0:
                    if (triangle == TriangleEnum.Bottom)
                    {
                        direction = DirectionEnum.NE;
                    }
                    else
                    {
                        isInvalid = true;
                    }
                    break;

                case 1:
                    direction = (triangle == TriangleEnum.Top) ? DirectionEnum.NE : DirectionEnum.E;
                    break;

                case 2:
                    direction = (triangle == TriangleEnum.Top) ? DirectionEnum.E  : DirectionEnum.SE;
                    break;

                case 3:
                    if (triangle == TriangleEnum.Top)
                    {
                        direction = DirectionEnum.SE;
                    }
                    else
                    {
                        isInvalid = true;
                    }
                    break;

                default:
                    isInvalid = true;
                    break;
                }
            }

            //
            // Debugging output associated with a horrible bug in PointToCubic()
            //
            //Console.WriteLine( "Triangle: " + triangle );
            //Console.WriteLine( "Direction: " + direction );
            //Console.WriteLine( "" );
            //Console.WriteLine( "" );

            if (isInvalid)
            {
                throw new InvalidOperationException("This should never happen!");
            }
            else
            {
                return(direction);
            }
        }
Esempio n. 5
0
 public static Parity StringToParity(string AValue)
 {
     return(ParityEnum.Single(p => ParityToString(p) == AValue));
 }
 public ParityBet(int player, int money, ParityEnum parity) : base(player, money) => BetCell = parity;
Esempio n. 7
0
        /// <summary>
        /// Returns a TriangleEnum representing the triangle (within the current slice, either 
        /// top or bottom, that the point belongs to).
        /// </summary>
        /// <param name="withinSlice">A point on the x-z cartesian plane, relative to the top-left 
        /// of the current slice.</param>
        /// <param name="parity">The "parity" of the slice, indicating wither the border seaparting 
        /// the two triangles within the slice goes from top-left to bottom-right (ODD) or 
        /// bottom-left to top-right (EVEN).</param>
        /// <returns>A TriangleEnum representing the triangle (within the current slice, either 
        /// top or bottom, that the point belongs to).</returns>
        private TriangleEnum WhichTriangle( Vec2D withinSlice, ParityEnum parity )
        {
            float xFraction = withinSlice.x / Slice.x;
            float yBorder = 0f;

            if ( parity == ParityEnum.Even )
            {
                // When parity is even, the border is bottom-left to top-right.
                yBorder = Slice.y * xFraction;
            }
            else
            {
                // When parity is odd, the border is top-left to bottom-right.
                yBorder = Slice.y * ( 1f - xFraction );
            }

            return ( withinSlice.y < yBorder ) ? TriangleEnum.Top : TriangleEnum.Bottom;
        }