コード例 #1
0
 /// <summary>
 /// Convert a battleship board into a compact string
 /// </summary>
 /// <param name="board">Board to convert</param>
 /// <returns>
 /// String in which each letter represents one board sqare.
 /// </returns>
 public static string ToShortString(this IReadOnlyBoard board) =>
 string.Create(100, board, (buf, content) =>
 {
     for (var i = 0; i < 100; i++)
     {
         buf[i] = BoardContentJsonConverter.SquareContentToChar(content[new BoardIndex(i)]);
     }
 });
コード例 #2
0
 internal static string SerializeLog(IEnumerable <SinglePlayerGameLogRecord> log)
 {
     return(string.Create(log.Count() * 3, log, (buf, log) =>
     {
         foreach (var item in log)
         {
             item.Location.Column.TryFormat(buf, out var _);
             item.Location.Row.TryFormat(buf[1..], out var _);
             buf[2] = BoardContentJsonConverter.SquareContentToChar(item.ShotResult);
             buf = buf[3..];