Chess engine configuration

Jun 30, 2009 at 10:28 PM

Hello Gregory,

Could you solve the configuration of the Winboard chess engine Crafty
or the UCI chess engine Rybka with CafeChess 1340 01/01/09?

Context: Visual C# 2008 Express Edition SP1 .NET 3.5 Windows Vista.
Usage: In "Engine/Parsing" tab, click to "Engine Command" push button.

Issue: A first chance exception of type 'System.Configuration.ConfigurationErrorsException' occurred in Cafechess.Chess.dll
Warning 1000: Cannot load XML config of chess engine
Inner exception: Sections must only appear once per config file.


[Cafechess.Control.Chessboard.Demo] ChessDisplay.cs
Below: using Cafechess.Chess.Engines.UCI;
I added:

using System.Diagnostics; // for debugging purpose


[...]

//ChessEngines engineConfig;
    ChessEngines engineConfig = null; // Nimmzo
    /// <summary>Display in the output the Exception info </summary>
    /// <param name="ex">the exception</param>
    /// <param name="msg">the warning message</param>
    public void DebugException(Exception except, string msg)
    {
        Debug.WriteLine(msg);
        if (null != except.InnerException)
        {
            Debug.WriteLine("Inner exception: " + except.InnerException);
        }
        Debug.WriteLine("Message: " + except.Message);
        Debug.WriteLine("Type: " + except.GetType().FullName);
        Debug.WriteLine("Source: " + except.Source);
        Debug.WriteLine("Stack: " + except.StackTrace);
        Debug.WriteLine("TargetSite: " + except.TargetSite.ToString());
    } // end DebugException
    private void btnSubmitCommand_Click(object sender, System.EventArgs e)
    {
      if (engineConfig == null)
      {        
        //Cafechess.Chess.Engines.
        //ChessEngines allEngines = Factory.LoadConfig(@"C:\Source\NET\LIB\Cafechess\src\Cafechess.Chess\Engines\ChessEngines.xml");
          try
          {
              //engineConfig = Cafechess.Chess.Engines.Factory.LoadConfig(@"C:\Source\NET\LIB\Cafechess\src\Cafechess.Chess\Engines\ChessEngines.xml");
              engineConfig = Cafechess.Chess.Engines.Factory.LoadConfig(@"C:\Users\Chess\Documents\C#\CafeChess\src\Cafechess.Chess\Engines\ChessEngines.xml"); // Nimmzo
          }
          catch (Exception except)
          {
              DebugException(except, "Warning 1000: Cannot load XML config of chess engine"); // Nimmzo
          }

It is not a problem of hard coded path in ChessEngines.xml.

In catch, instead of eating the exception in the Chess Control Library,
I preferred to add: "throw" to catch the exception in the main program of Demo.

[Cafechess.Chess.Engines] Factory.cs

try
      {
          XmlSerializer serializer = new XmlSerializer(typeof(ChessEngines));
          reader = new StreamReader(filename);
          chessInterface = (ChessEngines)serializer.Deserialize(reader);
      }
      //catch (Exception myException)
      //{
      //  myException.ToString();
      //}
      catch
      {
          throw; // Nimmzo
      }

Without reaching the reading of the XML stream,
the new XmlSerializer(typeof(ChessEngines)) fails
because there is potentially a chess engine multi section in [Demo] App.config

<ChessEngineInterface>
    <EngineName value="Crafty 19.1"/>
    <Interface value="xboard"/>
    <Executable value="C:\Source.Cafe\Cafechess\examples\ChessboardDemo\engines\crafty-19-17FEN.exe">

[...]

<ChessEngineInterface>
    <EngineName value="Sjeng"/>
    <Interface value="uci"/>
    <Executable value="C:\Source\NET\LIB\Cafechess\examples\ChessboardDemo\Engines.UCI\Sjeng\Sjeng.exe">

Why does App.config need to configure the chess engines
while Factory dynamically loads ChessEngines.xml?
How to solve the inner exception: "Sections must only appear once per config file"?


About the name of the Chess protocol for Windows, I suggest replacing "xboard" with "winboard".
Would you add in all C# source code: using System.Diagnostics; // for debugging purpose

In the ComboBox EngineCommands, there are the items in the following order:
STOP
START
ANALYZE
STOPANALYSIS
SETBOARD

It could be easier to have START in first position:
START ENGINE
START ANALYSIS
STOP ANALYSIS
STOP ENGINE
SET BOARD

Yours truly,
Nimmzo