Skip to content

Commit

Permalink
add mistakenly ignored file
Browse files Browse the repository at this point in the history
  • Loading branch information
zdenecek committed Sep 5, 2023
1 parent a3dd11d commit 9f9bac3
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mono_crash.*

# Build results
[Dd]ebug/
!pbn/src/debug
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
Expand Down
69 changes: 69 additions & 0 deletions pbn/src/debug/DebugUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;
using System.IO;
using System.Linq;
using pbn.model;

namespace pbn.debug;

public static class DebugUtils
{
/// <summary>
/// Serializes a PbnFile to an output stream including token type names.
/// </summary>
/// <param name="file">File to serialize.</param>
/// <param name="outStream">Stream to serialize the file to.</param>
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++;
}
}

/// <summary>
/// Prints file BoardContext ranges to the stream.
/// </summary>
/// <param name="file">File to print BoardContext ranges from.</param>
/// <param name="outStream">Stream to print to.</param>
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<Position>())
{
outStream.Write($" {PositionHelpers.ToString(position)[0]}");

foreach (var suit in Enum.GetValues(typeof(Suit)).Cast<Suit>())
outStream.Write($"{table.GetDoubleDummyTricks(suit, position),4}");
outStream.WriteLine();
}
}


public static void Playground()
{
}
}

0 comments on commit 9f9bac3

Please sign in to comment.