Using Windows UCI engines with HIARCS Mac Chess Explorer

You can discuss all aspects of programming and technical matters here.

Moderators: Harvey Williamson, Watchman

User avatar
Hasimir
Member
Posts: 62
Joined: Sun Jun 29, 2014 1:24 pm
Location: Australia
Contact:

Re: Using Windows UCI engines with HIARCS Mac Chess Explorer

Post by Hasimir »

h.g.muller wrote:If you would let your wrapper read the string it feeds to system() from a file with a fixed name (say wrapper.ini) in the current directory, people could use it without comiling anything. They would only have to prepare an ini file with the wine command in it. Of course you could have the wrapper also supply the path to wine by itself and just read the path to the engine from the file. Or, to accomodate even more lazy users, let it construct the engine path from the current directory and the .exe name read from the wrapper.ini file.
Okay, here's roughly how it's done in Python:

Code: Select all

#!/usr/bin/env python

# Run this in the directory with the Win32 UCI .exe or a parent
# directory of it.
#
# Command&#58; uciloader&#91;.py&#93; <win32_uci_exe_filename>

from distutils.spawn import find_executable
import os
import os.path
import subprocess
import sys

name = sys.argv&#91;1&#93;
curdir = os.path.abspath&#40;"."&#41;

winexec = find_executable&#40;"wine"&#41;
winepath = os.path.abspath&#40;winexec&#41;

def uciengine&#40;name, curdir&#41;&#58;
    for root, dirs, files in os.walk&#40;curdir&#41;&#58;
        if name in files&#58;
            return os.path.join&#40;root, name&#41;

# Need to update this to use subprocess instead of os.system&#58;

os.system&#40;"&#123;0&#125; &#123;1&#125;".format&#40;winepath, uciengine&#40;name, curdir&#41;&#41;&#41;
There's no wrapper file there, instead it takes the name of the engine on the command line. When I remember how I last converted Python to C I'll add bits to take all this info, generate the C code on the fly and compile it. When that's done it should work for any platform with Python and a C compiler.
Website: Organised Adversary - ICCF: 30667
OpenPGP/GPG Key: 0x321E4E2373590E5D - BTC address: 18Ua6y7D65QatEDZ36dtWNWpG9Ttrd4eqy
h.g.muller
Member
Posts: 32
Joined: Fri Jan 09, 2009 11:14 am
Location: Amsterdam

Re: Using Windows UCI engines with HIARCS Mac Chess Explorer

Post by h.g.muller »

Hasimir wrote:Unfortunately that sample code there didn't compile for me, ...
I admit I did not test it. This one compiles for me on Linux with gcc. (It is C, not C++). I get a warning on get_current_dir_name(), though, like I did not #include the right header to declare it. The manual says it should be in unistd.h...

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
 
int main&#40;&#41;
&#123;
  FILE *f = fopen&#40;"wrapper.ini", "r"&#41;;
  char buf&#91;1024&#93;, exe_name&#91;1024&#93;;
  if&#40;!f&#41; return -1;
  fscanf&#40;f, "%&#91;^\n&#93;", exe_name&#41;; fclose&#40;f&#41;;
  snprintf&#40;buf, 1024, "/opt/local/bin/wine %s/%s", get_current_dir_name&#40;&#41;, exe_name&#41;;
  system&#40;buf&#41;;
  return 0;
&#125;
User avatar
Hasimir
Member
Posts: 62
Joined: Sun Jun 29, 2014 1:24 pm
Location: Australia
Contact:

Re: Using Windows UCI engines with HIARCS Mac Chess Explorer

Post by Hasimir »

h.g.muller wrote:
Hasimir wrote:Unfortunately that sample code there didn't compile for me, ...
I admit I did not test it. This one compiles for me on Linux with gcc. (It is C, not C++). I get a warning on get_current_dir_name(), though, like I did not #include the right header to declare it. The manual says it should be in unistd.h...

Code: Select all

#include <stdio>
#include <stdlib>
#include <unistd>
 
int main&#40;&#41;
&#123;
  FILE *f = fopen&#40;"wrapper.ini", "r"&#41;;
  char buf&#91;1024&#93;, exe_name&#91;1024&#93;;
  if&#40;!f&#41; return -1;
  fscanf&#40;f, "%&#91;^\n&#93;", exe_name&#41;; fclose&#40;f&#41;;
  snprintf&#40;buf, 1024, "/opt/local/bin/wine %s/%s", get_current_dir_name&#40;&#41;, exe_name&#41;;
  system&#40;buf&#41;;
  return 0;
&#125;
Yeah, that one compiles for me on a Slackware VM, but OS X hates it to the tune of:

Code: Select all

bash-3.2$ gcc uciloader.c -o uciloader
uciloader.c&#58;11&#58;52&#58; warning&#58; implicit declaration of function
      'get_current_dir_name' is invalid in C99 &#91;-Wimplicit-function-declaration&#93;
  snprintf&#40;buf, 1024, "/opt/local/bin/wine %s/%s", get_current_dir_name&#40;...
                                                   ^
/usr/include/secure/_stdio.h&#58;57&#58;62&#58; note&#58; expanded from macro 'snprintf'
  __builtin___snprintf_chk &#40;str, len, 0, __darwin_obsz&#40;str&#41;, __VA_ARGS__&#41;
                                                             ^
uciloader.c&#58;11&#58;52&#58; warning&#58; format specifies type 'char *' but the argument has
      type 'int' &#91;-Wformat&#93;
  ...1024, "/opt/local/bin/wine %s/%s", get_current_dir_name&#40;&#41;, exe_name&#41;;
                                ~~      ^~~~~~~~~~~~~~~~~~~~~~
                                %d
/usr/include/secure/_stdio.h&#58;57&#58;62&#58; note&#58; expanded from macro 'snprintf'
  __builtin___snprintf_chk &#40;str, len, 0, __darwin_obsz&#40;str&#41;, __VA_ARGS__&#41;
                                                             ^
2 warnings generated.
Undefined symbols for architecture x86_64&#58;
  "_get_current_dir_name", referenced from&#58;
      _main in uciloader-51d8f3.o
ld&#58; symbol&#40;s&#41; not found for architecture x86_64
clang&#58; error&#58; linker command failed with exit code 1 &#40;use -v to see invocation&#41;
bash-3.2$ 
Yes, I've got XCode and all the libs (I semi-regularly customise and compile my own copies of little things like GPG, OpenSSL and Tor).

Still, it's part of the way there and I'm all for solutions to help Linux along the way. ;)
Website: Organised Adversary - ICCF: 30667
OpenPGP/GPG Key: 0x321E4E2373590E5D - BTC address: 18Ua6y7D65QatEDZ36dtWNWpG9Ttrd4eqy
User avatar
SedarPL
Member
Posts: 69
Joined: Wed Mar 15, 2017 3:17 pm
Location: Poland
Contact:

Re: Using Windows UCI engines with HIARCS Mac Chess Explorer

Post by SedarPL »

Refreshing :D

I invite you to read the article: https://bit.ly/3Txi04s

ps.
I would like to take this opportunity to wholeheartedly thank user Hasimir, whose 2014 forum post inspired me to take action to use Windows chess engines on a Mac. Admittedly, in his post Hasimir focused on 32-bit engines, however the idea of using 64-bit engines on modern Macs - has not significant changed. Thanks!
Regards, Darius
https://chessengeria.eu
Josef
Member
Posts: 178
Joined: Mon Dec 12, 2016 12:56 pm

Re: Using Windows UCI engines with HIARCS Mac Chess Explorer

Post by Josef »

Since I sometimes need a Windows program on my Mac OS, I decided to buy Parallel Desktop, which also solves this problem.
Post Reply