/// <summary> /// 人間の入力したコマンドに対応した処理を行います。 /// 間違った入力があった場合、再帰的に呼び出されます。 /// /// Gnugo1.2 では、getmove関数。 /// </summary> /// <param name="move_charArray">入力した文字列。a1やT19などの指し手。</param> /// <param name="out_sasite">指し手。石を置く位置</param> /// <param name="taikyoku"></param> public static void DoCommand ( string command_str, out GobanPoint out_sasite, Taikyoku taikyoku ) { if (command_str == "stop") // ゲームを終了します。 { taikyoku.PlayState = GameState.Stop; out_sasite = new GobanPointImpl(-1, -1);// 2015-11-26 追加 } else { if (command_str == "save") // データを保存して、ゲームを終了します。 { // 局面を、テキストファイルに書き出します。 Util_Save.Save(taikyoku); taikyoku.PlayState = GameState.Saved; // i が -1 のときは、パスのシグナルです。 out_sasite = new GobanPointImpl(-1, -1); // 2015-11-26 追加 } else if (command_str == "pass") // 人間のパス { taikyoku.Pass++; // i が -1 のときは、パスのシグナルです。 out_sasite = new GobanPointImpl(-1, -1);// 2015-11-26 追加 } else { taikyoku.Pass = 0; if ( // 例えば、 a1 や、 T19 といった入力文字を解析し、盤上の位置に変換します。 !PointFugoImpl.TryParse(command_str, out out_sasite, taikyoku) || (taikyoku.Goban.At(out_sasite) != StoneColor.Empty) || Util_Suicide.Aa_Suicide(out_sasite, taikyoku) ) { // // 非合法手だった場合、再入力を促します。 // Console.WriteLine("illegal move !"); // [" + command_str + "] 2015-11-26 入力されたコマンドを表示するように拡張 Console.Write("your move? "); // 続けて、再帰的に処理実行。 string command_str2 = Console.ReadLine(); //scanf("%s", move); Util_CommandDriven.DoCommand(command_str2, out out_sasite, taikyoku); } } } }
/// <summary> /// どちらの地(陣地)でもない交点を、黒か白の石で交互に埋めます。 /// </summary> public static void FillNeutralTerritories ( Taikyoku taikyoku ) { bool isContinuePhase = true; // Gnugo1.2 では cont という変数名。continueの略だろうか? int youMeCounter = 0; //白黒を反転するためのカウンター GobanPoint location; // Gnugo1.2 では、 i, j という変数名。 do { if (youMeCounter % 2 == 0) { // // 指定した場所を、コンピューター側の石に置き換える処理です。 // Console.Write("Your piece? "); string an_str = Console.ReadLine(); //scanf("%s", an); //---------------------------------------- // 妥当な入力があるまで、くるくる回します。 //---------------------------------------- {//2015-11-27 追加 bool valid = false; if (an_str == "stop") { valid = true; location = null; } else { valid = PointFugoImpl.TryParse(an_str, out location, taikyoku); } if (!valid) { // 入力が不妥当なので、ループし直し。 goto gt_PlayerPieceContinue; } } // ここで入力が妥当と分かった。このあと処理。 if (an_str == "stop") { // ループから抜けます。 isContinuePhase = false; goto gt_PlayerPieceContinue; } else { taikyoku.Goban.Put(location, taikyoku.YourColor); ((BoardPrinterB)taikyoku.BoardPrinter).ShowBoard(taikyoku); } } else { // // 指定した場所を、相手(人間)の石に置き換える処理です。 // Console.Write("My piece? "); string an_str = Console.ReadLine(); //scanf("%s", an); //---------------------------------------- // 妥当な入力があるまで、くるくる回します。 //---------------------------------------- {//2015-11-27 追加 bool valid = false; if (an_str == "stop") { valid = true; location = null; } else { valid = PointFugoImpl.TryParse(an_str, out location, taikyoku); } if (!valid) { // 入力が不妥当なので、ループし直し。 goto gt_PlayerPieceContinue; } } // ここで入力が妥当と分かった。このあと処理。 if (an_str == "stop") { // ループから抜けます。 isContinuePhase = false; goto gt_PlayerPieceContinue; } else { taikyoku.Goban.Put(location, taikyoku.MyColor); ((BoardPrinterB)taikyoku.BoardPrinter).ShowBoard(taikyoku); } } youMeCounter++; gt_PlayerPieceContinue: ; }while (isContinuePhase); }
/// <summary> /// 死んでいる石のつながりを、盤上から削除します。 /// /// Gnugo1.2 では、endgame関数。 /// </summary> /// <param name="taikyoku"></param> public static void Remove_DeadPieces(Taikyoku taikyoku) { bool isContinuePhase; // Gnugo1.2 では cont という変数名。continueの略だろうか? // // 最初にコンピューター側を調べ、次に人間側を調べます。 // 盤上の各点の石が、どの方向に隣接する石を持っているかを調べています。 // // コンピューター側 Dictionary <int, List <int> > myList_neswStones_asNode_eachPoint;// Gnugo1.2 では、mymovelist という変数名。int mymovelist[NODES][5]。 Util_EndOfGame.GetNeswStones_AsNode_EachPoint(taikyoku.MyColor, out myList_neswStones_asNode_eachPoint, taikyoku); // 人間側 Dictionary <int, List <int> > yourList_neswStones_asNode_eachPoint;// Gnugo1.2 では、umovelist という変数名。int umovelist[NODES][5];。 Util_EndOfGame.GetNeswStones_AsNode_EachPoint(taikyoku.YourColor, out yourList_neswStones_asNode_eachPoint, taikyoku); isContinuePhase = true; GobanPoint location;// Gnugo1.2 では、 i, j という変数名。 do { Console.Write("Dead piece? "); // 死んでいる石の場所を入力してください。 string an_str = Console.ReadLine(); //scanf("%s", an); //---------------------------------------- // 妥当な入力があるまで、くるくる回します。 //---------------------------------------- {//2015-11-27 追加 bool valid = false; if (an_str == "stop") { valid = true; location = null; } else { valid = PointFugoImpl.TryParse(an_str, out location, taikyoku); } if (!valid) { // 入力が不妥当なので、ループし直し。 goto gt_DeadPieceContinue; } } if (an_str == "stop") { // ループから抜けます。 isContinuePhase = false; goto gt_DeadPieceContinue; } else { if (taikyoku.Goban.At(location) == taikyoku.MyColor) { #if DEBUG Console.WriteLine("Just before bfslist."); #endif List <int> nodeList; Util_EndOfGame.GetConnectedStones_AsNode_FromPoint(out nodeList, location, myList_neswStones_asNode_eachPoint, taikyoku); #if DEBUG Console.WriteLine("Survived first bfslist."); #endif // 示された場所を空にしていき、コンピューターの取られた石カウントを増やします。 foreach (int node in nodeList) { Util_AboutBoard.GetLocationByNode(out location, node, taikyoku.GobanBounds); taikyoku.Goban.Put(location, StoneColor.Empty); taikyoku.Count_MyCaptured++; } } else if (taikyoku.Goban.At(location) == taikyoku.YourColor) { #if DEBUG Console.WriteLine("Just before second bfslist."); #endif List <int> nodeList; Util_EndOfGame.GetConnectedStones_AsNode_FromPoint(out nodeList, location, yourList_neswStones_asNode_eachPoint, taikyoku); // 示された場所を空にしていき、人間の取られた石カウントを増やします。 foreach (int node in nodeList) { Util_AboutBoard.GetLocationByNode(out location, node, taikyoku.GobanBounds); taikyoku.Goban.Put(location, StoneColor.Empty); taikyoku.Count_YourCaptured++; } } ((BoardPrinterB)taikyoku.BoardPrinter).ShowBoard(taikyoku); } gt_DeadPieceContinue: ; }while (isContinuePhase); }