Recent

Author Topic: Pascal version of the UCI Filter program  (Read 4401 times)

Roland57

  • Sr. Member
  • ****
  • Posts: 488
    • msegui.net
Pascal version of the UCI Filter program
« on: October 11, 2024, 10:33:25 am »
Hello everybody.

I translated to Pascal the program UCI Filter. It's a program designed to be used as a filter between a UCI chess engine and a chess GUI.

The Pascal version doesn't work correctly. Would someone help me to find the error?

Here is how to compile and test the original program:

(You need to have make and fpc available on the command line.)

D:\c\echecs\ucifilter-pascal-241011>make
gcc -Wall ucifilter.c -o ucifilter.exe

D:\c\echecs\ucifilter-pascal-241011>make test
ucifilter .\CT800_V1.34_x32.exe
CT800 V1.34 32 bit UCI version
2016-2019 by Rasmus Althoff
Free software under GPLv3+
quit


Here is how to compile and test the Pascal version:

D:\c\echecs\ucifilter-pascal-241011>make ucifilterpas
fpc -Mobjfpc -Sh -dDEBUG ucifilter.pas -oucifilterpas.exe
Compiling Debug Version
Free Pascal Compiler version 3.2.0 [2021/02/21] for i386
Copyright (c) 1993-2020 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling ucifilter.pas
Compiling log.pas
Linking ucifilterpas.exe
524 lines compiled, 0.3 sec, 170256 bytes code, 6724 bytes data

D:\c\echecs\ucifilter-pascal-241011>make testpas
ucifilterpas .\CT800_V1.34_x32.exe
| a♠CT800 V1.34 32☻  | a♠►' £ a♠2016-2019 by R☻  | a♠╣ a♠Free software ☻  | aquit


You can see that the output of the UCI engine is corrupted.

Which error did I make?
My projects are on Gitlab and on Codeberg.

bobby100

  • Sr. Member
  • ****
  • Posts: 264
    • Malzilla
Re: Pascal version of the UCI Filter program
« Reply #1 on: October 11, 2024, 03:07:54 pm »
Are you sure about using ansichar and ansistring? To me, it looks like you are getting multibyte text, and the garbage comes from reading it as singlebyte (ansi) chars.

af0815

  • Hero Member
  • *****
  • Posts: 1381
Re: Pascal version of the UCI Filter program
« Reply #2 on: October 11, 2024, 03:17:40 pm »
Best way, write the original raw stringdata to a file and analyse this file. I have see this, if i read output from a Delphi programm (2 Byte Chars) and misinterpret this in my first try.
regards
Andreas

Roland57

  • Sr. Member
  • ****
  • Posts: 488
    • msegui.net
Re: Pascal version of the UCI Filter program
« Reply #3 on: October 16, 2024, 03:18:52 pm »
Are you sure about using ansichar and ansistring?

I think ansichar is the equivalent of the char type used in the C program. The ansistring type is used only for the executable path, and it seems to work (since the executable starts).

Code: Pascal  [Select][+][-]
  1. function EngineStarten(EnginePath: AnsiString): THandle; forward;
My projects are on Gitlab and on Codeberg.

Fred vS

  • Hero Member
  • *****
  • Posts: 3466
    • StrumPract is the musicians best friend
Re: Pascal version of the UCI Filter program
« Reply #4 on: October 16, 2024, 10:59:41 pm »
I think ansichar is the equivalent of the char type used in the C program. ;

There is also cchar from ctypes.pp.
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Thaddy

  • Hero Member
  • *****
  • Posts: 16419
  • Censorship about opinions does not belong here.
Re: Pascal version of the UCI Filter program
« Reply #5 on: October 17, 2024, 06:47:40 am »
The equivalent of a C char is usually a byte, not a Pascal char.
There is nothing wrong with being blunt. At a minimum it is also honest.

TRon

  • Hero Member
  • *****
  • Posts: 3822
Re: Pascal version of the UCI Filter program
« Reply #6 on: October 17, 2024, 07:19:39 am »
A byte is equivalent to a unsigned char.
I do not have to remember anything anymore thanks to total-recall.

Thaddy

  • Hero Member
  • *****
  • Posts: 16419
  • Censorship about opinions does not belong here.
Re: Pascal version of the UCI Filter program
« Reply #7 on: October 17, 2024, 07:54:45 am »
That is compiler dependant. You can only assume that the size is sizeof(byte). See remark in ctypes.
There is nothing wrong with being blunt. At a minimum it is also honest.

Roland57

  • Sr. Member
  • ****
  • Posts: 488
    • msegui.net
Re: Pascal version of the UCI Filter program
« Reply #8 on: October 17, 2024, 11:02:14 am »
Thank you all for your answers.

I wonder if my buffers are properly initialized, here :

Code: Pascal  [Select][+][-]
  1. procedure GuiNachEngine(pFilter: PFilterDaten);
  2. // ...
  3. begin
  4.   // ...
  5.  
  6.   lp.hDatei := pFilter^.hVonGui;
  7.   lp.Groesse := 10000;
  8.   lp.pPuffer := StrAlloc(lp.Groesse + 1);
  9.  
  10.   //FillChar(lp.pPuffer, lp.Groesse * SizeOf(ansichar), #0);
  11.   StrPCopy(lp.pPuffer, StringOfChar(#0, lp.Groesse));

And here :

Code: Pascal  [Select][+][-]
  1. function EngineNachGui(pParam: Pointer): DWORD; stdcall;
  2. // ...
  3. begin
  4.   // ...
  5.  
  6.   pFilter := PFilterDaten(pParam);
  7.  
  8.   lp.hDatei := pFilter^.hVonEngine;
  9.   lp.Groesse := 10000;
  10.   lp.pPuffer := StrAlloc(lp.Groesse + 1);
  11.  
  12.   //FillChar(lp.pPuffer, lp.Groesse * SizeOf(ansichar), #0);
  13.   StrPCopy(lp.pPuffer, StringOfChar(#0, lp.Groesse));
My projects are on Gitlab and on Codeberg.

TRon

  • Hero Member
  • *****
  • Posts: 3822
Re: Pascal version of the UCI Filter program
« Reply #9 on: October 17, 2024, 12:07:27 pm »
Is the text output from the server still garbled ? or does the engine not respond ?

What platform is the engine running on, and what platform the client ? (the UCI documentation mentions some specifics)
« Last Edit: October 17, 2024, 12:09:24 pm by TRon »
I do not have to remember anything anymore thanks to total-recall.

Thaddy

  • Hero Member
  • *****
  • Posts: 16419
  • Censorship about opinions does not belong here.
Re: Pascal version of the UCI Filter program
« Reply #10 on: October 17, 2024, 12:24:50 pm »
Sigh, use AllocMem when translatinng C code.
There is nothing wrong with being blunt. At a minimum it is also honest.

Roland57

  • Sr. Member
  • ****
  • Posts: 488
    • msegui.net
Re: Pascal version of the UCI Filter program
« Reply #11 on: October 17, 2024, 03:11:24 pm »
Is the text output from the server still garbled ? or does the engine not respond ?

What platform is the engine running on, and what platform the client ?

The engine responds but the output of the filter is corrupted. The filter uses Windows API. Please see my first post.

Sigh, use AllocMem when translating C code.

Thanks, I will try.
My projects are on Gitlab and on Codeberg.

TRon

  • Hero Member
  • *****
  • Posts: 3822
Re: Pascal version of the UCI Filter program
« Reply #12 on: October 17, 2024, 03:16:10 pm »
The engine responds but the output of the filter is corrupted. The filter uses Windows API. Please see my first post.
"\n" means #13#10 on/for windows (as expressed in the UCI specifications)
I do not have to remember anything anymore thanks to total-recall.

Roland57

  • Sr. Member
  • ****
  • Posts: 488
    • msegui.net
Re: Pascal version of the UCI Filter program
« Reply #13 on: October 17, 2024, 03:33:20 pm »
AllocMem works, but doesn't solve the issue.

@TRon
Thanks, but I don't think that this be the issue.
My projects are on Gitlab and on Codeberg.

TRon

  • Hero Member
  • *****
  • Posts: 3822
Re: Pascal version of the UCI Filter program
« Reply #14 on: October 17, 2024, 03:41:48 pm »
@Roland:
Then don't be surprised if the output isn't as expected. The c-code seems to follow the convention, the translation doesn't.

There is very little specifications written down, so I would personally stick to what actually is available.
I do not have to remember anything anymore thanks to total-recall.

 

TinyPortal © 2005-2018