예제 #1
0
 private string GetValueText(Score score)
 {
     return(
         IsValueFullWidth ?
         IntConverter.Convert(NumberType.Big, score.Value) :
         score.Value.ToString());
 }
예제 #2
0
        public void IntConverterFromDecimalTooSmall()
        {
            var converter = new IntConverter();
            var result    = converter.Convert(decimal.MinValue);

            Assert.AreEqual(null, result);
        }
예제 #3
0
        /// <summary>
        /// 棋力を文字列化します。
        /// </summary>
        public static string ToString(SkillLevel skillLevel)
        {
            if (!string.IsNullOrEmpty(skillLevel.OriginalText))
            {
                var text = skillLevel.OriginalText;

                return(text.Length > 12 ?
                       text.Substring(0, 12) :
                       text);
            }

            var n = IntConverter.Convert(NumberType.Grade, skillLevel.Grade);

            switch (skillLevel.Kind)
            {
            case SkillKind.Kyu:
                return(n + "級");

            case SkillKind.Dan:
                return(n + "段");

            case SkillKind.Unknown:
                return("");
            }

            return("");
        }
예제 #4
0
        public void IntConverter(object input, int?expected)
        {
            var converter = new IntConverter();
            var result    = converter.Convert(input);

            Assert.AreEqual(expected, result);
        }
예제 #5
0
        public void IntConverterFromDecimal()
        {
            var converter = new IntConverter();
            var result    = converter.Convert(77.5m);

            Assert.AreEqual(78, result);
        }
        public SettingsWindow(ServiceBuilder serviceBuilder, HotKeysBuilder hotKeysBuilder)
        {
            InitializeComponent();

            serverPortConverter = new IntConverter();
            clientPortConverter = new IntNullableConverter()
            {
                AutoParseNullOrWhiteSpace = true,
                NullOrWhiteSpaceValue     = null
            };

            timMode.DataContext    = ServiceBuilder = serviceBuilder;
            timHotKeys.DataContext = HotKeysBuilder = hotKeysBuilder;

            if (serviceBuilder.BuildServer)
            {
                tbxPort.Text = serverPortConverter.Convert(serviceBuilder.ServerPort);
            }
            else if (serviceBuilder.BuildClient)
            {
                tbxPort.Text = clientPortConverter.Convert(serviceBuilder.ClientPort);
            }

            if (!serviceBuilder.IsSearchShuffle.HasValue)
            {
                cbxSearchShuffle.IsChecked = null;
            }
            if (!serviceBuilder.Play.HasValue)
            {
                cbxPlay.IsChecked = null;
            }
        }
        public SettingsWindow(ServiceBuilder serviceBuilder, HotKeysBuilder hotKeysBuilder)
        {
            InitializeComponent();

            serverPortConverter = new IntConverter();
            clientPortConverter = new IntNullableConverter()
            {
                AutoParseNullOrWhiteSpace = true,
                NullOrWhiteSpaceValue     = null
            };

            timMode.DataContext    = ServiceBuilder = serviceBuilder;
            timHotKeys.DataContext = HotKeysBuilder = hotKeysBuilder;

            if (serviceBuilder.BuildServer)
            {
                tbxPort.Text = serverPortConverter.Convert(serviceBuilder.ServerPort);
            }
            else if (serviceBuilder.BuildClient)
            {
                tbxPort.Text = clientPortConverter.Convert(serviceBuilder.ClientPort);
            }
            else
            {
                tbxPort.Text = "1884";
            }

            if (string.IsNullOrWhiteSpace(ServiceBuilder.ServerAddress))
            {
                ServiceBuilder.ServerAddress = "127.0.0.1";
            }
        }
예제 #8
0
        /// <summary>
        /// 駒の描画を行います。
        /// </summary>
        private void AddRenderPiece(RenderBuffer renderBuffer, BoardPiece piece,
                                    int count, PointF cpos, double zorder)
        {
            if (this.pieceTexture == null || !this.pieceTexture.IsAvailable)
            {
                return;
            }

            if (count <= 0)
            {
                return;
            }

            var s      = SquareSize;
            var bounds = new RectangleF(
                cpos.X - s.Width / 2, cpos.Y - s.Height / 2,
                s.Width, s.Height);

            // 駒自体の描画を行います。
            renderBuffer.AddRender(
                this.pieceTexture, BlendType.Diffuse,
                bounds, Transform, GetPieceMesh(piece), zorder);

            // 必要なら持ち駒の数も描画します。
            if (count >= 2)
            {
                var text = IntConverter.Convert(NumberType.Big, count);
                bounds = new RectangleF(
                    cpos.X - s.Width * 0.1f, cpos.Y - s.Height * 0.6f,
                    s.Width * 0.8f, s.Height * 0.5f);
                AddRenderText(
                    renderBuffer, text, this.pieceCountFont,
                    bounds, zorder + 0.05);
            }
        }
예제 #9
0
        /// <summary>
        /// 盤の描画を行います。
        /// </summary>
        private void AddRenderBoard(RenderBuffer renderBuffer)
        {
            // 盤
            renderBuffer.AddRender(
                this.boardTexture, BlendType.Diffuse,
                BoardBounds, Transform,
                ShogiZOrder.BoardZ, BoardOpacity);

            // 上部に描画する盤の符号の領域
            var totalBounds = RectangleF.FromLTRB(
                BoardSquareBounds.Left,
                BoardBounds.Top,
                BoardSquareBounds.Right,
                BoardSquareBounds.Top); // Topはミスではありません。
            var w = totalBounds.Width / Board.BoardSize;

            for (int n = 1; n <= Board.BoardSize; ++n)
            {
                // 符号を描画する領域
                var bounds = new RectangleF(
                    totalBounds.Left + w * (n - 1),
                    totalBounds.Top,
                    w,
                    totalBounds.Height);
                bounds.Inflate(0, -2.5f);
                var str = IntConverter.Convert(
                    NumberType.Big,
                    ViewSide == BWType.Black ? 10 - n : n);
                AddRenderText(
                    renderBuffer, str, this.boardSignFont,
                    bounds, ShogiZOrder.BoardZ);
            }

            // 右側に描画する盤の符号の領域
            totalBounds = RectangleF.FromLTRB(
                BoardSquareBounds.Right, // Rightはミスではありません。
                BoardSquareBounds.Top,
                BoardBounds.Right,
                BoardSquareBounds.Bottom);
            var h = totalBounds.Height / Board.BoardSize;

            for (int n = 1; n <= Board.BoardSize; ++n)
            {
                // 符号を描画する領域
                var bounds = new RectangleF(
                    totalBounds.Left,
                    totalBounds.Top + h * (n - 1),
                    totalBounds.Width,
                    w);
                bounds.Inflate(-1.5f, 0);
                var str = IntConverter.Convert(
                    NumberType.Kanji,
                    ViewSide == BWType.Black ? n : 10 - n);
                AddRenderText(
                    renderBuffer, str, this.boardSignFont,
                    bounds, ShogiZOrder.BoardZ);
            }
        }
예제 #10
0
        public void IntConverterTest()
        {
            Assert.That(IntConverter.Convert(233), Is.EqualTo("233"));
            Assert.That(IntConverter.Convert(-233), Is.EqualTo("-233"));
            Assert.That(IntConverter.Convert("444556"), Is.EqualTo(444556));

            Assert.Throws(typeof(FieldConvertError), delegate { IntConverter.Convert("+100"); });
            Assert.Throws(typeof(FieldConvertError), delegate { IntConverter.Convert("(100)"); });
            Assert.Throws(typeof(FieldConvertError), delegate { IntConverter.Convert("AB"); });
            Assert.Throws(typeof(FieldConvertError), delegate { IntConverter.Convert("2.3234"); });
            Assert.Throws(typeof(FieldConvertError), delegate { IntConverter.Convert(""); });
            Assert.Throws(typeof(FieldConvertError), delegate { IntConverter.Convert(null); });
        }
예제 #11
0
        public void IntConverter_CorrectConversionTest()
        {
            Array[] data = new int[][]
            {
                new int[] { int.MinValue, int.MaxValue },
                new int[] { -30000, 60000 },
            };

            var converter = new IntConverter();
            var sut       = converter.Convert(data, 2, 2);

            var expectation = new ushort[] { 0, ushort.MaxValue, 32767, 32768 };

            sut.Should().BeEquivalentTo(expectation);
        }
예제 #12
0
        /// <summary>
        /// 局面の各段をbod形式に直します。
        /// </summary>
        private static string RankToBod(Board board, int rank)
        {
            var sb = new StringBuilder();

            sb.Append("|");

            // 9筋が一番左で、1筋は右になります。
            for (var file = Board.BoardSize; file >= 1; --file)
            {
                sb.Append(KifUtil.PieceToStr(board[file, rank]));
            }

            sb.Append("|");
            sb.Append(IntConverter.Convert(NumberType.Kanji, rank));

            return(sb.ToString());
        }
        /// <summary>
        /// 整数値を全角数字の文字列に変換します。
        /// </summary>
        public object Convert(object value, Type targetType,
                              object parameter, CultureInfo culture)
        {
            try
            {
                var ivalue = (int)value;

                return(IntConverter.Convert(NumberType.Big, ivalue));
            }
            catch (InvalidCastException ex)
            {
                Log.ErrorException(ex,
                                   "IntToFullWidthString: 大文字に変換できませんでした。");

                return(null);
            }
        }
예제 #14
0
 /// <summary>
 /// Gets the integer value of a field
 /// </summary>
 /// <param name="tag">the FIX tag</param>
 /// <returns>the integer field value</returns>
 /// <exception cref="FieldNotFoundException" />
 public int GetInt(int tag)
 {
     try
     {
         Fields.IField fld = _fields[tag];
         if (fld.GetType() == typeof(IntField))
         {
             return(((IntField)fld).Obj);
         }
         else
         {
             return(IntConverter.Convert(fld.ToString()));
         }
     }
     catch (System.Collections.Generic.KeyNotFoundException)
     {
         throw new FieldNotFoundException(tag);
     }
 }
예제 #15
0
        /// <summary>
        /// 持ち駒を文字列に直します。
        /// </summary>
        private static string HandToBod(Board board, BWType turn)
        {
            var list =
                from pieceType in EnumEx.GetValues <PieceType>()
                let obj = new
            {
                Piece = new Piece(pieceType, false),
                Count = board.GetHand(pieceType, turn),
            }
            where obj.Count > 0
            select string.Format("{0}{1}{2} ",
                                 KifUtil.PieceToChar(obj.Piece),
                                 (obj.Count >= 10 ? "十" : ""),
                                 (obj.Count == 10 || obj.Count == 1 ? "" :
                                  IntConverter.Convert(NumberType.Kanji, obj.Count % 10)));

            var array = list.ToArray();

            return(array.Any() ? string.Join("", array) : "なし");
        }
예제 #16
0
 /// <summary>
 /// 指し手を文字列化します。
 /// </summary>
 public override string ToString()
 {
     if (SpecialMoveType != SpecialMoveType.None)
     {
         return(string.Format(
                    "{0}{1}",
                    Stringizer.ToString(BWType),
                    EnumEx.GetLabel(SpecialMoveType)));
     }
     else if (ActionType == ActionType.Drop)
     {
         return(string.Format(
                    "{0}{1}{2}{3}打",
                    Stringizer.ToString(BWType),
                    IntConverter.Convert(NumberType.Big, DstSquare.File),
                    IntConverter.Convert(NumberType.Kanji, DstSquare.Rank),
                    Stringizer.ToString(DropPieceType)));
     }
     else if (HasSameSquareAsPrev)
     {
         return(string.Format(
                    "{0}同 {1}{2}({3}{4})",
                    Stringizer.ToString(BWType),
                    MovePiece,
                    Stringizer.ToString(ActionType),
                    SrcSquare.File,
                    SrcSquare.Rank));
     }
     else
     {
         return(string.Format(
                    "{0}{1}{2}{3}{4}({5}{6})",
                    Stringizer.ToString(BWType),
                    IntConverter.Convert(NumberType.Big, DstSquare.File),
                    IntConverter.Convert(NumberType.Kanji, DstSquare.Rank),
                    MovePiece,
                    Stringizer.ToString(ActionType),
                    SrcSquare.File,
                    SrcSquare.Rank));
     }
 }
        public void IntConverter_Convert()
        {
            IValueConverter converter;
            object actualValue;
            Type expectedType;

            converter = new IntConverter();
            expectedType = typeof(string);

            //
            // Test with null.
            //

            try
            {
                converter.Convert(null);
                Assert.Fail("Expected ArgumentNullException to be thrown.");
            }
            catch (ArgumentNullException)
            {
            }

            //
            // Test with incorrect type.
            //

            try
            {
                converter.Convert("true");
                Assert.Fail("Expected ArgumentException to be thrown.");
            }
            catch (ArgumentException)
            {
            }

            //
            // Test with 0.
            //

            actualValue = converter.Convert(0);
            Assert.IsNotNull(actualValue, "Converted value is null.");
            Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect.");
            Assert.AreEqual("0", actualValue, "Converted value is incorrect.");

            //
            // Test with negative value.
            //

            actualValue = converter.Convert(-1);
            Assert.IsNotNull(actualValue, "Converted value is null.");
            Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect.");
            Assert.AreEqual("-1", actualValue, "Converted value is incorrect.");

            //
            // Test with positive value.
            //

            actualValue = converter.Convert(1024);
            Assert.IsNotNull(actualValue, "Converted value is null.");
            Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect.");
            Assert.AreEqual("1024", actualValue, "Converted value is incorrect.");
        }
예제 #18
0
 public static int Convert(string i)
 {
     return(IntConverter.Convert(i));
 }
예제 #19
0
        /// <summary>
        /// 指し手を文字列に変換します。
        /// </summary>
        /// <remarks>
        /// KifFileに使う指し手は同○○の場合、
        /// 「同」と「○○」の間に空白を入れないと"kif for windows"では
        /// 正しく読み込めなくなります。
        /// </remarks>
        public static string ToString(Move move,
                                      MoveTextStyle style = MoveTextStyle.Normal)
        {
            if (move == null)
            {
                return(null);
            }

            if (move.IsSpecialMove)
            {
                var turnStr = string.Empty;

                // 必要なら▲△を先頭に入れます。
                if (style == MoveTextStyle.Normal)
                {
                    turnStr = ToString(move.BWType);
                }

                return(turnStr + EnumEx.GetLabel(move.SpecialMoveType));
            }

            var result = new StringBuilder();

            result.Append(ToString(move.Piece));
            result.Append(ToString(move.RelFileType));
            result.Append(ToString(move.RankMoveType));
            result.Append(ToString(move.ActionType));

            if (move.SameAsOld)
            {
                var hasSpace = (
                    (style != MoveTextStyle.Simple) &&
                    (result.Length == 1 || style == MoveTextStyle.KifFile));

                // 文字数によって、同の後の空白を入れるか決めます。
                result.Insert(0, (hasSpace ? "同 " : "同"));
            }
            else
            {
                if (style == MoveTextStyle.Simple)
                {
                    result.Insert(0,
                                  IntConverter.Convert(NumberType.Normal, move.File));
                    result.Insert(1,
                                  IntConverter.Convert(NumberType.Normal, move.Rank));
                }
                else
                {
                    result.Insert(0,
                                  IntConverter.Convert(NumberType.Big, move.File));
                    result.Insert(1,
                                  IntConverter.Convert(NumberType.Kanji, move.Rank));
                }
            }

            // 必要なら▲△を先頭に入れます。
            if (style == MoveTextStyle.Normal)
            {
                result.Insert(0, ToString(move.BWType));
            }

            if (move.SrcSquare != null && style == MoveTextStyle.KifFile)
            {
                result.AppendFormat("({0}{1})",
                                    move.SrcSquare.File,
                                    move.SrcSquare.Rank);
            }

            return(result.ToString());
        }
예제 #20
0
        public void IntConverter_Convert()
        {
            IValueConverter converter;
            object          actualValue;
            Type            expectedType;

            converter    = new IntConverter();
            expectedType = typeof(string);

            //
            // Test with null.
            //

            try
            {
                converter.Convert(null);
                Assert.Fail("Expected ArgumentNullException to be thrown.");
            }
            catch (ArgumentNullException)
            {
            }

            //
            // Test with incorrect type.
            //

            try
            {
                converter.Convert("true");
                Assert.Fail("Expected ArgumentException to be thrown.");
            }
            catch (ArgumentException)
            {
            }

            //
            // Test with 0.
            //

            actualValue = converter.Convert(0);
            Assert.IsNotNull(actualValue, "Converted value is null.");
            Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect.");
            Assert.AreEqual("0", actualValue, "Converted value is incorrect.");

            //
            // Test with negative value.
            //

            actualValue = converter.Convert(-1);
            Assert.IsNotNull(actualValue, "Converted value is null.");
            Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect.");
            Assert.AreEqual("-1", actualValue, "Converted value is incorrect.");

            //
            // Test with positive value.
            //

            actualValue = converter.Convert(1024);
            Assert.IsNotNull(actualValue, "Converted value is null.");
            Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect.");
            Assert.AreEqual("1024", actualValue, "Converted value is incorrect.");
        }