|
|
Zeile 203: |
Zeile 203: |
|
| |
|
| <br clear="all"> | | <br clear="all"> |
|
| |
| <html>
| |
| <head>
| |
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
| |
| <title>FEN2Wikipedia - Translate FEN Chess positions into Wikipedia format (David A. Wheeler)</title>
| |
| <link rel="shortcut icon" href="../favicon.ico" type="image/x-icon">
| |
| <meta name="description" content="David A. Wheeler's FEN2Wikipedia">
| |
| <meta name="keywords" content="David, Wheeler, David A. Wheeler, David Wheeler, chess, FEN, wikipedia, chess position, chess diagram, MediaWiki, template, chess template, GPL, GNU GPL, Javascript">
| |
|
| |
| <!--
| |
| FEN2Wikipedia, translate Forsyth-Edwards Notation (FEN) to Wikipedia format.
| |
| Copyright (C) 2005 David A. Wheeler
| |
|
| |
| This program is free software; you can redistribute it and/or modify
| |
| it under the terms of the GNU General Public License as published by
| |
| the Free Software Foundation; either version 2 of the License, or
| |
| (at your option) any later version.
| |
|
| |
| This program is distributed in the hope that it will be useful,
| |
| but WITHOUT ANY WARRANTY; without even the implied warranty of
| |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
| |
| GNU General Public License for more details.
| |
|
| |
| You should have received a copy of the GNU General Public License
| |
| along with this program; if not, write to the Free Software
| |
| Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
| |
| -->
| |
|
| |
| <!--
| |
| ChangeLog:
| |
| * Version 1.00, August 31, 2005, initial version.
| |
| -->
| |
|
| |
| <script language="JavaScript">
| |
| <!-- Begin
| |
|
| |
| // FEN2Wikipedia - convert FEN to Wikipedia format.
| |
| // This program takes FEN, in this kind of format:
| |
| // rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR
| |
| // and generates this kind of format:
| |
| // {{Schachbrett|=
| |
| // | tright
| |
| // |
| |
| // |=
| |
| // 8 |br|bn|bb|bq|bk|bb|bn|br|=
| |
| // 7 |bp|bp|bp|bp| |bp|bp|bp|=
| |
| // 6 | | | | | | | | |=
| |
| // 5 | | | | |bp| | | |=
| |
| // 4 | | | | |wp|wp| | |=
| |
| // 3 | | | | | | | | |=
| |
| // 2 |wp|wp|wp|wp| | |wp|wp|=
| |
| // 1 |wr|wn|wb|wq|wk|wb|wn|wr|=
| |
| // a b c d e f g h
| |
| // | The King's Gambit
| |
| // }}
| |
| //
| |
| // By default, it reads the standard start of game:
| |
| // rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR
| |
| // and produces:
| |
| // {{Schachbrett|=
| |
| // | tright
| |
| // |
| |
| // |=
| |
| // 8 |br|bn|bb|bq|bk|bb|bn|br|=
| |
| // 7 |bp|bp|bp|bp|bp|bp|bp|bp|=
| |
| // 6 | | | | | | | | |=
| |
| // 5 | | | | | | | | |=
| |
| // 4 | | | | | | | | |=
| |
| // 3 | | | | | | | | |=
| |
| // 2 |wp|wp|wp|wp|wp|wp|wp|wp|=
| |
| // 1 |wr|wn|wb|wq|wk|wb|wn|wr|=
| |
| // a b c d e f g h
| |
| // |
| |
| // }}
| |
|
| |
|
| |
|
| |
| // globals -- the current row and column being generated.
| |
| var row;
| |
| var column;
| |
| var maxcolumn;
| |
|
| |
| function cellout(fensymbol) {
| |
| // Return the fensymbol, converted to Wikipedia template format.
| |
| var answer = "";
| |
| var count;
| |
| var i;
| |
| if ( (fensymbol == "/") || (fensymbol == " ") ) {return "";}
| |
|
| |
| // If we need to output multiple cells, do that and return.
| |
| if ((fensymbol >= 2 && fensymbol <= 9) || (fensymbol == "0")) {
| |
| count = 0 + fensymbol; // convert text to number (note order!).
| |
| if (count == 0) {count = 9;} // so "10" becomes 1+9=10.
| |
| for (i=0; i < count; i++) {
| |
| answer += cellout("1");
| |
| }
| |
| return answer;
| |
| }
| |
|
| |
| // Add row prefix if this is the first column.
| |
| if ( column == 1) {
| |
| answer = " " + row + " |";
| |
| }
| |
|
| |
| // Now output based on the symbol. "1" generates a blank cell.
| |
| if (fensymbol == 'x') {
| |
| answer += "xx";
| |
| } else if (fensymbol == 'o') {
| |
| answer += "xo";
| |
| } else if (fensymbol >= 'a' && fensymbol <= 'z') {
| |
| answer += "b" + fensymbol;
| |
| } else if (fensymbol >= 'A' && fensymbol <= 'Z') {
| |
| answer += "w" + fensymbol.toLowerCase();
| |
| } else if (fensymbol == 1) {
| |
| answer += " ";
| |
| }
| |
| answer += "|";
| |
|
| |
| // If we're at the end of the row, output row-ending material.
| |
| column++;
| |
| if ( column > maxcolumn) {
| |
| row--;
| |
| column = 1;
| |
| answer += "=\n";
| |
| }
| |
|
| |
| return answer;
| |
| }
| |
|
| |
| function ReplyText(fentext, diagramtype, alignmentvalue,
| |
| headertext, footertext) {
| |
| // returns Chess text given inputs.
| |
| // Currently only handles up to 10-column boards, and it only
| |
| // allows 8x8 and 10x8.
| |
| var res; // accumulated result.
| |
|
| |
| // initialize global variables.
| |
| row = 8;
| |
| column = 1; // row "a" is 1.
| |
| maxcolumn = 8;
| |
|
| |
| // Start template - Output type of output, e.g., "Schachbrett"
| |
| res = "{{" + diagramtype + "|=" + "\n";
| |
| if (diagramtype == "Schachbrett 8x10") {
| |
| maxcolumn = 10;
| |
| }
| |
|
| |
| // Output rest of header; alignment (tright or tleft) and headertext.
| |
| res += "| " + alignmentvalue + "\n";
| |
| res += "| " + headertext + "\n";
| |
| res += "|=\n";
| |
|
| |
| // Output cells.
| |
| for (i=0; i < fentext.length; i++) {
| |
| res += cellout(fentext.charAt(i));
| |
| if (row == 0) { break; } // Ignore trailing text (castling, etc.)
| |
| // Note that since we ignore stuff when we're done, we can't detect
| |
| // "Excess" information. I've decided it's not worth worrying about.
| |
| }
| |
|
| |
| // Output what's underneath -- the column labels, footer, etc.
| |
| res += " a b c d e f g h";
| |
| if (maxcolumn == 10) {
| |
| res += " i j";
| |
| }
| |
| res += "\n";
| |
| res += "| " + footertext + "\n";
| |
| res += "}}\n";
| |
|
| |
| if (row > 0) {
| |
| res = "Warning! Missing information! This won't work:\n\n" + res;
| |
| }
| |
|
| |
| return res;
| |
| }
| |
|
| |
|
| |
| function GenerateText(nameform) {
| |
| // Extract data from form, get board, and display on form.
| |
|
| |
| var dtemp, diagramtype_text;
| |
| var atemp, alignmentvalue_text;
| |
|
| |
| dtemp = nameform.diagramtype;
| |
| diagramtype_text = dtemp.options[dtemp.selectedIndex].value;
| |
| atemp = nameform.alignmentvalue;
| |
| alignmentvalue_text = atemp.options[atemp.selectedIndex].value;
| |
|
| |
| nameform.result.value =
| |
| ReplyText(nameform.fen.value, diagramtype_text, alignmentvalue_text,
| |
| nameform.header.value, nameform.footer.value);
| |
| }
| |
|
| |
|
| |
| // End -->
| |
| </script>
| |
| </head>
| |
| <h1>FEN2Wikipedia - Translate FEN Chess positions into Wikipedia format</h1>
| |
| <p>
| |
| This is FEN2Wikipedia, a simple tool that takes
| |
| <a href="http://en.wikipedia.org/wiki/Chess">Chess</a> positions described
| |
| using the
| |
| <a href="http://en.wikipedia.org/wiki/Forsyth-Edwards_Notation">
| |
| Forsyth-Edwards Notation (FEN)</a> format, and converts them
| |
| into the <a href="http://www.schach-computer.info/wiki/index.php/Hauptseite">Schachcomputer Wiki</a> format for
| |
| chess diagrams "Schachbrett" template</a>).
| |
| <p>
| |
| Enter the data below (at least the FEN value) and press
| |
| the "Generate Wikipedia Text Result (below)" button.
| |
| The Wikipedia format will be displayed below, which you can then cut and paste
| |
| into Wikipedia.
| |
| <p>
| |
|
| |
| <form name="main">
| |
| <table>
| |
| <tr><th>FEN:</th><td><input type="text" name="fen" size="70" value="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"></td></tr>
| |
| <tr><th>Header:</th><td> <input type="text" name="header" size="70"></td></tr>
| |
| <tr><th>Footer:</th><td><input type="text" name="footer" size="70"></td></tr>
| |
| <tr>
| |
| <th>Type:</th><td>
| |
| <select size="1" name="diagramtype">
| |
| <option selected="on" value="Schachbrett">Schachbrett (Feldgröße 44x44 px)</option>
| |
| <option value="Schachbrett klein">Schachbrett klein (Feldgröße 32x32 px)</option>
| |
| </select>
| |
| </td>
| |
| </tr>
| |
| <th>Alignment:</th><td>
| |
| <select size="1" name="alignmentvalue">
| |
| <option selected="selected" value="tright">Right</option>
| |
| <option value="tleft">Left</option>
| |
| </select>
| |
| </td>
| |
| </tr>
| |
|
| |
|
| |
| <tr>
| |
| <td colspan="2">
| |
| <input type="button" name="generate" value="Generate Wikipedia Text Result (below)" onClick="GenerateText(this.form)">
| |
| <input type="reset" name="Reset">
| |
| </td>
| |
| </tr>
| |
| </table>
| |
| <p>
| |
|
| |
| <textarea name="result" readonly="readonly" rows="20" cols="70"></textarea>
| |
|
| |
| </form>
| |
| <p>
| |
| FEN2Wikipedia was created by
| |
| <a href="http://www.dwheeler.com">David A. Wheeler</a>, and
| |
| is implemented using Javascript (aka ECMAscript).
| |
| <p>
| |
| <a href="http://commons.wikimedia.org/wiki/Standard_chess_diagram">
| |
| Wikimedia commons has more information on the Wikipedia
| |
| standard "chess diagram" template</a>.
| |
| This form takes normal FEN (e.g., "N" is white knight and "n" is black knight),
| |
| as well as "x" for a cross, "o" for a circle
| |
| on an empty squre, and the Capablanca chess symbols
| |
| "a" for archbishop and "c" for chancelor.
| |
| It uses two characters for a position, not one (the second character
| |
| shows the side of the piece/pawn); this means that the data will
| |
| work correctly on case-insensitive systems.
| |
| Wikipedia itself works correctly with case-sensitive data,
| |
| but by storing data this way, the data will work correctly
| |
| even on case-insensitive (some might say case-corrupting) systems.
| |
| In other words, by doing things this way, the data is more portable.
| |
|
| |
| <p>
| |
| <a href="http://www.w3schools.com/js/default.asp">W3Schools has more
| |
| information about Javascript/ECMAscript.</a>
| |
| <a href="http://www.w3.org/TR/html4/">W3C posts
| |
| the HTML 4.01 specification</a>.
| |
|
| |
| <p>
| |
| You can get the latest version of FEN2Wikipedia from
| |
| <a href="http://www.dwheeler.com/misc/fen2wikipedia.html">
| |
| http://www.dwheeler.com/misc/fen2wikipedia.html</a>.
| |
|
| |
| <p>
| |
| FEN2Wikipedia is <a href="http://www.dwheeler.com/oss_fs_why.html">open source
| |
| software / free software (OSS/FS)</a>.
| |
| That means that you
| |
| can freely give it to anyone, and you can
| |
| modify and redistribute modified versions of it to whoever you wish.
| |
| FEN2Wikipedia is Copyright (C) 2005 David A. Wheeler, and
| |
| comes with ABSOLUTELY NO WARRANTY.
| |
| FEN2Wikipedia is licensed under the
| |
| <a href="http://www.fsf.org/licenses/gpl.html">
| |
| GNU General Public License (GPL), version 2 or later</a>.
| |
|
| |
| </html>
| |
Hinweise
Ein paar praktische Hinweise:
- Achte darauf, dass du das Grundschema nicht veränderst, insbesondere lasse die Zeichen "|" und "=" da, wo sie sind.
- Du kannst das Zeichen "|" nicht im Titel oder der Beschreibung verwenden.
- Falls du das Zeichen "=" im Titel oder in der Beschreibung verwenden möchtest, musst du es in nowiki-Elemente einschließen.
- Du kannst Formatierungen wie fett oder kursiv benutzen.
Diagrammarten
Standarddiagramm
Dieses Diagramm wird empfohlen zur allgemeinen Verwendung in Artikeln über Eröffnungen, Endspiele, Spielverläufe, Positionen usw. Siehe zugehörigen Code unten.
{{Schachbrett|=
| tright
| R30 V2.5 - Magellan
|=
8 |br|bn|bb|bq|bk|bb|bn|br|=
7 |bp|bp|bp|bp| |bp|bp|bp|=
6 | | | | | | | | |=
5 | | | | |bp| | | |=
4 | | | | |wp|wp| | |=
3 | | | | | | | | |=
2 |wp|wp|wp|wp| | |wp|wp|=
1 |wr|wn|wb|wq|wk|wb|wn|wr|=
a b c d e f g h
| Königsgambit
}}
Standarddiagramm klein
{{Schachbrett klein|=
| tright
| R30 V2.5 - Magellan
|=
8 |br|bn|bb|bq|bk|bb|bn|br|=
7 |bp|bp|bp|bp| |bp|bp|bp|=
6 | | | | | | | | |=
5 | | | | |bp| | | |=
4 | | | | |wp|wp| | |=
3 | | | | | | | | |=
2 |wp|wp|wp|wp| | |wp|wp|=
1 |wr|wn|wb|wq|wk|wb|wn|wr|=
a b c d e f g h
| Königsgambit
}}
Alternativ können bei beiden Varianten auch die Feldbezeichnungen oder Leerzeilen weggelassen werden. Sie dienen nur der besseren Orientierung bei der Arbeit im Quelltext:
{{Schachbrett klein|=
| tright
| R30 V2.5 - Magellan
|=
8 |br|bn|bb|bq|bk|bb|bn|br|=
7 |bp|bp|bp|bp| |bp|bp|bp|=
6 | | | | | | | | |=
5 | | | | |bp| | | |=
4 | | | | |wp|wp| | |=
3 | | | | | | | | |=
2 |wp|wp|wp|wp| | |wp|wp|=
1 |wr|wn|wb|wq|wk|wb|wn|wr|=
a b c d e f g h
| Königsgambit
}}
Diagramm ohne Überschriften + Sonderzeichen
{{Schachbrett|=
| tright
|
|=
8 | | | | | | | | |=
7 | | | | | | | | |=
6 | |xx|xo|xx| | | | |=
5 | | |wp| | | | | |=
4 | | | | | |xo| | |=
3 | | | | |xx|xo|xx| |=
2 | | | | | |bp| | |=
1 | | | | | | | | |=
a b c d e f g h
|
}}
{{Schachbrett klein|=
| tright
|
|=
8 | | | | | | | | |=
7 | | | | | | | | |=
6 | |xx|xo|xx| | | | |=
5 | | |wp| | | | | |=
4 | | | | | |xo| | |=
3 | | | | |xx|xo|xx| |=
2 | | | | | |bp| | |=
1 | | | | | | | | |=
a b c d e f g h
|
}}
Konversion FEN --> Wiki-Vorlage
FEN2Wiki konvertiert Forsyth-Edwards-Notation (FEN) in Wiki-Schachdiagramme