Need help on getting my chess-engine winboard compatible

Programming Topics (Computer Chess) and technical aspects as test techniques, book building, program tuning etc

Moderator: Andres Valverde

Need help on getting my chess-engine winboard compatible

Postby jacobbl » 13 Jun 2008, 22:08

Hi, I've made an OK chess program (ELO about 2000), but I'd like to make it winboard compatible.

I've been programming in Visual Basic 2008 Express.

Can anyone please help me with the commands in Visual Basic that allows me to read and write to the standard input/output? An example on would be very nice.

Does anyone know what speed gain I could expect to get by converting the program to C?

Regards
Jacob
jacobbl
 
Posts: 5
Joined: 13 Jun 2008, 21:57

Re: Need help on getting my chess-engine winboard compatible

Postby Dann Corbit » 14 Jun 2008, 00:23

Here is VB 6 source code for a chess program called LarsenVB:
http://xoomer.alice.it/ludormio/download/lvbsource.zip

Converting to C will give you 2-4x speed increase (1-2 ply more at best).
Unless you are fluent in C, I would not bother.
Dann Corbit
 

Re: Need help on getting my chess-engine winboard compatible

Postby Dann Corbit » 14 Jun 2008, 01:04

I think that this is the bit that you need (I made some changes so that it will work in VB.NET for you):
Code: Select all
Option Strict Off
Option Explicit On
Module IOBas
   
   '==================================================
   'IOBas:
   '
    'Method of communication with  Winboard
   '==================================================
   
   Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Integer) As Integer
   Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Integer) As Integer
    Declare Function PeekNamedPipe Lib "kernel32" (ByVal hNamedPipe As Integer, ByRef lpBuffer As String, ByVal nBufferSize As Integer, ByRef lpBytesRead As Integer, ByRef lpTotalBytesAvail As Integer, ByRef lpBytesLeftThisMessage As Integer) As Integer
    Declare Function ReadFile Lib "kernel32" (ByVal hFile As Integer, ByRef lpBuffer As String, ByVal nNumberOfBytesToRead As Integer, ByRef lpNumberOfBytesRead As Integer, ByRef lpOverlapped As Integer) As Integer
    Declare Function WriteFile Lib "kernel32" (ByVal hFile As Integer, ByVal lpBuffer As String, ByVal nNumberOfBytesToWrite As Integer, ByRef lpNumberOfBytesWritten As Integer, ByRef lpOverlapped As Integer) As Integer
   
   Public hStdIn As Integer ' handle dello Standard Input
   Public hStdOut As Integer ' handle dello Standard Output
   '---------------------------------------------------------------------------
    'PollCommand() - It checks for the presence of data in the standard input buffer
   '
    'it returns TRUE if characters are available
   '---------------------------------------------------------------------------
   Function PollCommand() As Boolean
      
#If DEBUGMODE Then
      PollCommand = FakeInputState
#Else
      Dim sBuff As String
      Dim lBytesRead As Integer
      Dim lTotalBytes As Integer
      Dim lAvailBytes As Integer
      Dim rc As Integer
      
      sBuff = New String(Chr(0), 2048)
      rc = PeekNamedPipe(hStdIn, sBuff, 2048, lBytesRead, lTotalBytes, lAvailBytes)
      
      PollCommand = CBool(rc And lBytesRead > 0)
#End If
      
   End Function
   '---------------------------------------------------------------------------
    'ReadCommand() - collect strings from standard input
   '---------------------------------------------------------------------------
   Function ReadCommand() As String
      
#If DEBUGMODE Then
      ReadCommand = FakeInput
      FakeInputState = False
      FakeInput = ""
#Else
      Dim sBuff As String
      Dim lBytesRead As Integer
      Dim rc As Integer
      
      sBuff = New String(Chr(0), 2048)
      rc = ReadFile(hStdIn, sBuff, 2048, lBytesRead, 0)
        'ToDo: handles errors if rc=0
      ReadCommand = Left(sBuff, lBytesRead)
#End If
      
   End Function
   
   '---------------------------------------------------------------------------
    'SendCommand() - sends a string to standard output
   '
    'it effectively returns the sent string (comprised the LineFeeds)
   '---------------------------------------------------------------------------
   Function SendCommand(ByVal sCommand As String) As String
      
#If DEBUGMODE Then
      With frmDebugMain
      If Len(.txtIO) > 32000 Then .txtIO = ""
      .txtIO = .txtIO & vbCrLf & sCommand
      .txtIO.SelStart = Len(.txtIO)
      .txtIO.SelLength = 0
      .Refresh
      End With
#Else
      Dim lBytesWritten As Integer
      Dim lBytes As Integer
      Dim rc As Integer
      
        'according to the documentation of WinBoard a LineFeed Before the command would not have to be sent,
        'however, without that WinBoard reads alone before the string that we send and then stops to answer.
        'Probably something escapes to me in a documentation of WriteFile and the management of strings in VB;
        'however this " patch" it seems to make it work and does not seem to annoy WinBoard. Fix for DDInterfaceEngine:
        'it continues to receive characters in input but at least they are separated from the corrected commands
        sCommand = vbCrLf & sCommand & vbCrLf

        lBytes = sCommand.Length

      rc = WriteFile(hStdOut, sCommand, lBytes, lBytesWritten, 0)
        'ToDo: handle errors if rc=0
#End If
      SendCommand = sCommand
      
   End Function
End Module
Dann Corbit
 

Re: Need help on getting my chess-engine winboard compatible

Postby jacobbl » 14 Jun 2008, 08:27

Thank's a lot.

Jacob
jacobbl
 
Posts: 5
Joined: 13 Jun 2008, 21:57


Return to Programming and Technical Discussions

Who is online

Users browsing this forum: No registered users and 41 guests