Comments (5)
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.
@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.
@johndoknjas Yes, that makes sense. Thank you
from stockfish.
@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.
@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)
- Option to get board visual from either side HOT 2
- FR - Include chess notation entry HOT 2
- FR - Translate move string to human readable description of the move HOT 1
- top_moves returning empty list stockfish 15 HOT 2
- Improving some small things about self.depth HOT 1
- Stockfish 15 Errors on Linux HOT 4
- could use help implementing this HOT 2
- Jupyter Notebook HOT 2
- Improve the is_fen_valid function HOT 1
- Get best move from current position HOT 1
- Compatibility with chess library HOT 2
- [Meta] The future of this project (Please read this before opening new issues or PRs)
- can't use stockfish_mv in google colab HOT 1
- get_evaluation() implemented wrong HOT 2
- Error in stockfish\models.py in __del__, _put HOT 2
- does_current_engine_version_have_wdl_option() not work on stockfish variant
- stockfish derivatives not work when analyze pgn HOT 16
- take longer time compare with chess module HOT 5
- will_move_be_a_capture throws exeption when converting pawn
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stockfish.