Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jan 27 16:42
    fantomechess commented #953
  • Jan 27 16:37
    fantomechess commented #953
  • Jan 27 14:42
    mratanusarkar commented #953
  • Jan 26 17:42
    niklasf commented #954
  • Jan 26 17:42

    niklasf on master

    Update cp multiplier to match L… Merge pull request #954 from ja… (compare)

  • Jan 26 17:42
    niklasf closed #954
  • Jan 26 17:35
    jacksonthall22 opened #954
  • Jan 26 17:20
    fantomechess commented #953
  • Jan 26 17:20
    fantomechess commented #953
  • Jan 26 17:13
    fantomechess commented #953
  • Jan 26 16:59
    fantomechess commented #953
  • Jan 26 16:57
    fantomechess commented #953
  • Jan 26 16:52
    mratanusarkar commented #953
  • Jan 26 16:48
    fantomechess commented #953
  • Jan 26 16:45
    fantomechess commented #953
  • Jan 26 16:30
    mratanusarkar commented #953
  • Jan 26 16:28
    mratanusarkar commented #953
  • Jan 26 16:26
    mratanusarkar commented #953
  • Jan 26 16:22
    mratanusarkar commented #953
Gandalf Sax Guy
@galacticue06
stockfish
stockfish 13
I tried to find subprocess.call in engine.py to add a startup flag but couldn't find
Niklas Fiekas
@niklasf
any additional keyword arguments like popen_uci(..., startupinfo=..., creationflags=...)are passed along to subprocess.Popen
Gandalf Sax Guy
@galacticue06
oh thanks
that worked
thanks a lot
Niklas Fiekas
@niklasf
still a bit strange, but glad it works like that, at least
Ghost
@ghost~58c242a5d73408ce4f4f9df5
@niklasf, what is the recommended way to manipulate the SVG data in chess.svg module? I know that the chess.svg module returns an SvgWrapper type (str type). How can I manipulate that data? Actually, how can I even pull that data out of SvgWrapper? I want to reference pieces by their id tags for drag&drop. Any examples would be very beneficial, because this isn't documented anywhere. Thanks.
Niklas Fiekas
@niklasf
it is basically really nothing but a string. so the only reliable way would be to parse it again, for example https://docs.python.org/3/library/xml.etree.elementtree.html#parsing-xml
Ghost
@ghost~58c242a5d73408ce4f4f9df5
Another question, @niklasf. When would one need the apply_transform() method of chess.Board? What purpose does it serve? Why is it there? It's not documented, so please explain.
Niklas Fiekas
@niklasf
see https://python-chess.readthedocs.io/en/latest/core.html#chess.Board.transform. it's exactly liketransform(), except that it modifies the existing board instead of creating a new one
Niklas Witzig
@nmwitzig
Hi all, I am currently trying to configure a Stockfish engine using python chess to evaluate many games. I noticed that on our university's cluster, even though I am configuring the Engine to use multiple cores using engine = chess.engine.SimpleEngine.popen_uci("/...bin/stockfish") and engine.configure({"Threads": NCPUS}), the script only uses a single core. Is there a limit on the number of threads?
Niklas Fiekas
@niklasf
@nmwitzig mhh ... no. that should definitely work. maybe the cluster has some quota?
16 replies
Ghost
@ghost~58c242a5d73408ce4f4f9df5
@niklasf, I found out that xlink:href is deprecated in favor of href, so the xlink namespace is not needed. This applies to the chess.svg module where in the <use> tags you reference chess pieces via xlink:href. Please remove the xlink namespace in the generated SVG code and fix xlink:href to just href.
Ghost
@ghost~58c242a5d73408ce4f4f9df5
I would create a pull request, but I am banned from doing so. Anyway, in svg.py, remove line 170 completely, in line 378 fix "xlink:href" to "href" and also fix "xlink:href" to "href" in line 385.
Niklas Fiekas
@niklasf
the output should be svg tiny 1.2 compatible, so deprecations from svg 2 don't apply, yet
Niklas Fiekas
@niklasf
i guess we can have both, according to https://www.w3.org/TR/SVG2/linking.html#XLinkRefAttrs
Ghost
@ghost~58c242a5d73408ce4f4f9df5
Very good! Thanks for the patch. This means python-chess now conforms to SVG Tiny 1.2 AND SVG 2.0 standards. That's a very welcome change.
Ghost
@ghost~58c242a5d73408ce4f4f9df5

@niklasf, please fix the alignment of white and black pawns, because their offset from the center of a square on the x axis is exactly 0.5 pixels to the left.

I have fixed this by editing the translate() data of an already generated SVG and added 0.5 pixels to the x attribute.

<use href="#white-pawn" transform="translate(15, 285)"/>
was fixed to

<use href="#white-pawn" transform="translate(15.5, 285)"/>

Ghost
@ghost~58c242a5d73408ce4f4f9df5
I don't know what exactly to fix in svg.py so that pawns (white and black) are correctly centered in the square. I don't know whether SVG path data needs to be fixed or the formula for the x and y (svg.py, lines 371 & 372).
Ghost
@ghost~58c242a5d73408ce4f4f9df5
image.png
Ghost
@ghost~58c242a5d73408ce4f4f9df5
As you can see from the screenshot image above, blue dots mark legal chess moves for the knight on f6. Notice the blue dot on the white pawn on e4. You can clearly see (well, if you look closely) that the white pawn is off center. The position of the circle is x=22.5 and y=22.5 which is the center of a square (which defaults to 45). I have monkey-patched the chess.svg.XX attribute to have this value: "<g id="xx"><circle r="5.0" cx="22.5" cy="22.5" fill="#0000ff"></circle></g>"
Ghost
@ghost~58c242a5d73408ce4f4f9df5
@niklasf, line 169 in svg.py is "version": "1.1". Shouldn't that be "version": "1.2", since the SVG documentation in the SVG rendering section says "The chess.svg module renders SVG Tiny 1.2 images"?
Niklas Fiekas
@niklasf
done via niklasf/python-chess@e7d07fd. i'll check out the pawn positions soonish
Niklas Fiekas
@niklasf
and pawns done via niklasf/python-chess@1d52ea6
Ghost
@ghost~58c242a5d73408ce4f4f9df5
Amazing work, @niklasf! Can you push a new version? Please?
Ghost
@ghost~58c242a5d73408ce4f4f9df5
The changes since v1.5.0 deserve a v1.5.1 version. Do you agree?
Also, GitHub changed the name of the 'master' branch to be named 'main' now. Can we accomodate that change?
Ghost
@ghost~58c242a5d73408ce4f4f9df5
@niklasf, thanks for v1.6.0!
Ghost
@ghost~58c242a5d73408ce4f4f9df5
@niklasf, are you willing to implement a way for us to inject JavaScript into the generated SVG? Just like there's a style argument in chess.svg.board(), it would be beneficial to have a script argument as well. If you unban me, I can make a PR.
Niklas Fiekas
@niklasf
no, but you can use an xml.etree or so to insert custom elements
Ghost
@ghost~58c242a5d73408ce4f4f9df5
I don't understand how should I even go and start manipulating your SVG document (chess.svg). I would like to add event listeners to your svg so that some drag & drop functionality can be implemented. Is that even possible? If yes, PLEASE GIVE AN EXAMPLE.
Niklas Fiekas
@niklasf
no, i told you multiple times it's not meant to do that, and this will be the last time
Ghost
@ghost~58c242a5d73408ce4f4f9df5
I have a question. Is it by design (and normal?) that a chess engine also returns its played move in the principal variation info list (i.e., in the result.info["pv"] list of chess.Move objects)? So, from the initial position of Standard Chess, if White plays 1.e4 and an engine responds with 1...e6, the result.info["pv"] list of chess.Move objects is then [chess.Move.from_uci("e7e6"), ..., ...]. Is it possible that it only outputs principal variation moves AFTER its own move in the principal variation info list (so, basically, from the pondermove onwards [hence, truncating its own played move])?
1 reply
Ghost
@ghost~58c242a5d73408ce4f4f9df5

@niklasf, there's a bug in chess.svg, namely on line 71 (CHECK_GRADIENT). The "r" attribute is missing there, so PyQt6 doesn't render the radial gradient at all and produces an error. PyQt5, for some reason, works without the "r" attribute. And as tested, adding the "r" attribute works in both frameworks. Adding the "r" attribute doesn't brake anyone's code, so it's safe to add it.

Please fix line 71 in chess.svg to be:

CHECK_GRADIENT = """<radialGradient id="check_gradient" r="0.5"><stop offset="0%" stop-color="#ff0000" stop-opacity="1.0" /><stop offset="50%" stop-color="#e70000" stop-opacity="1.0" /><stop offset="100%" stop-color="#9e0000" stop-opacity="0.0" /></radialGradient>""" # noqa: E501

2 replies
Ghost
@ghost~58c242a5d73408ce4f4f9df5

How to get the best-understandable score of a chessboard position (i.e., a centipawn score in the format like 0.41) returned by result.info["score"].white().score() (which returns a not-so-understandable value in the format like 41.00)?

Well, my approach is that I just divide the returned value of that score() method by 100. So like this: result.info["score"].white().score() / 100 (I prefer to have centipawn scores from White's point of view).

There's no mention of this "formula" (dividing by 100) in the python-chess documentation. There could (maybe even should) be a method (named perhaps centipawn_score()) that divides the returned value of that score() method by 100. It'd be used as result.info["score"].white().centipawn_score() to get the actual (centipawn) score (like 0.41, as it is displayed by all chess GUIs I know) and not a (perhaps strange) number (like 41.00).

Can this be implemented?

Ghost
@ghost~58c242a5d73408ce4f4f9df5
I would fix the method score() of the Cp class in chess.engine on line 644 and define it like this:
def score(self, *, mate_score: Optional[int] = None) -> float:
    return self.cp / 100
Ghost
@ghost~58c242a5d73408ce4f4f9df5
@niklasf, I think it would be more reasonable for the find_move() method of chess.Board() to return None if no legal move is found by it. It now raises a ValueError exception, but I think that could be improved. It's better to do if board.find_move(some_move) is not None than to have a try/except block.
Sam Q
@SamQ26867433_twitter
Hi, I'd like to know how to change the colors of the light and dark chessboard squares. An example would be nice.
Sam Q
@SamQ26867433_twitter
I know I can go to the svg.py file and change the light and dark colors there, but I'd like to know how do do it without modifying the python-chess library.
Ghost
@ghost~58c242a5d73408ce4f4f9df5
@SamQ26867433_twitter, the way I do it is like this:
  1. firstly, I define a Python dictionary and override those default python-chess hex values that represent colors
    my_default_theme = {
     "coord": "#f0f6fd80",
     "margin": "#15781b80",
     "arrow red": "#88202080",
     "arrow blue": "#00308880",
     "arrow green": "#15781b80",
     "square dark": "#e5e5e5ff",
     "square light": "#f0f6fdff",
     "arrow yellow": "#e68f0080",
     "square dark lastmove": "#8b000080",
     "square light lastmove": "#8b000080",
    }
  2. then I just pass this my_default_theme dictionary to chess.svg.board(..., colors=my_default_theme)
Sam Q
@SamQ26867433_twitter
@PedanticHacker Is there any way to have a dynamically resizable chessboard in python-chess? I tried to do it with QSplitters, but it didn't work. Also, I read svg was causing problems when using pyinstaller. If true, it's a deal-breaker using svg, the python-chess is still useful anyway.
Ghost
@ghost~58c242a5d73408ce4f4f9df5

@SamQ26867433_twitter, you need to have the chessboard quadraticly shaped, otherwise you end up with squares that are not squares anymore but rectangles, and this messes up the coordinate system of your chessboard; clicking on the a1 square, for example, is registered as being the a2 square, etc.

I propose you have options for displaying a small chessboard, a medium chessboard and a big chessboard, each of its size being quadraticly shaped; say, 400×400 chessboard size for the small version, 500×500 for the medium version and 600×600 for the big version... you then have complete control over the coordinate system of your chessboard, because your coordinate formula takes the size of the chessboard (whichever of those 3 sizes is chosen by the user of your application), and then every square is registered correctly, because the formula adapts to whichever size you pass into it, but it must be quadratic (400×400, 500×500, etc.)

you can't freely stretch and shrink the chessboard, that's a limitation of the chessboard (and its squares of which it is comprised) being naturally quadratic...

Ghost
@ghost~58c242a5d73408ce4f4f9df5
@niklasf, what is happening with the development of python-chess? there hasn't been a new version for more than 2 months now... I know you probably were on vacation, but is the development of python-chess going to continue? perhaps in September?
Niklas Fiekas
@niklasf
no worries. i don't have any major plans for new features at the moment, but definitely still actively maintaining the project
Ghost
@ghost~58c242a5d73408ce4f4f9df5
@niklasf, can you please release a new version? Perhaps a v1.6.2? I have to monkey-patch the chess.svg.CHECK_GRADIENT for it to have r="0.5". As I already explained, (I don't know why, but) PyQt6 needs this "r" attribute explicitly set, even though a default is already set as r="0.5" as per the SVG specification). This was already fixed by you, but if you release a new version, my monkey-patch will no longer be needed.
Niklas Fiekas
@niklasf
you can just install from git in meantime (pip install git+https://github.com/niklasf/python-chess)
Ghost
@ghost~58c242a5d73408ce4f4f9df5

I've done that. Thanks for the tip.

@niklasf, what will the next version number of python-chess be? Are you waiting for the final version of Python 3.10 to then drop Python 3.9 support and bump python-chess to version v2.0.0?