Exemple #1
0
        /// <summary>
        /// 局面の出力
        /// </summary>
        /// <param name="position"></param>
        /// <param name="sr"></param>
        private static void WritePosition(SPosition position, TextWriter wr, int movenumber)
        {
            int sq    = 0;
            int space = 0;

            // 盤面出力

            for (int rank = 0; rank < Square.NRANK; rank++)
            {
                // 段の切り替わりで/を出力
                if (rank != 0)
                {
                    wr.Write('/');
                }

                for (int file = 0; file < Square.NFILE; file++, sq++)
                {
                    Piece piece = position.GetPiece(sq);
                    char  ch;

                    if (piece == Piece.NoPiece)
                    {
                        space++;
                    }
                    else
                    {
                        if (space != 0)
                        {
                            wr.Write(space);
                            space = 0;
                        }

                        if (piece.IsPromoted())
                        {
                            // 成り
                            wr.Write('+');
                        }

                        ch = CharFromPieceType(piece.TypeOf());

                        if (piece.HasFlag(Piece.WhiteFlag))
                        {
                            ch = char.ToLower(ch);
                        }

                        wr.Write(ch);
                    }
                }

                if (space != 0)
                {
                    wr.Write(space);
                    space = 0;
                }
            }

            // 手番の出力
            if (position.Turn == PlayerColor.White)
            {
                wr.Write(" w ");
            }
            else
            {
                wr.Write(" b ");
            }

            // 持ち駒の出力
            int hand_cnt = 0;

            for (PieceType pt = PieceType.HI; pt > PieceType.NoPieceType; pt--)
            {
                int num = position.GetBlackHand(pt);
                if (num != 0)
                {
                    if (num > 1)
                    {
                        wr.Write(num);
                    }

                    wr.Write(CharFromPieceType(pt));

                    hand_cnt++;
                }
            }

            for (PieceType pt = PieceType.HI; pt > PieceType.NoPieceType; pt--)
            {
                int num = position.GetWhiteHand(pt);
                if (num != 0)
                {
                    if (num > 1)
                    {
                        wr.Write(num);
                    }

                    char ch = CharFromPieceType(pt);
                    ch = char.ToLower(ch); // 後手は小文字
                    wr.Write(ch);

                    hand_cnt++;
                }
            }

            if (hand_cnt == 0)
            {
                wr.Write("-");
            }

            if (movenumber != 0)
            {
                wr.Write(" {0}", movenumber); // 手数 実際には次が何手目か
            }
        }
Exemple #2
0
        /// <summary>
        /// 局面の出力
        /// </summary>
        /// <param name="position"></param>
        /// <param name="sr"></param>
        private static void WritePosition(SPosition position, TextWriter wr, int movenumber)
        {
            int sq = 0;
            int space = 0;

            // 盤面出力

            for (int rank = 0; rank < Square.NRANK; rank++)
            {
                // 段の切り替わりで/を出力
                if (rank != 0)
                {
                    wr.Write('/');
                }

                for (int file = 0; file < Square.NFILE; file++, sq++)
                {
                    Piece piece = position.GetPiece(sq);
                    char ch;

                    if (piece == Piece.NoPiece)
                    {
                        space++;
                    }
                    else
                    {
                        if (space != 0)
                        {
                            wr.Write(space);
                            space = 0;
                        }

                        if (piece.IsPromoted())
                        {
                            // 成り
                            wr.Write('+');
                        }

                        ch = CharFromPieceType(piece.TypeOf());

                        if (piece.HasFlag(Piece.WhiteFlag))
                        {
                            ch = char.ToLower(ch);
                        }

                        wr.Write(ch);
                    }
                }

                if (space != 0)
                {
                    wr.Write(space);
                    space = 0;
                }
            }

            // 手番の出力
            if (position.Turn == PlayerColor.White)
            {
                wr.Write(" w ");
            }
            else
            {
                wr.Write(" b ");
            }

            // 持ち駒の出力
            int hand_cnt = 0;
            for (PieceType pt = PieceType.HI; pt > PieceType.NoPieceType; pt--)
            {
                int num = position.GetBlackHand(pt);
                if (num != 0)
                {
                    if (num > 1)
                    {
                        wr.Write(num);
                    }

                    wr.Write(CharFromPieceType(pt));

                    hand_cnt++;
                }
            }

            for (PieceType pt = PieceType.HI; pt > PieceType.NoPieceType; pt--)
            {
                int num = position.GetWhiteHand(pt);
                if (num != 0)
                {
                    if (num > 1)
                    {
                        wr.Write(num);
                    }

                    char ch = CharFromPieceType(pt);
                    ch = char.ToLower(ch); // 後手は小文字
                    wr.Write(ch);

                    hand_cnt++;
                }
            }

            if (hand_cnt == 0)
            {
                wr.Write("-");
            }

            if (movenumber != 0)
            {
                wr.Write(" {0}", movenumber); // 手数 実際には次が何手目か
            }
        }