diff --git a/.gitignore b/.gitignore index 76d2184..b4f5943 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ mono_crash.* # Build results [Dd]ebug/ +!pbn/src/debug [Dd]ebugPublic/ [Rr]elease/ [Rr]eleases/ diff --git a/pbn/src/debug/DebugUtils.cs b/pbn/src/debug/DebugUtils.cs new file mode 100644 index 0000000..e512daf --- /dev/null +++ b/pbn/src/debug/DebugUtils.cs @@ -0,0 +1,69 @@ +using System; +using System.IO; +using System.Linq; +using pbn.model; + +namespace pbn.debug; + +public static class DebugUtils +{ + /// + /// Serializes a PbnFile to an output stream including token type names. + /// + /// File to serialize. + /// Stream to serialize the file to. + public static void SerializePbnFile(PbnFile file, TextWriter outStream) + { + var i = 0; + foreach (var token in file.Tokens) + { + outStream.Write($"{i,4}"); + outStream.Write(": "); + outStream.Write($"{"<" + token.Typename + ">",-25}"); + + token.Serialize(outStream); + outStream.WriteLine(); + i++; + } + } + + /// + /// Prints file BoardContext ranges to the stream. + /// + /// File to print BoardContext ranges from. + /// Stream to print to. + public static void PrintBoardContextRanges(PbnFile file, TextWriter outStream) + { + Console.WriteLine("Board Contexts:"); + + foreach (var context in file.Boards) + { + outStream.Write("Board "); + outStream.Write(context.BoardNumber); + outStream.Write(": "); + + var range = context.TokenRange; + outStream.Write($"[{range.StartIndex}, {range.EndIndex}]"); + outStream.WriteLine(); + } + } + + + public static void PrintAnalysisTable(AnalysisTable table, TextWriter outStream) + { + outStream.WriteLine(" NT ♠ ♥ ♦ ♣"); + foreach (var position in Enum.GetValues(typeof(Position)).Cast()) + { + outStream.Write($" {PositionHelpers.ToString(position)[0]}"); + + foreach (var suit in Enum.GetValues(typeof(Suit)).Cast()) + outStream.Write($"{table.GetDoubleDummyTricks(suit, position),4}"); + outStream.WriteLine(); + } + } + + + public static void Playground() + { + } +} \ No newline at end of file