/// <summary> /// 指し手を文字列に変換します。 /// </summary> /// <remarks> /// KifFileに使う指し手は同○○の場合、 /// 「同」と「○○」の間に空白を入れないと"kif for windows"では /// 正しく読み込めなくなります。 /// </remarks> public static string ToString(Move move, MoveTextStyle style = MoveTextStyle.Normal) { if (move == null) { return(null); } if (move.IsSpecialMove) { var turnStr = string.Empty; // 必要なら▲△を先頭に入れます。 if (style == MoveTextStyle.Normal) { turnStr = ToString(move.BWType); } return(turnStr + EnumEx.GetLabel(move.SpecialMoveType)); } var result = new StringBuilder(); result.Append(ToString(move.Piece)); result.Append(ToString(move.RelFileType)); result.Append(ToString(move.RankMoveType)); result.Append(ToString(move.ActionType)); if (move.SameAsOld) { var hasSpace = ( (style != MoveTextStyle.Simple) && (result.Length == 1 || style == MoveTextStyle.KifFile)); // 文字数によって、同の後の空白を入れるか決めます。 result.Insert(0, (hasSpace ? "同 " : "同")); } else { if (style == MoveTextStyle.Simple) { result.Insert(0, IntConverter.Convert(NumberType.Normal, move.File)); result.Insert(1, IntConverter.Convert(NumberType.Normal, move.Rank)); } else { result.Insert(0, IntConverter.Convert(NumberType.Big, move.File)); result.Insert(1, IntConverter.Convert(NumberType.Kanji, move.Rank)); } } // 必要なら▲△を先頭に入れます。 if (style == MoveTextStyle.Normal) { result.Insert(0, ToString(move.BWType)); } if (move.SrcSquare != null && style == MoveTextStyle.KifFile) { result.AppendFormat("({0}{1})", move.SrcSquare.File, move.SrcSquare.Rank); } return(result.ToString()); }
/// <summary> /// 指し手を文字列に変換します。 /// </summary> /// <remarks> /// KifFileに使う指し手は同○○の場合、 /// 「同」と「○○」の間に空白を入れないと"kif for windows"では /// 正しく読み込めなくなります。 /// </remarks> public static string ToString(Move move, MoveTextStyle style = MoveTextStyle.Normal) { if (move == null) { return null; } if (move.IsSpecialMove) { var turnStr = string.Empty; // 必要なら▲△を先頭に入れます。 if (style == MoveTextStyle.Normal) { turnStr = ToString(move.BWType); } return (turnStr + EnumEx.GetLabel(move.SpecialMoveType)); } var result = new StringBuilder(); result.Append(ToString(move.Piece)); result.Append(ToString(move.RelFileType)); result.Append(ToString(move.RankMoveType)); result.Append(ToString(move.ActionType)); if (move.SameAsOld) { var hasSpace = ( (style != MoveTextStyle.Simple) && (result.Length == 1 || style == MoveTextStyle.KifFile)); // 文字数によって、同の後の空白を入れるか決めます。 result.Insert(0, (hasSpace ? "同 " : "同")); } else { if (style == MoveTextStyle.Simple) { result.Insert(0, IntConverter.Convert(NumberType.Normal, move.File)); result.Insert(1, IntConverter.Convert(NumberType.Normal, move.Rank)); } else { result.Insert(0, IntConverter.Convert(NumberType.Big, move.File)); result.Insert(1, IntConverter.Convert(NumberType.Kanji, move.Rank)); } } // 必要なら▲△を先頭に入れます。 if (style == MoveTextStyle.Normal) { result.Insert(0, ToString(move.BWType)); } if (move.SrcSquare != null && style == MoveTextStyle.KifFile) { result.AppendFormat("({0}{1})", move.SrcSquare.File, move.SrcSquare.Rank); } return result.ToString(); }