GithubHelp home page GithubHelp logo

Comments (5)

kieferro avatar kieferro commented on May 22, 2024 1

I would also like to have an error message for invalid FENs that can be caught.
I think a change to the _read_line-function like this would work:

def _read_line(self) -> str:
    if not self._stockfish.stdout:
        raise BrokenPipeError()
    if self._stockfish.poll() is not None:
        raise ValueError(
            "Stockfish has crashed. This was probably caused by an invalid FEN."
        )
    return self._stockfish.stdout.readline().strip()

What do you think @zhelyabuzhsky? I could add that, some checks with invalid FENs and an entry in the README and then open a PR if you want this feature to be included.

from stockfish.

johndoknjas avatar johndoknjas commented on May 22, 2024 1

@kieferro I think that would be good to include. An invalid FEN can cause SF to either crash, or return (none) for the best move (in both cases, after giving it the "go" command). It looks like your code handles the first case. I found some code online which should be able to help out with detecting fens causing this case as well. I'm also writing some stuff for fens causing the second case. Our branches shouldn't conflict since we're dealing with different functions.

from stockfish.

kieferro avatar kieferro commented on May 22, 2024 1

@johndoknjas Yes, that makes sense. Thank you

from stockfish.

kieferro avatar kieferro commented on May 22, 2024

@johndoknjas Okay, I've already included my code and a unittest on my fork. Feel free to take care of the second case. As long as both cases return the same kind of error, everything should be fine.
Do you want me to make the change to the README as well? I would just add a section and write that when an invalid FEN is entered, a ValueError with the text "Stockfish has crashed. This was probably caused by an invalid FEN." gets raised and maybe explain how to catch it. Does this fit with what you are planning on doing?

Edit: Now that I think about it, it probably does make sense to have two different error messages. If I understand correctly, then after the check you are dealing with, it is certain that the FEN is invalid. However, I only check if the process has been terminated, which also happens, for example, if someone kills the process. Therefore it would probably make sense to at least formulate the text differently. What are your thoughts?

from stockfish.

johndoknjas avatar johndoknjas commented on May 22, 2024

@kieferro I think your error message makes sense, since the process just stopping has a good chance of being caused by a bad FEN. Although in the readme, you could say that it's not guaranteed invalid FENs will cause a crash. The stuff I'm doing more or less tries to deal with these kinds of FENs. So I think what you have fits with my code, and updating the readme is fine. My PR will involve some stuff other than fen validation, so I'll probably wait until yours is merged into master first. As far as error messages go, right now my plan for my function is to just return a bool instead, and then say in the readme that the user can call this function to test their FEN. For your code though, returning an error should be done, since generally if read_line is called, errors aren't the expected behaviour.

from stockfish.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.