/// <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); }
/// <summary> /// 決着判定 /// </summary> /// <param name="bestMove">投了かどうか調べるだけだぜ☆(^▽^)</param> public static bool Try_JudgeKettyaku(Move bestMove #if DEBUG , StringBuilder hyoji #endif ) { Taikyokusya tb2 = Conv_Taikyokusya.Hanten(PureMemory.kifu_teban); if (Move.Toryo == bestMove) { switch (PureMemory.kifu_teban)// 投了した時点で、次の手番に移っているぜ☆ { case Taikyokusya.T2: // 対局者1が投了して、対局者2の手番になったということだぜ☆ // だから対局者2の勝ちだぜ☆ PureMemory.gky_kekka = TaikyokuKekka.Taikyokusya2NoKati; break; case Taikyokusya.T1: PureMemory.gky_kekka = TaikyokuKekka.Taikyokusya1NoKati; break; default: #if DEBUG hyoji.AppendLine("未定義の手番"); #endif return(false); } } // トライルール else if (Util_TryRule.IsTried( tb2//手番が進んでいるので、相手番のトライを判定☆ ) ) { switch (tb2) { case Taikyokusya.T1: PureMemory.gky_kekka = TaikyokuKekka.Taikyokusya1NoKati; break; case Taikyokusya.T2: PureMemory.gky_kekka = TaikyokuKekka.Taikyokusya2NoKati; break; default: #if DEBUG hyoji.AppendLine("未定義の手番"); #endif return(false); } } else { // らいおんがいるか☆ bool raion1Vanished = PureMemory.gky_ky.shogiban.ibashoBan_yk00.yomiIbashoBan.IsEmptyKoma(Piece.K1); bool raion2Vanished = PureMemory.gky_ky.shogiban.ibashoBan_yk00.yomiIbashoBan.IsEmptyKoma(Piece.K2); if (raion1Vanished && raion2Vanished) { // らいおんが2匹ともいない場合(エラー) PureMemory.gky_kekka = TaikyokuKekka.Hikiwake; } else if (raion2Vanished) { PureMemory.gky_kekka = TaikyokuKekka.Taikyokusya1NoKati; } else if (raion1Vanished) { PureMemory.gky_kekka = TaikyokuKekka.Taikyokusya2NoKati; } } return(true); }