2 * Copyright (c) 2018. Developed by Hedgecode.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.hedgecode.chess.wiki;
19 import java.util.HashMap;
22 import org.hedgecode.chess.position.Color;
23 import org.hedgecode.chess.position.ColorPiece;
24 import org.hedgecode.chess.position.Piece;
27 * Wikipedia chess diagram constants.
29 * @author Dmitry Samoshin aka gotty
31 public final class Wiki {
33 public static final String CRLF = System.lineSeparator();
35 public static final String EMPTY = " ";
36 public static final String SEPARATOR = "|";
38 public static final String TEMPLATE_BEGIN = "{{";
39 public static final String TEMPLATE_END = "}}";
41 public static final String WHITE_PAWN = "pl";
42 public static final String WHITE_KNIGHT = "nl";
43 public static final String WHITE_BISHOP = "bl";
44 public static final String WHITE_ROOK = "rl";
45 public static final String WHITE_QUEEN = "ql";
46 public static final String WHITE_KING = "kl";
48 public static final String BLACK_PAWN = "pd";
49 public static final String BLACK_KNIGHT = "nd";
50 public static final String BLACK_BISHOP = "bd";
51 public static final String BLACK_ROOK = "rd";
52 public static final String BLACK_QUEEN = "qd";
53 public static final String BLACK_KING = "kd";
55 private static final Map<ColorPiece, String> PIECES = new HashMap<ColorPiece, String>() {
57 put(ColorPiece.WHITE_PAWN, WHITE_PAWN); put(ColorPiece.BLACK_PAWN, BLACK_PAWN);
58 put(ColorPiece.WHITE_KNIGHT, WHITE_KNIGHT); put(ColorPiece.BLACK_KNIGHT, BLACK_KNIGHT);
59 put(ColorPiece.WHITE_BISHOP, WHITE_BISHOP); put(ColorPiece.BLACK_BISHOP, BLACK_BISHOP);
60 put(ColorPiece.WHITE_ROOK, WHITE_ROOK); put(ColorPiece.BLACK_ROOK, BLACK_ROOK);
61 put(ColorPiece.WHITE_QUEEN, WHITE_QUEEN); put(ColorPiece.BLACK_QUEEN, BLACK_QUEEN);
62 put(ColorPiece.WHITE_KING, WHITE_KING); put(ColorPiece.BLACK_KING, BLACK_KING);
66 private static boolean withTemplate = false;
71 public static boolean withTemplate() {
75 public static void setTemplate(boolean isTemplate) {
76 withTemplate = isTemplate;
79 public static ColorPiece getColorPiece(String piece) {
80 if (piece != null && !EMPTY.equals(piece)) {
81 for (Map.Entry<ColorPiece, String> entry : PIECES.entrySet()) {
82 if (entry.getValue().equals(piece))
83 return entry.getKey();
89 public static String getWikiPiece(Color color, Piece piece) {
91 ColorPiece.getColorPiece(color, piece)
95 public static String getWikiPiece(ColorPiece colorPiece) {
96 return (colorPiece != null)
97 ? PIECES.get(colorPiece)