<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3AChess_from_pgn</id>
	<title>Module:Chess from pgn - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3AChess_from_pgn"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Chess_from_pgn&amp;action=history"/>
	<updated>2026-05-27T03:18:42Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://stockhub.co/index.php?title=Module:Chess_from_pgn&amp;diff=135569&amp;oldid=prev</id>
		<title>imported&gt;Pppery: Pppery moved page Module:Chess games to Module:Chess from pgn without leaving a redirect: Make module name match template name</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Chess_from_pgn&amp;diff=135569&amp;oldid=prev"/>
		<updated>2019-04-28T21:13:13Z</updated>

		<summary type="html">&lt;p&gt;Pppery moved page &lt;a href=&quot;/index.php?title=Module:Chess_games&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Module:Chess games (page does not exist)&quot;&gt;Module:Chess games&lt;/a&gt; to &lt;a href=&quot;/research/Module:Chess_from_pgn&quot; title=&quot;Module:Chess from pgn&quot;&gt;Module:Chess from pgn&lt;/a&gt; without leaving a redirect: Make module name match template name&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;pgn = require(&amp;#039;module:pgn&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local function moveToIndex(move)&lt;br /&gt;
	if not move:match(&amp;#039;^%d+[dl]$&amp;#039;) then return -1 end -- not a move&lt;br /&gt;
	local num, color = move:match(&amp;#039;(%d+)([dl])&amp;#039;)&lt;br /&gt;
	return num * 2 + (color == &amp;#039;d&amp;#039; and 1 or 0)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function indexToMove(index)&lt;br /&gt;
	return string.format(&amp;#039;%d%s&amp;#039;, math.floor( index / 2), index % 2 == 0 and &amp;#039;l&amp;#039; or &amp;#039;d&amp;#039;)&lt;br /&gt;
end&lt;br /&gt;
	&lt;br /&gt;
function display_game(frame)&lt;br /&gt;
	local args = frame:getParent().args&lt;br /&gt;
	for k, v in pairs(frame.args) do args[k] = v end&lt;br /&gt;
	local game = args[&amp;#039;pgn&amp;#039;]&lt;br /&gt;
	if not game then error(&amp;#039;must have &amp;quot;pgn&amp;quot; parameter&amp;#039;) end&lt;br /&gt;
	&lt;br /&gt;
	local moves = pgn.pgn2fen(game)&lt;br /&gt;
	local template = args[&amp;#039;template&amp;#039;]&lt;br /&gt;
	if not template then error(&amp;#039;must have &amp;quot;template&amp;quot; parameter&amp;#039;) end&lt;br /&gt;
	local tmTable = {}&lt;br /&gt;
	&lt;br /&gt;
	local hydrate = function(index, comment) &lt;br /&gt;
		local temp = template:gsub(&amp;#039;%$fen%$&amp;#039;, moves[index])&lt;br /&gt;
		temp = temp:gsub(&amp;#039;%$comment%$&amp;#039;, comment)&lt;br /&gt;
		temp = temp:gsub(&amp;#039;%$move%$&amp;#039;, indexToMove(index))&lt;br /&gt;
		table.insert(tmTable,  { index, temp } )&lt;br /&gt;
	end&lt;br /&gt;
	template = mw.text.unstripNoWiki( template )&lt;br /&gt;
	for arg, val in pairs(args) do -- collect boards of the form &amp;quot;12l = comment&amp;quot;&lt;br /&gt;
		local index = moveToIndex(arg)&lt;br /&gt;
		if index &amp;gt;= 0 then hydrate(index, val) end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	for arg, val in pairs(args) do -- collect boards of the form &amp;quot;| from1 = 7d | to1 = 8l | comments1 = { &amp;quot;comment&amp;quot;, &amp;quot;comment&amp;quot; }&lt;br /&gt;
		if arg:match(&amp;#039;^from%d+$&amp;#039;) then&lt;br /&gt;
			local hunk = arg:match((&amp;#039;^from(%d+)$&amp;#039;))&lt;br /&gt;
			toMove = args[&amp;#039;to&amp;#039; .. hunk]&lt;br /&gt;
			if not toMove then error (string.format(&amp;#039;parameter %s exists, but no parameter to%s&amp;#039;, arg, hunk)) end&lt;br /&gt;
			local fromIndex = moveToIndex(val)&lt;br /&gt;
			if fromIndex &amp;lt; 0 then error(string.format(&amp;#039;malformed value for parameter %s&amp;#039;, arg)) end&lt;br /&gt;
			local toIndex = moveToIndex(toMove)&lt;br /&gt;
			if toIndex &amp;lt; 0 then error(string.format(&amp;#039;malformed value for parameter to%s&amp;#039;, hunk)) end&lt;br /&gt;
			local comments = {}&lt;br /&gt;
			local commentsVal = args[&amp;#039;comments&amp;#039; .. hunk] or &amp;#039;&amp;#039;&lt;br /&gt;
			for comment in commentsVal:gmatch(&amp;#039;{([^}]*)}&amp;#039;) do table.insert(comments, comment) end&lt;br /&gt;
			for index = fromIndex, toIndex do hydrate(index, table.remove(comments, 1) or &amp;#039;&amp;#039;) end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	table.sort(tmTable, function(a, b) return a[1] &amp;lt; b[1] end)&lt;br /&gt;
	local res = &amp;#039;&amp;#039;&lt;br /&gt;
	for _, item in ipairs(tmTable) do res = res ..  frame:preprocess(item[2]) end&lt;br /&gt;
	return res&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return {&lt;br /&gt;
	[&amp;#039;display game&amp;#039;] = display_game&lt;br /&gt;
}&lt;/div&gt;</summary>
		<author><name>imported&gt;Pppery</name></author>
	</entry>
</feed>