Ejemplo n.º 1
0
        /// <summary>
        /// 局面を描きます。
        /// </summary>
        public static void Paint(Graphics g, KyokumenPngArgs args)
        {
            //----------------------------------------
            // 8×8 の将棋盤
            //----------------------------------------
            int bOx = args.Env.KmW + 2 * args.Env.SjW; // 将棋盤の左辺
            int bOy = 0;

            //----------------------------------------
            // 移動元の升を灰色に塗る
            //----------------------------------------
            if (0 <= args.SrcMasu_orMinusOne && args.SrcMasu_orMinusOne <= 80)
            {
                g.FillRectangle(Brushes.LightGray, Util_KyokumenPngPainter.GetBanjoRectangle(args.SrcMasu_orMinusOne, bOx, bOy, args));
            }

            //----------------------------------------
            // 駒台の駒を打った場合
            //----------------------------------------
            if (args.DropKoma != KyokumenPngArgs_FoodOrDropKoma.UNKNOWN && args.DropKoma != KyokumenPngArgs_FoodOrDropKoma.NONE)
            {
                Rectangle rect = Util_KyokumenPngPainter.GetMotiRectangle(args.DropKoma, args);
                // 駒台に塗りつぶし矩形、灰色
                g.FillRectangle(Brushes.LightGray, rect);
            }

            //----------------------------------------
            // 動かした先の升を黒く塗る
            //----------------------------------------
            if (0 <= args.DstMasu_orMinusOne && args.DstMasu_orMinusOne <= 80)
            {
                // 盤上に塗りつぶし矩形
                g.FillRectangle(Brushes.Black, Util_KyokumenPngPainter.GetBanjoRectangle(args.DstMasu_orMinusOne, bOx, bOy, args));
            }

            //----------------------------------------
            // 取った駒の駒台の背景を黒く塗る
            //----------------------------------------
            if (args.FoodKoma != KyokumenPngArgs_FoodOrDropKoma.UNKNOWN && args.FoodKoma != KyokumenPngArgs_FoodOrDropKoma.NONE)
            {
                g.FillRectangle(Brushes.Black, Util_KyokumenPngPainter.GetMotiRectangle(args.FoodKoma, args));
            }


            //----------------------------------------
            // 図形
            //----------------------------------------

            {
                // 縦線
                for (int col = 0; col < 10; col++)
                {
                    g.DrawLine(Pens.Black, col * args.Env.KmW + bOx, 0 + bOy, col * args.Env.KmW + bOx, 180 + bOy);
                }

                // 横線
                for (int row = 0; row < 10; row++)
                {
                    g.DrawLine(Pens.Black, 0 + bOx, row * args.Env.KmH + bOy, 180 + bOx, row * args.Env.KmH + bOy);
                }
            }

            // 盤上の駒
            {
                for (int suji = 1; suji < 10; suji++)
                {
                    for (int dan = 1; dan < 10; dan++)
                    {
                        string sign = args.Ro_Kyokumen1.Ban[suji, dan];
                        if ("" != sign)
                        {
                            Point pt = Util_KyokumenPngPainter.CropXyBySign(sign, args);
                            g.DrawImage(Image.FromFile(args.Env.ImgFolder + args.Env.KmFile),
                                        new Rectangle((9 - suji) * args.Env.KmW + bOx, (dan - 1) * args.Env.KmH + bOy, args.Env.KmW, args.Env.KmH), //dst
                                        new Rectangle(pt.X, pt.Y, args.Env.KmW, args.Env.KmH),                                                      //src
                                        GraphicsUnit.Pixel
                                        );
                        }
                    }
                }
            }

            // 後手の持駒 (飛,角,金,銀,桂,香,歩)
            {
                string[] signs = new string[] { "r", "b", "g", "s", "n", "l", "p" };
                int      ox    = 0;
                int      oy    = 0;
                for (int moti = 0; moti < 7; moti++)
                {
                    Point pt = Util_KyokumenPngPainter.CropXyBySign(signs[moti], args);
                    // 枚数
                    int player = 2;
                    int maisu  = args.Ro_Kyokumen1.Moti[player, moti];
                    if (0 < maisu)
                    {
                        //駒
                        g.DrawImage(
                            Image.FromFile(args.Env.ImgFolder + args.Env.KmFile),
                            new Rectangle(ox, (signs.Length - moti - 1) * args.Env.KmH + oy, args.Env.KmW, args.Env.KmH), //dst
                            new Rectangle(pt.X, pt.Y, args.Env.KmW, args.Env.KmH),                                        //src
                            GraphicsUnit.Pixel
                            );

                        // 1桁目が先
                        {
                            int ichi = maisu % 10;
                            g.DrawImage(Image.FromFile(args.Env.ImgFolder + args.Env.SjFile),
                                        new Rectangle(ox + args.Env.KmW, (signs.Length - moti - 1) * args.Env.KmH + (args.Env.KmH - args.Env.SjH) + oy, args.Env.SjW, args.Env.SjH), //dst
                                        new Rectangle(ichi * args.Env.SjW, args.Env.SjH, args.Env.SjW, args.Env.SjH),                                                                //src
                                        GraphicsUnit.Pixel
                                        );                                                                                                                                           // 一の位
                        }

                        // 2桁目が後
                        {
                            int ju = maisu / 10;
                            if (ju < 1)
                            {
                                ju = -1;//空桁
                            }
                            g.DrawImage(
                                Image.FromFile(args.Env.ImgFolder + args.Env.SjFile),
                                new Rectangle(ox + args.Env.KmW + args.Env.SjW, (signs.Length - moti - 1) * args.Env.KmH + (args.Env.KmH - args.Env.SjH) + oy, args.Env.SjW, args.Env.SjH), //dst
                                new Rectangle(ju * args.Env.SjW, 0, args.Env.SjW, args.Env.SjH),                                                                                            //src
                                GraphicsUnit.Pixel
                                );                                                                                                                                                          // 十の位
                        }
                    }
                }
            }

            // 先手の持駒 (飛,角,金,銀,桂,香,歩)
            {
                string[] signs = new string[] { "R", "B", "G", "S", "N", "L", "P" };
                int      ox    = (args.Env.KmW + 2 * args.Env.SjW) + 9 * args.Env.KmW + BN_BRD_R_W;
                int      oy    = (9 * args.Env.KmW + BN_BRD_B_W) - 7 * args.Env.KmH;
                for (int moti = 0; moti < 7; moti++)
                {
                    Point pt = Util_KyokumenPngPainter.CropXyBySign(signs[moti], args);

                    // 枚数
                    int player = 1;
                    int maisu  = args.Ro_Kyokumen1.Moti[player, moti];
                    if (0 < maisu)
                    {
                        g.DrawImage(Image.FromFile(args.Env.ImgFolder + args.Env.KmFile),
                                    new Rectangle(ox, moti * args.Env.KmH + oy, args.Env.KmW, args.Env.KmH), //dst
                                    new Rectangle(pt.X, pt.Y, args.Env.KmW, args.Env.KmH),                   //src
                                    GraphicsUnit.Pixel
                                    );                                                                       //駒

                        // 十の位が先
                        {
                            int ju = maisu / 10;
                            if (ju < 1)
                            {
                                ju = -1;//空桁
                            }
                            g.DrawImage(Image.FromFile(args.Env.ImgFolder + args.Env.SjFile),
                                        new Rectangle(ox + args.Env.KmW, moti * args.Env.KmH + (args.Env.KmH - args.Env.SjH) + oy, args.Env.SjW, args.Env.SjH), //dst
                                        new Rectangle(ju * args.Env.SjW, 0, args.Env.SjW, args.Env.SjH),                                                        //src
                                        GraphicsUnit.Pixel
                                        );                                                                                                                      // 十の位
                        }

                        // 一の位が後
                        {
                            int ichi = maisu % 10;
                            g.DrawImage(Image.FromFile(args.Env.ImgFolder + args.Env.SjFile),
                                        new Rectangle(ox + args.Env.KmW + args.Env.SjW, moti * args.Env.KmH + (args.Env.KmH - args.Env.SjH) + oy, args.Env.SjW, args.Env.SjH), //dst
                                        new Rectangle(ichi * args.Env.SjW, 0, args.Env.SjW, args.Env.SjH),                                                                     //src
                                        GraphicsUnit.Pixel
                                        );                                                                                                                                     // 一の位
                        }
                    }
                }
            }

            // 手目済み
            float x;

            if (99 < args.Ro_Kyokumen1.Temezumi)// 3桁以上のとき
            {
                x = 0.0f;
            }
            else if (9 < args.Ro_Kyokumen1.Temezumi)// 2桁のとき
            {
                x = 9.0f;
            }
            else// 1桁のとき
            {
                x = 18.0f;
            }
            g.DrawString(args.Ro_Kyokumen1.Temezumi.ToString(), Util_KyokumenPngPainter.Font, Brushes.White, new PointF(x, 150.0f));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 局面データと、出力ファイル名を指定することで、局面の画像ログを出力します。
        /// </summary>
        /// <param name="ro_Kyokumen1"></param>
        /// <param name="dstMasu_orMinusOne">あれば、移動先升番号。なければ -1。</param>
        /// <param name="appendFilepath"></param>
        /// <param name="outFile"></param>
        /// <param name="reportEnvironment"></param>
        /// <returns></returns>
        public static bool Write1(
            ISfenPosition1 ro_Kyokumen1,
            int srcMasu_orMinusOne,
            int dstMasu_orMinusOne,
            KyokumenPngArgs_FoodOrDropKoma foodKoma,
            string sfenMoveStrOrEmpty,
            string appendFilepath,
            string outFile,
            KyokumenPngEnvironment reportEnvironment
            )
        {
            bool successful = true;


            //----------------------------------------
            // 打った駒を調べる
            //----------------------------------------
            KyokumenPngArgs_FoodOrDropKoma dropKoma;

            {
                dropKoma = KyokumenPngArgs_FoodOrDropKoma.UNKNOWN;
                if ("" != sfenMoveStrOrEmpty)
                {
                    string moji1;
                    string moji2;
                    string moji3;
                    string moji4;
                    string moji5;
                    string rest;
                    SfenMovesTextConv.ToTokens(
                        sfenMoveStrOrEmpty,
                        out moji1,
                        out moji2,
                        out moji3,
                        out moji4,
                        out moji5,
                        out rest
                        );

                    if (moji2 == "*")
                    {
                        switch (moji1)
                        {
                        case SfenWord.P_PAWN__: dropKoma = KyokumenPngArgs_FoodOrDropKoma.FU__; break;

                        case SfenWord.L_LANCE_: dropKoma = KyokumenPngArgs_FoodOrDropKoma.KYO_; break;

                        case SfenWord.N_KNIGHT: dropKoma = KyokumenPngArgs_FoodOrDropKoma.KEI_; break;

                        case SfenWord.S_SILVER: dropKoma = KyokumenPngArgs_FoodOrDropKoma.GIN_; break;

                        case SfenWord.G_GOLD__: dropKoma = KyokumenPngArgs_FoodOrDropKoma.KIN_; break;

                        case SfenWord.B_BISHOP: dropKoma = KyokumenPngArgs_FoodOrDropKoma.KAKU; break;

                        case SfenWord.R_ROOK__: dropKoma = KyokumenPngArgs_FoodOrDropKoma.HI__; break;

                        default: break;
                        }
                    }
                    else
                    {
                        dropKoma = KyokumenPngArgs_FoodOrDropKoma.NONE;
                    }
                }
            }


            //----------------------------------------
            // ファイルに使える文字に変換
            //----------------------------------------
            appendFilepath = appendFilepath.Replace('*', '*');
            outFile        = outFile.Replace('*', '*');

            KyokumenPngArgs args = new KyokumenPngArgsImpl(
                ro_Kyokumen1,
                srcMasu_orMinusOne,
                dstMasu_orMinusOne,
                foodKoma,
                dropKoma,
                outFile,
                reportEnvironment
                );

            // 局面画像を描きだします。
            Bitmap bmp = new Bitmap(
                2 * (args.Env.KmW + 2 * args.Env.SjW) + Util_KyokumenPngPainter.BN_SUJIS * args.Env.KmW + Util_KyokumenPngPainter.BN_BRD_R_W,
                Util_KyokumenPngPainter.BN_DANS * args.Env.KmH + Util_KyokumenPngPainter.BN_BRD_B_W
                );


            Util_KyokumenPngPainter.Paint(Graphics.FromImage(bmp), args);


            //args.Env.OutFolder + args.OutFile, "bmp.Save"
            string filepath = args.Env.OutFolder + appendFilepath + args.OutFile;

            // フォルダーが無ければ、作る必要があります。
            {
                DirectoryInfo dirInfo = Directory.GetParent(filepath);
                if (!Directory.Exists(dirInfo.FullName))
                {
                    Directory.CreateDirectory(dirInfo.FullName);
                }
            }

            bmp.Save(filepath);

            return(successful);
        }