public string Execute( ref KifuParserA_Result result, Model_Taikyoku model_Taikyoku, out KifuParserA_State nextState, KifuParserA owner, KifuParserA_Genjo genjo ) { nextState = this; Logger.Error($"(^△^)「{genjo.InputLine}」vs【{this.GetType().Name}】 : さて、どんな内容なんだぜ☆?"); StartposImporter startposImporter1; string restText; bool successful = StartposImporter.TryParse( genjo.InputLine, out startposImporter1, out restText ); genjo.StartposImporter_OrNull = startposImporter1; Logger.Error($"(^△^)restText=「{restText}」 successful=【{successful}】"); if (successful) { genjo.InputLine = restText; //if(null!=genjo.StartposImporter_OrNull) //{ // // SFENの解析結果を渡すので、 // // その解析結果をどう使うかは、委譲します。 // owner.Delegate_OnChangeSky_Im( // model_PnlTaikyoku, // genjo, // logTag // ); //} nextState = KifuParserA_StateA2_SfenMoves.GetInstance(); } else { // 解析に失敗しました。 //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> genjo.ToBreak_Abnormal(); } return(genjo.InputLine); }
public static bool TryParse( string inputLine, out StartposImporter instance, out string rest ) { bool successful = true; ISfenPosition2 ro_SfenStartpos; if (!Sfenstring146Conv.ToKyokumen2(inputLine, out rest, out ro_SfenStartpos)) { successful = false; instance = null; goto gt_EndMethod; } instance = new StartposImporter(inputLine, ro_SfenStartpos); gt_EndMethod: return(successful); }
public SkyConst ToSky(Playerside kaisiPside, int temezumi) { // 駒40個に、Finger番号を割り当てておきます。 SkyBuffer dst_Sky = new SkyBuffer(kaisiPside, temezumi);// 駒数0。 //SkyBuffer dst_Sky = new SkyBuffer(Util_Sky.New_Komabukuro());// SFENインポート時 Dictionary <Finger, RO_Star> komaDic = new Dictionary <Finger, RO_Star>(); // ・インクリメントするので、Finger型ではなく int型で。 // ・駒を取ったときに、先手後手は浮動するので区別できない。 // 王 0~1 int int_fingerK1 = 0; int int_fingerK2 = 1; // 飛車 2~3 int int_fingerR1 = 2; int int_fingerR2 = 3; // 角 4~5 int int_fingerB1 = 4; int int_fingerB2 = 5; // 金 6~9 int int_fingerG1 = 6; int int_fingerG2 = 8; // 銀 10~13 int int_fingerS1 = 10; int int_fingerS2 = 12; // 桂 14~17 int int_fingerN1 = 14; int int_fingerN2 = 16; // 香 18~21 int int_fingerL1 = 18; int int_fingerL2 = 20; // 歩 22~30,31~39 int int_fingerP1 = 22; int int_fingerP2 = 31; // // どの升に、どの駒がいるか // foreach (KeyValuePair <int, RO_Star> entry in this.masubetuKoma_banjo) { int int_finger; // 今回のカウント switch (entry.Value.Komasyurui) { case PieceType.P: switch (entry.Value.Pside) { case Playerside.P1: int_finger = int_fingerP1; break; case Playerside.P2: int_finger = int_fingerP2; break; default: throw new Exception("未対応のプレイヤー番号"); } break; case PieceType.L: switch (entry.Value.Pside) { case Playerside.P1: int_finger = int_fingerL1; break; case Playerside.P2: int_finger = int_fingerL2; break; default: throw new Exception("未対応のプレイヤー番号"); } break; case PieceType.N: switch (entry.Value.Pside) { case Playerside.P1: int_finger = int_fingerN1; break; case Playerside.P2: int_finger = int_fingerN2; break; default: throw new Exception("未対応のプレイヤー番号"); } break; case PieceType.S: switch (entry.Value.Pside) { case Playerside.P1: int_finger = int_fingerS1; break; case Playerside.P2: int_finger = int_fingerS2; break; default: throw new Exception("未対応のプレイヤー番号"); } break; case PieceType.G: switch (entry.Value.Pside) { case Playerside.P1: int_finger = int_fingerG1; break; case Playerside.P2: int_finger = int_fingerG2; break; default: throw new Exception("未対応のプレイヤー番号"); } break; case PieceType.K: switch (entry.Value.Pside) { case Playerside.P1: int_finger = int_fingerK1; break; case Playerside.P2: int_finger = int_fingerK2; break; default: throw new Exception("未対応のプレイヤー番号"); } break; case PieceType.R: switch (entry.Value.Pside) { case Playerside.P1: int_finger = int_fingerR1; break; case Playerside.P2: int_finger = int_fingerR2; break; default: throw new Exception("未対応のプレイヤー番号"); } break; case PieceType.B: switch (entry.Value.Pside) { case Playerside.P1: int_finger = int_fingerB1; break; case Playerside.P2: int_finger = int_fingerB2; break; default: throw new Exception("未対応のプレイヤー番号"); } break; case PieceType.PR: switch (entry.Value.Pside) { case Playerside.P1: int_finger = int_fingerR1; break; case Playerside.P2: int_finger = int_fingerR2; break; default: throw new Exception("未対応のプレイヤー番号"); } break; case PieceType.PB: switch (entry.Value.Pside) { case Playerside.P1: int_finger = int_fingerB1; break; case Playerside.P2: int_finger = int_fingerB2; break; default: throw new Exception("未対応のプレイヤー番号"); } break; case PieceType.PP: switch (entry.Value.Pside) { case Playerside.P1: int_finger = int_fingerP1; break; case Playerside.P2: int_finger = int_fingerP2; break; default: throw new Exception("未対応のプレイヤー番号"); } break; case PieceType.PL: switch (entry.Value.Pside) { case Playerside.P1: int_finger = int_fingerL1; break; case Playerside.P2: int_finger = int_fingerL2; break; default: throw new Exception("未対応のプレイヤー番号"); } break; case PieceType.PN: switch (entry.Value.Pside) { case Playerside.P1: int_finger = int_fingerN1; break; case Playerside.P2: int_finger = int_fingerN2; break; default: throw new Exception("未対応のプレイヤー番号"); } break; case PieceType.PS: switch (entry.Value.Pside) { case Playerside.P1: int_finger = int_fingerS1; break; case Playerside.P2: int_finger = int_fingerS2; break; default: throw new Exception("未対応のプレイヤー番号"); } break; default: throw new Exception($"未対応の駒種類=[{entry.Value.Komasyurui}]"); } Debug.Assert(0 <= int_finger && int_finger <= 39, $"finger=[{int_finger}]"); Debug.Assert(!komaDic.ContainsKey(int_finger), $"finger=[{int_finger}]"); komaDic.Add(int_finger, entry.Value); // カウントアップ switch (entry.Value.Komasyurui) { case PieceType.P: switch (entry.Value.Pside) { case Playerside.P1: int_fingerP1++; break; case Playerside.P2: int_fingerP2++; break; default: throw new Exception("未対応のプレイヤー番号"); } break; case PieceType.L: switch (entry.Value.Pside) { case Playerside.P1: int_fingerL1++; break; case Playerside.P2: int_fingerL2++; break; default: throw new Exception("未対応のプレイヤー番号"); } break; case PieceType.N: switch (entry.Value.Pside) { case Playerside.P1: int_fingerN1++; break; case Playerside.P2: int_fingerN2++; break; default: throw new Exception("未対応のプレイヤー番号"); } break; case PieceType.S: switch (entry.Value.Pside) { case Playerside.P1: int_fingerS1++; break; case Playerside.P2: int_fingerS2++; break; default: throw new Exception("未対応のプレイヤー番号"); } break; case PieceType.G: switch (entry.Value.Pside) { case Playerside.P1: int_fingerG1++; break; case Playerside.P2: int_fingerG2++; break; default: throw new Exception("未対応のプレイヤー番号"); } break; case PieceType.K: switch (entry.Value.Pside) { case Playerside.P1: int_fingerK1++; break; case Playerside.P2: int_fingerK2++; break; default: throw new Exception("未対応のプレイヤー番号"); } break; case PieceType.R: switch (entry.Value.Pside) { case Playerside.P1: int_fingerR1++; break; case Playerside.P2: int_fingerR2++; break; default: throw new Exception("未対応のプレイヤー番号"); } break; case PieceType.B: switch (entry.Value.Pside) { case Playerside.P1: int_fingerB1++; break; case Playerside.P2: int_fingerB2++; break; default: throw new Exception("未対応のプレイヤー番号"); } break; case PieceType.PR: switch (entry.Value.Pside) { case Playerside.P1: int_fingerR1++; break; case Playerside.P2: int_fingerR2++; break; default: throw new Exception("未対応のプレイヤー番号"); } break; case PieceType.PB: switch (entry.Value.Pside) { case Playerside.P1: int_fingerB1++; break; case Playerside.P2: int_fingerB2++; break; default: throw new Exception("未対応のプレイヤー番号"); } break; case PieceType.PP: switch (entry.Value.Pside) { case Playerside.P1: int_fingerP1++; break; case Playerside.P2: int_fingerP2++; break; default: throw new Exception("未対応のプレイヤー番号"); } break; case PieceType.PL: switch (entry.Value.Pside) { case Playerside.P1: int_fingerL1++; break; case Playerside.P2: int_fingerL2++; break; default: throw new Exception("未対応のプレイヤー番号"); } break; case PieceType.PN: switch (entry.Value.Pside) { case Playerside.P1: int_fingerN1++; break; case Playerside.P2: int_fingerN2++; break; default: throw new Exception("未対応のプレイヤー番号"); } break; case PieceType.PS: switch (entry.Value.Pside) { case Playerside.P1: int_fingerS1++; break; case Playerside.P2: int_fingerS2++; break; default: throw new Exception("未対応のプレイヤー番号"); } break; default: throw new Exception($"未対応の駒種類=[{entry.Value.Komasyurui}]"); } } // // 40個の駒が、どの升に居るか // { // finger の順に並べる。 RO_Star[] komas = new RO_Star[40]; foreach (KeyValuePair <Finger, RO_Star> entry in komaDic) { Debug.Assert(0 <= (int)entry.Key && (int)entry.Key <= 39, $"entry.Key=[{(int)entry.Key}]"); komas[(int)entry.Key] = entry.Value; } // finger の順に追加。 int komaHandle = 0; foreach (RO_Star koma in komas) { dst_Sky.PutOverwriteOrAdd_Starlight( komaHandle, new RO_Starlight( //komaHandle, koma ) ); komaHandle++; } } StartposImporter.Assert_HirateHonsyogi(dst_Sky, $"ToSkyの終了直前 this.InputLine=[{this.InputLine}]"); return(SkyConst.NewInstance(dst_Sky, -1//dst_sky で設定済みなのでそのまま。 )); }
/// <summary> /// /// </summary> /// <param name="kifu"></param> /// <param name="restText"></param> /// <param name="startposImporter"></param> /// <param name="logTag"></param> public static ParsedKyokumen ToParsedKyokumen( Model_Manual model_Manual,// Gui局面を使用 StartposImporter startposImporter, KifuParserA_Genjo genjo ) { ParsedKyokumen parsedKyokumen = new ParsedKyokumenImpl(); //------------------------------ // 初期局面の先後 //------------------------------ if (startposImporter.RO_SfenStartpos.PsideIsBlack) { // 黒は先手。 parsedKyokumen.FirstPside = Playerside.P1; } else { // 白は後手。 parsedKyokumen.FirstPside = Playerside.P2; } //------------------------------ // 駒の配置 //------------------------------ parsedKyokumen.KifuNode = new KifuNodeImpl( Util_Sky258A.RootMove, //ルートなので new KyokumenWrapper( SkyConst.NewInstance( startposImporter.ToSky( parsedKyokumen.FirstPside, startposImporter.RO_SfenStartpos.Temezumi // FIXME: 将棋所だと常に 1 かも?? ), -1 // src_Sky_Newで設定済みだからそのまま。 ) ) ); //------------------------------ // 駒袋に表示されている駒を、駒台に表示されるように移します。 //------------------------------ { //------------------------------ // 持ち駒 ▲王 //------------------------------ if (0 < startposImporter.RO_SfenStartpos.Moti1K) { parsedKyokumen.MotiList.Add(new MotiItemImpl(PieceType.K, startposImporter.RO_SfenStartpos.Moti1K, Playerside.P1)); } //------------------------------ // 持ち駒 ▲飛 //------------------------------ if (0 < startposImporter.RO_SfenStartpos.Moti1R) { parsedKyokumen.MotiList.Add(new MotiItemImpl(PieceType.R, startposImporter.RO_SfenStartpos.Moti1R, Playerside.P1)); } //------------------------------ // 持ち駒 ▲角 //------------------------------ if (0 < startposImporter.RO_SfenStartpos.Moti1B) { parsedKyokumen.MotiList.Add(new MotiItemImpl(PieceType.B, startposImporter.RO_SfenStartpos.Moti1B, Playerside.P1)); } //------------------------------ // 持ち駒 ▲金 //------------------------------ if (0 < startposImporter.RO_SfenStartpos.Moti1G) { parsedKyokumen.MotiList.Add(new MotiItemImpl(PieceType.G, startposImporter.RO_SfenStartpos.Moti1G, Playerside.P1)); } //------------------------------ // 持ち駒 ▲銀 //------------------------------ if (0 < startposImporter.RO_SfenStartpos.Moti1S) { parsedKyokumen.MotiList.Add(new MotiItemImpl(PieceType.S, startposImporter.RO_SfenStartpos.Moti1S, Playerside.P1)); } //------------------------------ // 持ち駒 ▲桂 //------------------------------ if (0 < startposImporter.RO_SfenStartpos.Moti1N) { parsedKyokumen.MotiList.Add(new MotiItemImpl(PieceType.N, startposImporter.RO_SfenStartpos.Moti1N, Playerside.P1)); } //------------------------------ // 持ち駒 ▲香 //------------------------------ if (0 < startposImporter.RO_SfenStartpos.Moti1L) { parsedKyokumen.MotiList.Add(new MotiItemImpl(PieceType.L, startposImporter.RO_SfenStartpos.Moti1L, Playerside.P1)); } //------------------------------ // 持ち駒 ▲歩 //------------------------------ if (0 < startposImporter.RO_SfenStartpos.Moti1P) { parsedKyokumen.MotiList.Add(new MotiItemImpl(PieceType.P, startposImporter.RO_SfenStartpos.Moti1P, Playerside.P1)); } //------------------------------ // 持ち駒 △王 //------------------------------ if (0 < startposImporter.RO_SfenStartpos.Moti2k) { parsedKyokumen.MotiList.Add(new MotiItemImpl(PieceType.K, startposImporter.RO_SfenStartpos.Moti2k, Playerside.P2)); } //------------------------------ // 持ち駒 △飛 //------------------------------ if (0 < startposImporter.RO_SfenStartpos.Moti2r) { parsedKyokumen.MotiList.Add(new MotiItemImpl(PieceType.R, startposImporter.RO_SfenStartpos.Moti2r, Playerside.P2)); } //------------------------------ // 持ち駒 △角 //------------------------------ if (0 < startposImporter.RO_SfenStartpos.Moti2b) { parsedKyokumen.MotiList.Add(new MotiItemImpl(PieceType.B, startposImporter.RO_SfenStartpos.Moti2b, Playerside.P2)); } //------------------------------ // 持ち駒 △金 //------------------------------ if (0 < startposImporter.RO_SfenStartpos.Moti2g) { parsedKyokumen.MotiList.Add(new MotiItemImpl(PieceType.G, startposImporter.RO_SfenStartpos.Moti2g, Playerside.P2)); } //------------------------------ // 持ち駒 △銀 //------------------------------ if (0 < startposImporter.RO_SfenStartpos.Moti2s) { parsedKyokumen.MotiList.Add(new MotiItemImpl(PieceType.S, startposImporter.RO_SfenStartpos.Moti2s, Playerside.P2)); } //------------------------------ // 持ち駒 △桂 //------------------------------ if (0 < startposImporter.RO_SfenStartpos.Moti2n) { parsedKyokumen.MotiList.Add(new MotiItemImpl(PieceType.N, startposImporter.RO_SfenStartpos.Moti2n, Playerside.P2)); } //------------------------------ // 持ち駒 △香 //------------------------------ if (0 < startposImporter.RO_SfenStartpos.Moti2l) { parsedKyokumen.MotiList.Add(new MotiItemImpl(PieceType.L, startposImporter.RO_SfenStartpos.Moti2l, Playerside.P2)); } //------------------------------ // 持ち駒 △歩 //------------------------------ if (0 < startposImporter.RO_SfenStartpos.Moti2p) { parsedKyokumen.MotiList.Add(new MotiItemImpl(PieceType.P, startposImporter.RO_SfenStartpos.Moti2p, Playerside.P2)); } } //------------------------------------------------------------------------------------------------------------------------ // 移動 //------------------------------------------------------------------------------------------------------------------------ for (int i = 0; i < parsedKyokumen.MotiList.Count; i++) { Playerside itaruPside; //(至)先後 Okiba itaruOkiba; //(至)置き場 if (Playerside.P2 == parsedKyokumen.MotiList[i].Playerside) { // 宛:後手駒台 itaruPside = Playerside.P2; itaruOkiba = Okiba.Gote_Komadai; } else { // 宛:先手駒台 itaruPside = Playerside.P1; itaruOkiba = Okiba.Sente_Komadai; } //------------------------------ // 駒を、駒袋から駒台に移動させます。 //------------------------------ { parsedKyokumen.buffer_Sky = new SkyBuffer(model_Manual.GuiSkyConst); Fingers komas = Util_Sky_FingersQuery.InOkibaKomasyuruiNow( SkyConst.NewInstance( // FIXME: SkyConstではなく、Skyではだめなのか☆? parsedKyokumen.buffer_Sky, -1 //そのまま。 ), Okiba.KomaBukuro, parsedKyokumen.MotiList[i].Komasyurui ); int moved = 1; foreach (Finger koma in komas.Items) { // 駒台の空いている枡 SyElement akiMasu = Util_IttesasuRoutine.GetKomadaiKomabukuroSpace( itaruOkiba, SkyConst.NewInstance( parsedKyokumen.buffer_Sky, -1//そのまま ) ); parsedKyokumen.buffer_Sky.PutOverwriteOrAdd_Starlight( koma, new RO_Starlight( new RO_Star( itaruPside, akiMasu, parsedKyokumen.MotiList[i].Komasyurui ) ) ); if (parsedKyokumen.MotiList[i].Maisu <= moved) { break; } moved++; } } }//for return(parsedKyokumen); }