/// <summary> /// 局面をbod形式に変換します。 /// </summary> /// <example> /// 後手の持駒:飛 角 金 銀 桂 香 歩四 /// 9 8 7 6 5 4 3 2 1 /// +---------------------------+ /// |v香v桂 ・ ・ ・ ・ ・ ・ ・|一 /// | ・ ・ ・ 馬 ・ ・ 龍 ・ ・|二 /// | ・ ・v玉 ・v歩 ・ ・ ・ ・|三 /// |v歩 ・ ・ ・v金 ・ ・ ・ ・|四 /// | ・ ・v銀 ・ ・ ・v歩 ・ ・|五 /// | ・ ・ ・ ・ 玉 ・ ・ ・ ・|六 /// | 歩 歩 ・ 歩 歩v歩 歩 ・ 歩|七 /// | ・ ・ ・ ・ ・ ・ ・ ・ ・|八 /// | 香 桂v金 ・v金 ・ ・ 桂 香|九 /// +---------------------------+ /// 先手の持駒:銀二 歩四 /// 手数=171 ▲6二角成 まで /// /// 後手番 /// </example> public static string BoardToBod(Board board) { if (board == null || !board.Validate()) { throw new ArgumentException("board"); } var result = new List <string>(); var type = BoardTypeUtil.GetBoardTypeFromBoard(board); if (type != BoardType.None) { result.Add("手合割:" + EnumEx.GetLabel(type)); } else { result.Add("後手の持駒:" + HandToBod(board, BWType.White)); result.Add(" 9 8 7 6 5 4 3 2 1"); result.Add("+---------------------------+"); result.AddRange( Enumerable.Range(1, Board.BoardSize) .Select(_ => RankToBod(board, _))); result.Add("+---------------------------+"); result.Add("先手の持駒:" + HandToBod(board, BWType.Black)); result.Add("手数=" + board.MoveCount); if (board.Turn == BWType.White) { result.Add("後手番"); } } return(string.Join("\n", result)); }
/// <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); }