/// <summary> /// bod形式の文字列から、局面を読み取ります。 /// </summary> public static Board Parse(string text) { if (text == null) { throw new ArgumentNullException("text"); } var parser = new BodParser(); var lines = text.Split( new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); foreach (var line in lines) { if (KifUtil.IsCommentLine(line)) { continue; } // 局面の読み取りを試みます。 if (parser.TryParse(line)) { continue; } var item = KifUtil.ParseHeaderItem(line); if (item != null) { continue; } break; } if (!parser.IsCompleted) { throw new ShogiException( "局面の読み取りを完了できませんでした。"); } return(parser.Board); }
/// <summary> /// bod形式の文字列から、局面を読み取ります。 /// </summary> public static Board Parse(string text) { if (text == null) { throw new ArgumentNullException("text"); } var parser = new BodParser(); var lines = text.Split( new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); foreach (var line in lines) { if (KifUtil.IsCommentLine(line)) { continue; } // 局面の読み取りを試みます。 if (parser.TryParse(line)) { continue; } var item = KifUtil.ParseHeaderItem(line); if (item != null) { continue; } break; } if (!parser.IsCompleted) { throw new ShogiException( "局面の読み取りを完了できませんでした。"); } return parser.Board; }
/// <summary> /// ヘッダー行をパースします。 /// </summary> private bool ParseHeaderLine(string line, BodParser parser, KifuHeader header = null, KifMoveNode head = null) { if (line == null) { // ファイルの終了を意味します。 return false; } var commentData = KifUtil.ParseCommentLine(line); if (commentData != null) { // コメントはパース結果に含めます。 if (head != null && commentData.IsMoveComment) { head.AddComment(commentData.Comment); } return true; } // 読み飛ばすべき説明行 if (line.Contains("手数----指手---------消費時間")) { this.isKif = true; // kif形式です。 return true; } // 局面の読み取りを試みます。 if (parser.TryParse(line)) { return true; } var item = KifUtil.ParseHeaderItem(line); if (item != null) { if (item.Key == "手合割" && item.Value != "その他") { this.startBoard = BoardTypeUtil.CreateBoardFromName(item.Value); } if (header != null) { // 可能ならヘッダアイテムを設定します。 var type = KifUtil.GetHeaderType(item.Key); if (type != null) { header[type.Value] = item.Value; } } return true; } // ヘッダが正しく読めない場合、 // 区切りなしに指し手行に入っている可能性があります。 if (MoveLineRegex.IsMatch(line)) { this.isKif = true; } return false; }
/// <summary> /// ヘッダー行をパースします。 /// </summary> private bool ParseHeaderLine(string line, BodParser parser, KifuHeader header = null, KifMoveNode head = null) { if (line == null) { // ファイルの終了を意味します。 return(false); } var commentData = KifUtil.ParseCommentLine(line); if (commentData != null) { // コメントはパース結果に含めます。 if (head != null && commentData.IsMoveComment) { head.AddComment(commentData.Comment); } return(true); } // 読み飛ばすべき説明行 if (line.Contains("手数----指手---------消費時間")) { this.isKif = true; // kif形式です。 return(true); } // 局面の読み取りを試みます。 if (parser.TryParse(line)) { return(true); } var item = KifUtil.ParseHeaderItem(line); if (item != null) { if (item.Key == "手合割" && item.Value != "その他") { this.startBoard = BoardTypeUtil.CreateBoardFromName(item.Value); } if (header != null) { // 可能ならヘッダアイテムを設定します。 var type = KifUtil.GetHeaderType(item.Key); if (type != null) { header[type.Value] = item.Value; } } return(true); } // ヘッダが正しく読めない場合、 // 区切りなしに指し手行に入っている可能性があります。 if (MoveLineRegex.IsMatch(line)) { this.isKif = true; } return(false); }
/// <summary> /// ヘッダー行をパースします。 /// </summary> private bool ParseHeaderLine(string line, BodParser parser, KifuHeader header = null) { if (line == null) { // ファイルの終了を意味します。 return false; } if (IsCommentLine(line)) { return true; } // 読み飛ばすべき説明行 if (line.Contains("手数----指手---------消費時間")) { this.isKif = true; // kif形式です。 return true; } // 局面の読み取りを試みます。 if (parser.TryParse(line)) { return true; } var item = KifUtil.ParseHeaderItem(line); if (item != null) { if (item.Key == "手合割" && item.Value != "その他") { this.startBoard = BoardTypeUtil.CreateBoardFromName(item.Value); } if (header != null) { // 可能ならヘッダアイテムを設定します。 var type = KifUtil.GetHeaderType(item.Key); if (type != null) { header[type.Value] = item.Value; } } return true; } return false; }