/// <summary> /// 局面を、テキストファイルに書き出します。 /// /// 19路盤、9路盤 両用です。 /// </summary> /// <param name="taikyoku"></param> public static void Save(Taikyoku taikyoku) { StringBuilder sb = new StringBuilder(); //fp = fopen("gnugo.dat", "w"); // 盤設定を保存します。 for (int m = 0; m < taikyoku.GobanBounds.BoardSize; m++) { for (int n = 0; n < taikyoku.GobanBounds.BoardSize; n++) { sb.Append(Conv_StoneColor.ToNumber(taikyoku.Goban.At(new GobanPointImpl(m, n)))); //fprintf(fp, "%c", Util_GlobalVar.P[m,n]); } } // コンピューターの色、お互いの取ったピース sb.Append(Conv_StoneColor.ToNumber(taikyoku.MyColor)); sb.Append(" "); sb.Append(taikyoku.Count_MyCaptured); sb.Append(" "); sb.Append(taikyoku.Count_YourCaptured); sb.Append(" "); //fprintf(fp, "%d %d %d ", Util_GlobalVar.Mymove, Util_GlobalVar.Mk, Util_GlobalVar.Uk); // 序盤定跡フラグ for (int index = 0; index < 9; index++) { sb.Append(taikyoku.OpeningZyosekiFlag[index] ? 1 : 0); sb.Append(" "); //fprintf(fp, "%d ", Util_GlobalVar.Opn[m]); } //fclose(fp); File.WriteAllText(taikyoku.SaveFileName, sb.ToString()); }
/// <summary> /// セーブファイルを読み込み、局面を復元します。 /// </summary> /// <param name="taikyoku"></param> /// <param name="boardSize">19路盤なら19、9路盤なら9と入れてください。</param> public static void Load(out Taikyoku taikyoku, int boardSize) { BoardPrinterB boardPrinterB; switch (boardSize) { case 9: boardPrinterB = new N9zibanPrinterImpl(); break; default: boardPrinterB = new N19zibanPrinterImpl(); break; } taikyoku = new TaikyokuImpl( boardSize, new ComputerPlayerBImpl(), new BoardImpl(boardSize), new MarkingBoardImpl(boardSize), new CountedBoardImpl(boardSize), boardPrinterB ); string gnugoDatText = File.ReadAllText(taikyoku.SaveFileName); // 盤設定を読み込みます。 for (int i = 0; i < taikyoku.GobanBounds.BoardSize; i++) { for (int j = 0; j < taikyoku.GobanBounds.BoardSize; j++) { taikyoku.Goban.Put(new GobanPointImpl(i, j), Conv_StoneColor.FromNumber(int.Parse(gnugoDatText.Substring(0, 1)))); gnugoDatText = gnugoDatText.Substring(1); //fscanf(fp, "%c", ref ; } } // コンピューターの色、取ったピースズを読み込みます。 int ix; ix = gnugoDatText.IndexOf(" "); taikyoku.MyColor = Conv_StoneColor.FromNumber(int.Parse(gnugoDatText.Substring(0, ix))); gnugoDatText = gnugoDatText.Substring(ix + 1//空白の次へ ); ix = gnugoDatText.IndexOf(" "); taikyoku.Count_MyCaptured = int.Parse(gnugoDatText.Substring(0, ix)); gnugoDatText = gnugoDatText.Substring(ix + 1); ix = gnugoDatText.IndexOf(" "); taikyoku.Count_YourCaptured = int.Parse(gnugoDatText.Substring(0, ix)); gnugoDatText = gnugoDatText.Substring(ix + 1); //fscanf(fp, "%d %d %d ", ref Util_GlobalVar.Mymove, // ref Util_GlobalVar.Mk, ref Util_GlobalVar.Uk); // 序盤定跡フラグを読み込みます。 for (int index = 0; index < 9; index++) { ix = gnugoDatText.IndexOf(" "); taikyoku.OpeningZyosekiFlag[index] = int.Parse(gnugoDatText.Substring(0, ix)) != 0; gnugoDatText = gnugoDatText.Substring(ix + 1); //fscanf(fp, "%d ", ref Util_GlobalVar.Opn[i]); } //fclose(fp); taikyoku.YourColor = Conv_StoneColor.FromNumber(3 - (int)taikyoku.MyColor); }