Example #1
0
        public static void BunkaiMoveUmv()
        {
            PureMemory.umv_ss = PureMemory.kifu_moveArray[PureMemory.kifu_endTeme];

            // 駒がないところを指していることがないか?
            PureMemory.umv_ms_t1 = AbstractConvMove.GetDstMasu_WithoutErrorCheck((int)PureMemory.umv_ss);
            PureMemory.umv_km_t1 = PureMemory.gky_ky.yomiKy.yomiShogiban.yomiIbashoBan.GetBanjoKoma(PureMemory.umv_ms_t1);
            PureMemory.umv_ks_t1 = Med_Koma.KomaToKomasyurui(PureMemory.umv_km_t1);// 成っているかもしれない☆
            Debug.Assert(Conv_Masu.IsBanjoOrError(PureMemory.umv_ms_t1), "error Undo-Begin-6");
            Debug.Assert(Conv_Koma.IsOk(PureMemory.umv_km_t1), "error Undo-Begin-7");


            if (!AbstractConvMove.IsUtta(PureMemory.umv_ss))                                                  // 指す
            {
                PureMemory.umv_ms_t0 = AbstractConvMove.GetSrcMasu_WithoutErrorCheck((int)PureMemory.umv_ss); // 戻し先。
                Debug.Assert(Conv_Masu.IsBanjo(PureMemory.umv_ms_t0), "error Undo-Begin-21 #金魚 戻し先が盤上でない?");

                PureMemory.umv_mk_t0 = Motigoma.Yososu;
                if (AbstractConvMove.IsNatta(PureMemory.umv_ss))                               // 成っていたとき
                {
                    PureMemory.umv_ks_t0 = Conv_Komasyurui.ToNarazuCase(PureMemory.umv_ks_t1); // 成る前
                }
                else
                {
                    PureMemory.umv_ks_t0 = PureMemory.umv_ks_t1;// 成る前、あるいは、成っていない、あるいは もともと にわとり☆
                }
                PureMemory.umv_km_t0 = Med_Koma.KomasyuruiAndTaikyokusyaToKoma(PureMemory.umv_ks_t0, PureMemory.kifu_teban);
                Debug.Assert(Conv_Koma.IsOk(PureMemory.umv_km_t0), "error Undo-Begin-9 #羊");
                Debug.Assert(Conv_Masu.IsBanjoOrError(PureMemory.umv_ms_t0), "error Undo-Begin-8 #颪");
            }
            else// 打つ
            {
                PureMemory.umv_ms_t0 = Conv_Masu.masu_error;
                PureMemory.umv_km_t0 = Piece.Yososu;
                PureMemory.umv_ks_t0 = Komasyurui.Yososu;
                PureMemory.umv_mk_t0 = Med_Koma.KomasyuruiAndTaikyokusyaToMotiKoma(PureMemory.umv_ks_t1, PureMemory.kifu_teban);
            }


            PureMemory.umv_ks_c = PureMemory.kifu_toraretaKsAr[PureMemory.kifu_endTeme];

            if (Komasyurui.Yososu != PureMemory.umv_ks_c)
            {
                PureMemory.umv_km_c = Med_Koma.KomasyuruiAndTaikyokusyaToKoma(PureMemory.umv_ks_c, PureMemory.kifu_aiteban);
                PureMemory.umv_mk_c = Med_Koma.BanjoKomaToMotiKoma(PureMemory.umv_km_c);
                Debug.Assert(Conv_Koma.IsOk(PureMemory.umv_km_c), "error Undo-Begin-10 #竜巻");
            }
            else
            {
                PureMemory.umv_km_c = Piece.Yososu;
                PureMemory.umv_mk_c = Motigoma.Yososu;
            }
        }
Example #2
0
        /// <summary>
        /// 将棋盤の駒を適当に動かすぜ☆(^▽^)www
        /// 主にテスト用だぜ☆(^▽^)
        /// </summary>
        public static bool TryFail_Mazeru(FenSyurui f
#if DEBUG
                                          , IDebugMojiretu reigai1
#endif
                                          )
        {
            int            r;                  //ランダム値☆
            Piece          tmpKm;
            MotigomaItiran motiKomaItiranImpl; //使わない

            // 盤がでかくなると時間がかかる☆(^~^)最大 1万回で☆(^~^)
            int nokori = 10000;

            // 50回もやれば混ざるだろ☆(^▽^)
            for (int i = 0; i < 50; i++)
            {
                int        kakuritu = PureSettei.banHeimen + Conv_Motigoma.itiran.Length;//適当☆(^~^)
                Komasyurui tmpKs;

                // 盤上にある駒を、別の空き升、あるいは持ち駒に移動するぜ☆(^▽^)
                for (int iMs1 = 0; iMs1 < PureSettei.banHeimen; iMs1++)
                {
                    for (int iMs2 = 0; iMs2 < PureSettei.banHeimen; iMs2++)
                    {
                        r = PureSettei.random.Next(kakuritu);
                        if (3 == r || 4 == r || 5 == r || 6 == r)// 確率
                        {
                            // 位置交換成立☆(^~^)空白同士の交換とか意味ないこともするぜ☆(^▽^)
                            tmpKm = PureMemory.gky_ky.yomiKy.yomiShogiban.yomiIbashoBan.GetBanjoKoma((Masu)iMs1);
                            if (3 == r || 5 == r)
                            {
                                if (PureMemory.gky_ky.shogiban.TryFail_OkuKoma(//混ぜる
                                        (Masu)iMs1, Conv_Koma.Hanten(PureMemory.gky_ky.yomiKy.yomiShogiban.yomiIbashoBan.GetBanjoKoma((Masu)iMs2)),
                                        true
#if DEBUG
                                        , reigai1
#endif
                                        ))
                                {
                                    return(Pure.FailTrue("TryFail_Oku"));
                                }
                            }
                            else
                            {
                                if (PureMemory.gky_ky.shogiban.TryFail_OkuKoma(//混ぜる
                                        (Masu)iMs1, PureMemory.gky_ky.yomiKy.yomiShogiban.yomiIbashoBan.GetBanjoKoma((Masu)iMs2),
                                        true
#if DEBUG
                                        , reigai1
#endif
                                        ))
                                {
                                    return(Pure.FailTrue("Try_Oku"));
                                }
                            }

                            if (4 == r || 5 == r)
                            {
                                if (PureMemory.gky_ky.shogiban.TryFail_OkuKoma(//混ぜる
                                        (Masu)iMs2, Conv_Koma.Hanten(tmpKm), true
#if DEBUG
                                        , reigai1
#endif
                                        ))
                                {
                                    return(Pure.FailTrue("Try_Oku"));
                                }
                            }
                            else
                            {
                                if (PureMemory.gky_ky.shogiban.TryFail_OkuKoma(//混ぜる
                                        (Masu)iMs2, tmpKm, true
#if DEBUG
                                        , reigai1
#endif
                                        ))
                                {
                                    return(Pure.FailTrue("Try_Oku"));
                                }
                            }

                            nokori--;
                        }
                        else if ((1 == r || 2 == r) && PureMemory.gky_ky.shogiban.ibashoBan_yk00.yomiIbashoBan.ExistsKomaZenbu((Masu)iMs1))
                        {
                            // 持駒交換成立☆(^▽^)
                            Piece km_tmp = PureMemory.gky_ky.yomiKy.yomiShogiban.yomiIbashoBan.GetBanjoKoma((Masu)iMs1);
                            tmpKs = Med_Koma.KomaToKomasyurui(km_tmp);

                            //Taikyokusya tai_tmp = Med_Koma.KomaToTaikyokusya(km_tmp);

                            // どちらの持駒にするかはランダムで☆(^~^)
                            Motigoma mk = Med_Koma.KomasyuruiAndTaikyokusyaToMotiKoma(tmpKs, 1 == r ? Taikyokusya.T1 : Taikyokusya.T2);

                            switch (tmpKs)
                            {
                            case Komasyurui.Z:
                            {
                                PureMemory.gky_ky.motigomaItiran.Fuyasu(mk);
                                Piece km_remove = PureMemory.gky_ky.yomiKy.yomiShogiban.yomiIbashoBan.GetBanjoKoma((Masu)iMs1);
                                Debug.Assert(Conv_Koma.IsOk(km_remove), "km_remove can not remove");
                                if (PureMemory.gky_ky.shogiban.TryFail_TorinozokuKoma(
                                        (Masu)iMs1,
                                        km_remove, Conv_Masu.masu_error, true
#if DEBUG
                                        , reigai1
#endif
                                        ))
                                {
                                    return(Pure.FailTrue("TryFail_Torinozoku(4)"));
                                }
                            }
                            break;

                            case Komasyurui.K:
                            {
                                PureMemory.gky_ky.motigomaItiran.Fuyasu(mk);
                                Piece km_remove = PureMemory.gky_ky.yomiKy.yomiShogiban.yomiIbashoBan.GetBanjoKoma((Masu)iMs1);
                                Debug.Assert(Conv_Koma.IsOk(km_remove), "km_remove can not remove");
                                if (PureMemory.gky_ky.shogiban.TryFail_TorinozokuKoma(
                                        (Masu)iMs1,
                                        km_remove,
                                        Conv_Masu.masu_error, true
#if DEBUG
                                        , reigai1
#endif
                                        ))
                                {
                                    return(Pure.FailTrue("TryFail_Torinozoku(5)"));
                                }
                            }
                            break;

                            case Komasyurui.PH:    //thru
                            case Komasyurui.H:
                            {
                                PureMemory.gky_ky.motigomaItiran.Fuyasu(mk);
                                Piece km_remove = PureMemory.gky_ky.yomiKy.yomiShogiban.yomiIbashoBan.GetBanjoKoma((Masu)iMs1);
                                Debug.Assert(Conv_Koma.IsOk(km_remove), "km_remove can not remove");
                                if (PureMemory.gky_ky.shogiban.TryFail_TorinozokuKoma(
                                        (Masu)iMs1,
                                        km_remove,
                                        Conv_Masu.masu_error, true
#if DEBUG
                                        , reigai1
#endif
                                        ))
                                {
                                    return(Pure.FailTrue("TryFail_Torinozoku(6)"));
                                }
                            }
                            break;
                            }

                            nokori--;
                        }
                    }

                    // ひんぱんに、ひよこ/にわとりの入れ替えだぜ☆(^▽^)www
                    {
                        Piece km;
                        r = PureSettei.random.Next(kakuritu);
                        if (r % 5 < 2)
                        {
                            if (PureMemory.gky_ky.shogiban.ibashoBan_yk00.yomiIbashoBan.ExistsKoma(Piece.P1, (Masu)iMs1) || PureMemory.gky_ky.shogiban.ibashoBan_yk00.yomiIbashoBan.ExistsKoma(Piece.P2, (Masu)iMs1))
                            {
                                if (0 == r)
                                {
                                    km = Piece.PP1;
                                }
                                else
                                {
                                    km = Piece.PP2;
                                }
                            }
                            else if (PureMemory.gky_ky.shogiban.yomiIbashoBan_yoko.IsOn(Piece.PP1, (Masu)iMs1) || PureMemory.gky_ky.shogiban.yomiIbashoBan_yoko.IsOn(Piece.PP2, (Masu)iMs1))
                            {
                                if (0 == r)
                                {
                                    km = Piece.P1;
                                }
                                else
                                {
                                    km = Piece.P2;
                                }
                            }
                            else
                            {
                                km = Piece.Yososu;
                            }

                            if (km != Piece.Yososu)
                            {
                                if (PureMemory.gky_ky.shogiban.TryFail_OkuKoma(// 混ぜる
                                        (Masu)iMs1, km, true
#if DEBUG
                                        , reigai1
#endif
                                        ))
                                {
                                    return(Pure.FailTrue("TryFail_Oku"));
                                }
                            }
                        }
                    }

                    for (int iMk2 = 0; iMk2 < Conv_Motigoma.itiran.Length; iMk2++)
                    {
                        Piece km = Piece.Yososu;
                        r = PureSettei.random.Next(kakuritu);
                        if ((1 == r || 2 == r) && PureMemory.gky_ky.shogiban.ibashoBan_yk00.yomiIbashoBan.ExistsKomaZenbu((Masu)iMs1) &&
                            PureMemory.gky_ky.motigomaItiran.yomiMotigomaItiran.HasMotigoma((Motigoma)iMk2))
                        {
                            // 持駒交換成立☆(^▽^)
                            switch ((Motigoma)iMk2)
                            {
                            case Motigoma.Z:

                                if (!PureMemory.gky_ky.motigomaItiran.Try_Herasu(out motiKomaItiranImpl, Motigoma.Z
#if DEBUG
                                                                                 , reigai1
#endif
                                                                                 ))
                                {
                                    return(Pure.FailTrue("Try_Herasu"));
                                }

                                if (1 == r)
                                {
                                    km = Piece.B1;
                                }
                                else
                                {
                                    km = Piece.B2;
                                }
                                break;

                            case Motigoma.K:

                                if (!PureMemory.gky_ky.motigomaItiran.Try_Herasu(out motiKomaItiranImpl, Motigoma.K
#if DEBUG
                                                                                 , reigai1
#endif
                                                                                 ))
                                {
                                    return(Pure.FailTrue("Try_Herasu"));
                                }

                                if (1 == r)
                                {
                                    km = Piece.R1;
                                }
                                else
                                {
                                    km = Piece.R2;
                                }
                                break;

                            case Motigoma.H:
                                if (!PureMemory.gky_ky.motigomaItiran.Try_Herasu(out motiKomaItiranImpl, Motigoma.H
#if DEBUG
                                                                                 , (IDebugMojiretu)reigai1
#endif
                                                                                 ))
                                {
                                    return(Pure.FailTrue("Try_Herasu"));
                                }

                                if (1 == r)
                                {
                                    km = Piece.P1;
                                }
                                else
                                {
                                    km = Piece.P2;
                                }
                                break;

                            case Motigoma.z:
                                if (!PureMemory.gky_ky.motigomaItiran.Try_Herasu(out motiKomaItiranImpl, Motigoma.z
#if DEBUG
                                                                                 , (IDebugMojiretu)reigai1
#endif
                                                                                 ))
                                {
                                    return(Pure.FailTrue("Try_Herasu"));
                                }

                                if (1 == r)
                                {
                                    km = Piece.B2;
                                }
                                else
                                {
                                    km = Piece.B1;
                                }
                                break;

                            case Motigoma.k:
                                if (!PureMemory.gky_ky.motigomaItiran.Try_Herasu(out motiKomaItiranImpl, Motigoma.k
#if DEBUG
                                                                                 , reigai1
#endif
                                                                                 ))
                                {
                                    return(Pure.FailTrue("Try_Herasu"));
                                }

                                if (1 == r)
                                {
                                    km = Piece.R2;
                                }
                                else
                                {
                                    km = Piece.R1;
                                }
                                break;

                            case Motigoma.h:
                                if (!PureMemory.gky_ky.motigomaItiran.Try_Herasu(out motiKomaItiranImpl, Motigoma.h
#if DEBUG
                                                                                 , reigai1
#endif
                                                                                 ))
                                {
                                    return(Pure.FailTrue("Try_Herasu"));
                                }

                                if (1 == r)
                                {
                                    km = Piece.P2;
                                }
                                else
                                {
                                    km = Piece.P1;
                                }
                                break;
                            }

                            if (Piece.Yososu != km)
                            {
                                if (PureMemory.gky_ky.shogiban.TryFail_OkuKoma(//混ぜる
                                        (Masu)iMs1, km, true
#if DEBUG
                                        , reigai1
#endif
                                        ))
                                {
                                    return(Pure.FailTrue("TryFail_Oku"));
                                }
                            }

                            nokori--;
                        }
                    }

                    if (nokori < 0)
                    {
                        break;
                    }
                }

                // FIXME: 手番をひっくり返す機能は無いぜ☆(^~^)

                if (nokori < 0)
                {
                    break;
                }
            }

            // らいおんの先後を調整するぜ☆(^▽^)
            {
                Taikyokusya tb = Taikyokusya.T1;
                r = PureSettei.random.Next(2);
                if (0 == r)
                {
                    tb = Conv_Taikyokusya.Hanten(tb);
                }

                for (int iMs1 = 0; iMs1 < PureSettei.banHeimen; iMs1++)
                {
                    /*
                     * // トライしてたら、位置を変えるぜ☆(^▽^)www
                     * if (Koma.R == this.Komas[iMs1] && Conv_Masu.IsTried(Taikyokusya.T1, (Masu)iMs1))
                     * {
                     *  int iMs2 = iMs1 + 9;//9升足しておくか☆(^▽^)www
                     *  tmpKm = this.Komas[iMs1];
                     *  this.Komas[iMs1] = this.Komas[iMs2];
                     *  this.Komas[iMs2] = tmpKm;
                     * }
                     * else if (Koma.r == this.Komas[iMs1] && Conv_Masu.IsTried(Taikyokusya.T2, (Masu)iMs1))
                     * {
                     *  int iMs2 = iMs1 - 9;//9升引いておくか☆(^▽^)www
                     *  tmpKm = this.Komas[iMs1];
                     *  this.Komas[iMs1] = this.Komas[iMs2];
                     *  this.Komas[iMs2] = tmpKm;
                     * }
                     */

                    if (PureMemory.gky_ky.shogiban.ibashoBan_yk00.yomiIbashoBan.ExistsKoma(Piece.K1, (Masu)iMs1) || PureMemory.gky_ky.shogiban.ibashoBan_yk00.yomiIbashoBan.ExistsKoma(Piece.K2, (Masu)iMs1))
                    {
                        Piece km = Piece.Yososu;
                        if (tb == Taikyokusya.T1)
                        {
                            km = Piece.K1;
                        }
                        else
                        {
                            km = Piece.K2;
                        }

                        if (Piece.Yososu != km)
                        {
                            if (PureMemory.gky_ky.shogiban.TryFail_OkuKoma(//混ぜる
                                    (Masu)iMs1, km, true
#if DEBUG
                                    , reigai1
#endif
                                    ))
                            {
                                return(Pure.FailTrue("TryFail_Oku"));
                            }
                        }

                        tb = Conv_Taikyokusya.Hanten(tb);
                    }
                }
            }

            // 駒を配置したあとで使えだぜ☆(^~^)
            PureMemory.gky_ky.shogiban.Tukurinaosi_RemakeKiki();
            return(Pure.SUCCESSFUL_FALSE);
        }