Template talk:Chess diagram
This is the talk page for discussing improvements to the Chess diagram template. |
|
Chess Template‑class | |||||||
|
Template:Chess diagram is permanently protected from editing because it is a heavily used or highly visible template. Substantial changes should first be proposed and discussed here on this page. If the proposal is uncontroversial or has been discussed and is supported by consensus, editors may use {{edit template-protected}} to notify an administrator or template editor to make the requested edit. Usually, any contributor may edit the template's documentation to add usage notes or categories.
Any contributor may edit the template's sandbox. Functionality of the template can be checked using test cases. |
|
||
This page has archives. Sections older than 90 days may be automatically archived by Lowercase sigmabot III when more than 4 sections are present. |
Dedicated 12 by 12 diagram edit
Would anyone be willing to create a dedicated 12 by 12 diagram? I'm looking to use said diagram in my article for the variant "Chess on a 12 by 12 board", so I can set up the variant's opening position without wrangling with confusing syntax on one line. – Itswikisam (t • c) 02:22, 6 June 2022 (UTC)
- you could create one by copying Template:Chess diagram 10x10 and changing the 10 to 12. Frietjes (talk) 16:47, 25 July 2022 (UTC)
- What about Wikipedia:Templates_for_discussion/Log/2019_June_22 where a bunch of non-standard sizes were deleted? Samboy (talk) 16:40, 9 August 2022 (UTC)
I have a pull request edit
There’s an issue with how these chessboards look on mobile browsers. I have fixed the issue (it took me hours to find the fix). The issue is this code in Module:Chessboard/Chess
return string.format( '[[File:Chess %s%st45.svg|%dx%dpx|alt=%s|%s|link=|class=notpageimage]]', piece, color, size, size, alt, alt )
In order for the images to look right on mobile browsers, we need to specify the vertical alignment, as follows:
return string.format( '[[File:Chess %s%st45.svg|%dx%dpx|alt=%s|%s|link=|class=notpageimage|top]]', piece, color, size, size, alt, alt )
(The <nowiki> tags are only here so the code looks right when reading it)
This issue is especially evident when looking at mobile pages with smaller chess diagrams in Firefox (the chess pieces are outside of the squares they are supposed to be in).
While there is WP:BOLD, there is also "don’t merge code in to production without approval from another programmer”. I am not going to make this change; I have instead created Module:Chessboard/ChessSmall and Template:Chess diagram samboy for testing the change.
Other modules and templates I created to debug the issue: Module:ChessboardSamboy, Template:Chess diagram samboy, and User:Samboy/Chess. Hopefully someone with an iPhone can make sure the diagrams in User:Samboy/Chess look OK there. They look fine in Chrome for Android.
Samboy (talk) 16:11, 9 August 2022 (UTC)
- Samboy, I added the "top" to the submodules. Frietjes (talk) 14:20, 10 August 2022 (UTC)
- Samboy, if everything is fixed for you, could you tag your demonstration modules/templates for deletion, or move them to
Module:Sandbox/Samboy/Chessboard
and your userspace? we try to keep module and template space clean when possible. thank you for finding/fixing the problem! Frietjes (talk) 18:01, 10 August 2022 (UTC)
- I understand about keeping the global namespace clean. I have replaced all of the pages with {{db-g2}} so hopefully an admin can clean them up. Also, things now look great on my mobile devices; this solves the issue with chess piece misplacement caused by some strange CSS making a div we specify being, say, 22x22 px have a higher height. I’ll use
Module:Sandbox/Samboy/
should I need to play with Lua to test something like this again. Is there a “Sandbox” namespace for Templates, e.g.Template:Sandbox/Samboy/
? Samboy (talk) 19:21, 10 August 2022 (UTC)- Samboy, thank you. for existing templates/modules, you can just use the standard template sandboxes (e.g., use
{{chess diagram/sandbox}}
,Module:Chessboard/Chess/sandbox
...). theModule:Sandbox/Samboy/
is a substitute for personal userspace sandboxes since you can't #invoke a userpage. thank you again. Frietjes (talk) 19:31, 10 August 2022 (UTC)
- Samboy, thank you. for existing templates/modules, you can just use the standard template sandboxes (e.g., use
- I understand about keeping the global namespace clean. I have replaced all of the pages with {{db-g2}} so hopefully an admin can clean them up. Also, things now look great on my mobile devices; this solves the issue with chess piece misplacement caused by some strange CSS making a div we specify being, say, 22x22 px have a higher height. I’ll use
Another pull request: Add multi-digit support to FEN edit
Since the FEN parsing code in Module:Chessboard mxn is clean and allows for fairy pieces, the only thing stopping us from using this code to have large board chess variant support a lack of support for multi-digit numbers in the FEN converter. I have fixed this.
Here’s the current code (lines 130-152):
function convertFenToArgs( fen ) -- converts FEN notation to an array of positions, offset by 2 local res = {' ', ' '} -- Loop over rows, which are delimited by / for srow in string.gmatch("/" .. fen, "/%w+") do -- Loop over all letters and numbers in the row for piece in srow:gmatch( "%w" ) do if (piece:match("%d")) then -- if a digit for k=1,piece do table.insert(res,' ') end else -- not a digit local color = piece:match( '%u' ) and 'l' or 'd' piece = piece:lower() table.insert(res, piece .. color ) end end end
return res end
Here’s my updated version of that code with support for multi-character numbers (which are used in, say, Fairy Stockfish), over at Module:Chessboard_mxn/Sandbox so that we can have standard large board Fairy chess FEN like rnbqkcabnr/pppppppppp/10/10/10/10/PPPPPPPPPP/RNBQKCABNR
(lines 130-171 in the “Sandbox” module):
function convertFenToArgs( fen ) -- converts FEN notation to an array of positions, offset by 2 local res = {' ', ' '} -- Loop over rows, which are delimited by / for srow in string.gmatch("/" .. fen, "/%w+") do srow = srow:gsub("/","") -- clean up row -- Loop over all letters and numbers in the row -- Since Lua regexes do not have the | operator, we have -- to spell things out local index = 1 local piece = "" -- Piece can also be empty squares local place = 0 local pstart = 0 local pend = 0 local length = srow:len() while index <= length do -- Look for a number. Can have multiple digits pstart, pend = srow:find("%d+", index) if pstart == index then piece = srow:sub(pstart, pend) index = pend + 1 for k=1,tonumber(piece) do table.insert(res,' ') end else -- If number not found, look for a letter (piece on board) pstart = srow:find("%a",index) if pstart == index then piece = srow:sub(pstart, pstart) index = pstart + 1 -- l: White (light); d: Black (dark) local color = piece:match( '%u' ) and 'l' or 'd' piece = piece:lower() table.insert(res, piece .. color) else index = length + 1 -- Break loop end end end end return res end
Some thoughts on the coding style:
- I avoid Lua’s coercion with an explicit “tonumber()” call. This isn’t needed in Lua, but I have it here so that other programmers know I meant to make that string a number
- There’s some infinite loop protection, which is needed for code which runs on a “mainframe” like Wikimedia’s servers: We will always increase “index”, no matter what is in the string.
- Lua doesn’t have an
|
operator in its regex library. This is by design; if you have ever seen how big the Lua port of a pcre library is, we can make the loop a little bigger to keep the regex library small. (Speaking of pcre, I once had dinner with Larry Wall) - I have a number of tests over at User:Samboy/Chess
- We should only make this change in Module:Chessboard mxn, *not* Module:Chessboard since the only use case for this is large board chess variants.
Attribution and chess images edit
I'm looking at the various chess pieces that this template uses, and they appear to be released under CC BY-SA 3.0. That's perfectly fine for using, but we'd need to maintain some way to give the creators of those pieces attribution for their artwork. Some of these pieces are not trivially simple as to be in the public domain by virtue of their simplicity—particularly so for fairy chess pieces like the elephant. The standard way to do this is by linking to the source material for the various images that are used, but the template currently makes it so that clicking on a piece does not take one into the mediaviewer. For reasons of copyright, I think this probably should be changed, and I'm opening up discussion here towards that end. — Red-tailed hawk (nest) 14:37, 1 November 2023 (UTC)
- Any objections? — Red-tailed hawk (nest) 21:09, 4 November 2023 (UTC)
Template-protected edit request on 26 January 2024 edit
This edit request to Module:Chessboard has been answered. Set the |answered= or |ans= parameter to no to reactivate your request. |
Can we please add a CSS class of "notheme" to the output of Module:Chessboard, in addition to the "chess-board" class? This will help prevent issues with styling in Dark themes in mobile apps, and will not impact presentation otherwise. (phab:T284327) Dmitry Brant (talk) 13:42, 26 January 2024 (UTC)