+++ /dev/null
-/*
- * Copyright (c) 2018. Developed by Hedgecode.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.hedgecode.chess.wiki;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.hedgecode.chess.position.Color;
-import org.hedgecode.chess.position.ColorPiece;
-import org.hedgecode.chess.position.Piece;
-
-/**
- * Wikipedia chess diagram constants.
- *
- * @author Dmitry Samoshin aka gotty
- */
-public final class Wiki {
-
- public static final String CRLF = System.lineSeparator();
-
- public static final String EMPTY = " ";
- public static final String SEPARATOR = "|";
-
- public static final String TEMPLATE_BEGIN = "{{";
- public static final String TEMPLATE_END = "}}";
-
- public static final String WHITE_PAWN = "pl";
- public static final String WHITE_KNIGHT = "nl";
- public static final String WHITE_BISHOP = "bl";
- public static final String WHITE_ROOK = "rl";
- public static final String WHITE_QUEEN = "ql";
- public static final String WHITE_KING = "kl";
-
- public static final String BLACK_PAWN = "pd";
- public static final String BLACK_KNIGHT = "nd";
- public static final String BLACK_BISHOP = "bd";
- public static final String BLACK_ROOK = "rd";
- public static final String BLACK_QUEEN = "qd";
- public static final String BLACK_KING = "kd";
-
- private static final Map<ColorPiece, String> PIECES = new HashMap<ColorPiece, String>() {
- {
- put(ColorPiece.WHITE_PAWN, WHITE_PAWN); put(ColorPiece.BLACK_PAWN, BLACK_PAWN);
- put(ColorPiece.WHITE_KNIGHT, WHITE_KNIGHT); put(ColorPiece.BLACK_KNIGHT, BLACK_KNIGHT);
- put(ColorPiece.WHITE_BISHOP, WHITE_BISHOP); put(ColorPiece.BLACK_BISHOP, BLACK_BISHOP);
- put(ColorPiece.WHITE_ROOK, WHITE_ROOK); put(ColorPiece.BLACK_ROOK, BLACK_ROOK);
- put(ColorPiece.WHITE_QUEEN, WHITE_QUEEN); put(ColorPiece.BLACK_QUEEN, BLACK_QUEEN);
- put(ColorPiece.WHITE_KING, WHITE_KING); put(ColorPiece.BLACK_KING, BLACK_KING);
- }
- };
-
- private static boolean withTemplate = false;
-
- private Wiki() {
- }
-
- public static boolean withTemplate() {
- return withTemplate;
- }
-
- public static void setTemplate(boolean isTemplate) {
- withTemplate = isTemplate;
- }
-
- public static ColorPiece getColorPiece(String piece) {
- if (piece != null && !EMPTY.equals(piece)) {
- for (Map.Entry<ColorPiece, String> entry : PIECES.entrySet()) {
- if (entry.getValue().equals(piece))
- return entry.getKey();
- }
- }
- return null;
- }
-
- public static String getWikiPiece(Color color, Piece piece) {
- return getWikiPiece(
- ColorPiece.getColorPiece(color, piece)
- );
- }
-
- public static String getWikiPiece(ColorPiece colorPiece) {
- return (colorPiece != null)
- ? PIECES.get(colorPiece)
- : EMPTY;
- }
-
-}