Jump to content

英文维基 | 中文维基 | 日文维基 | 草榴社区

Template talk:Chess diagram

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

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.

Samboy (talk) 21:59, 10 August 2022 (UTC)[reply]

done. Frietjes (talk) 16:13, 11 August 2022 (UTC)[reply]

Attribution and chess images

[edit]
The Elephant is probably complex enough that attribution requirements become an issue.

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)[reply]

Any objections? — Red-tailed hawk (nest) 21:09, 4 November 2023 (UTC)[reply]

Template-protected edit request on 26 January 2024

[edit]

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)[reply]

 DoneSD0001 (talk) 18:11, 26 January 2024 (UTC)[reply]

Colored symbol suggestions

[edit]

Two suggestions:

  1. I propose adding a black border around the white marking symbols. As it is, they kinda blend in when placed on a light square. I have to imagine that that was why the white piece symbols were given black borders, so we might as well do it here, too.
  2. Can we get a third type of marking, the ring? It's like the dot, but it has a circular bit missing inside. You use "oO" and "xO" for the white ring and black ring, respectively. It'd be nice to standardize using the ring to indicate non-capturing moves, which applies to the pawn and to many fairy chess pieces. Plus, having a third colored symbol might also come in handy elsewhere (e.g., that one diagram in Castling § History, where we could really use a symbol to fill in the squares given by H. J. R. Murray).

ISaveNewspapers (talk) 02:50, 14 June 2024 (UTC)[reply]

Castling also counts as a non-capturing move. ISaveNewspapers (talk) 22:16, 15 June 2024 (UTC)[reply]

Edit request 21 August 2024

[edit]

Description of suggested change: There's an ugly empty row below the chess board if the caption is set to a single newline (see e.g. King's Gambit, Nimzowitsch-Larsen Attack, Petrov's Defence, Two Knights Defense, and Sicilian Defence). Instead of fixing all these articles, let's get rid of this once and for all so that our eyes may finally stop hurting.

Diff:

if (footer and footer ~= '') then div:tag('div') :addClass('thumbcaption') :wikitext(footer) end
+
if (footer and mw.text.trim(footer) ~= '') then div:tag('div') :addClass('thumbcaption') :wikitext(footer) end

Dexxor (talk) 10:45, 21 August 2024 (UTC)[reply]

This has been added to the sandbox. There is an error in the live version of this module (since May 2013 apparently) and seems to be an issue with the escape patterns in lines 243 and 244. I have made a possible fix in the sandbox. Can you comment on this @Frietjes? — Martin (MSGJ · talk) 16:23, 22 August 2024 (UTC)[reply]
MSGJ, seems fine to me. I was first learning LUA back then, so I may have made a mistake with the escape patterns. if it works fine with these changes, then go for it. Frietjes (talk) 16:33, 22 August 2024 (UTC)[reply]
 Done — Martin (MSGJ · talk) 08:32, 23 August 2024 (UTC)[reply]