From 7d3846b2f94e42609a2cf900d7f9fcbe289c0cfe Mon Sep 17 00:00:00 2001 From: "Stanislav Ch. Nikolov" Date: Wed, 9 Aug 2023 23:24:11 +0200 Subject: [PATCH] Make Console.WriteLine not work in Think() --- bot-scaffold/Main.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/bot-scaffold/Main.cs b/bot-scaffold/Main.cs index 7efb404..151727e 100644 --- a/bot-scaffold/Main.cs +++ b/bot-scaffold/Main.cs @@ -1,4 +1,10 @@ -MyBot bot = new MyBot(); +// Disable console output. Some competitors use stdout for debugging info, which confuses the +// backend. +var nullWriter = new StreamWriter(Stream.Null); +var savedStdoutWriter = Console.Out; +Console.SetOut(nullWriter); + +MyBot bot = new MyBot(); while (true) { @@ -17,5 +23,8 @@ // Think and write move to stdout. ChessChallenge.API.Move move = bot.Think(apiBoard, apiTimer); + + Console.SetOut(savedStdoutWriter); Console.WriteLine($"{move}"); -} \ No newline at end of file + Console.SetOut(nullWriter); +}