kervinck / chessmoves

Python C extension for chess move and position generation (SAN/FEN/UCI)
BSD 3-Clause "New" or "Revised" License
8 stars 3 forks source link

How to run as .sh script? #6

Closed appletomato closed 4 years ago

appletomato commented 4 years ago

Hi, thank you for your project!

`Chessmoves' is a small module to make fast chess tree traversal available in a scripting environment, such as Python or sh.

I have figured out how to use chessmoves in a python script after running make, but could you please provide instructions on how to run it as a (standalone) shell/bash -script?

What I have tried so far:

  1. Compile from source:

    $ g++ Source/chessmovesmodule.c 
    clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
    Source/chessmovesmodule.c:46:10: fatal error: 'Python.h' file not found
  2. Running make and then compile the .so from the build-directory:

    $ g++ -o chessmoves build/lib.macosx-10.11-x86_64-2.7/chessmoves.so 
    ld: can't link with bundle (MH_BUNDLE) only dylibs (MH_DYLIB) file 'build/lib.macosx-10.11-x86_64-2.7/chessmoves.so'
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

Somehow I am stuck at the moment and cannot figure out what the above error messages are trying to tell me. Thank you for your help!

kervinck commented 4 years ago

There is an example in the repository: Tools/run-perft

I don't know what the messages you give mean. Just typed 'make' and 'make test' and it still works.

kervinck commented 4 years ago

Ah wait, in an earlier edition there was also a standalone executable. But I removed it:

Author: Marcel van Kervinck marcelk@bitpit.net Date: Sat Aug 22 10:58:22 2015 +0200

Remove the cli tool. This is now just a python extension module.
appletomato commented 4 years ago

Thank you for your answer! The quoted example executes python through a bash pipe:

<some cmd> | time python Tools/perft.py

I was wondering if it was possible to run your module directly without python, reducing the computational overhead on startup.

In my use case I am reading a pgn-file from disc and would send the parsed moves to your module in order to get the FEN after each move. Currently I am doing this with JavaScript/chess.js and for a large pgn-file extracting the FENs takes about ~2s for a fairly big pgn-file with a lot of (sub-) variations. I want to make the FEN-processing as fast as possible but I am not sure if it is feasible if I have to tell JavaScript to execute a bash command which executes a python script which executes a C function, if you understand what I mean ...

kervinck commented 4 years ago

I think I removed it because the overhead of the C executable was larger than running it through Python.

kervinck commented 4 years ago

The Python module is able to process streams of positions. The CLI tool could only handle one for each call. Something like that.

appletomato commented 4 years ago

The Python module is able to process streams of positions.

This seems the way to go. I have played around with the provided test.py script and was able to parse 1000 positions in less than 100ms. This is the kind of speedup I was looking for. Thank you for your help and quick response!

kervinck commented 4 years ago

Great to know!