/// <summary> /// CSA形式の文字列から、局面を読み取ります。 /// </summary> public static Board Parse(string csa) { if (string.IsNullOrEmpty(csa)) { throw new ArgumentNullException("csa"); } var parser = new CsaBoardParser(); csa.Split( new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries) .Where(_ => !CsaUtil.IsCommentLine(_)) .ForEach(_ => parser.TryParse(_)); return(parser.Board); }
/// <summary> /// ヘッダー行をパースします。 /// </summary> private bool ParseLine(string line, CsaBoardParser parser) { if (line == null) { // ファイルの終了を意味します。 return(false); } if (CsaUtil.IsCommentLine(line)) { return(true); } // 局面の読み取りを試みます。 if (parser.TryParse(line)) { if (parser.HasBoard && !parser.IsBoardParsing) { this.startBoard = parser.Board.Clone(); this.board = this.startBoard.Clone(); } return(true); } switch (line[0]) { case 'V': return(true); case 'N': ParseName(line); return(true); case '$': ParseHeader(line); return(true); case '+': case '-': case '%': var move = ParseMove(line); var node = new MoveNode { Move = move, }; this.lastNode.AddNextNode(node); this.lastNode = node; return(true); case 'T': var seconds = ParseTime(line); if (this.lastNode != null) { this.lastNode.DurationSeconds = seconds; } return(true); } return(false); }