DroidFish: Optional second title line with captured piece information and time control information. Implemented by Leo Mayer, with some changes by me.

This commit is contained in:
Peter Osterlund
2012-09-19 16:23:32 +00:00
parent 3f911220c2
commit aa0cc399bc
13 changed files with 272 additions and 52 deletions

View File

@@ -15,6 +15,11 @@
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:paddingLeft="1dp"> android:paddingLeft="1dp">
<include
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="@layout/title">
</include>
<LinearLayout <LinearLayout
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_width="fill_parent"

View File

@@ -3,6 +3,11 @@
android:orientation="vertical" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent"> android:layout_height="fill_parent">
<include
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="@layout/title">
</include>
<view <view
class="org.petero.droidfish.ChessBoardPlay" class="org.petero.droidfish.ChessBoardPlay"
android:id="@+id/chessboard" android:id="@+id/chessboard"

View File

@@ -10,6 +10,11 @@
android:layout_weight="1" android:layout_weight="1"
android:layout_width="0dip" android:layout_width="0dip"
android:layout_height="fill_parent"> android:layout_height="fill_parent">
<include
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="@layout/title">
</include>
<LinearLayout <LinearLayout
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_width="fill_parent"

View File

@@ -1,32 +1,101 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:background="@android:drawable/title_bar">
<LinearLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical"> android:layout_gravity="center_vertical">
<TextView <TextView
style="?android:attr/windowTitleStyle"
android:id="@+id/white_clock" android:id="@+id/white_clock"
android:layout_weight="1" style="?android:attr/windowTitleStyle"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:gravity="left" android:layout_height="wrap_content"
android:layout_height="wrap_content"> android:layout_weight="1"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="left|center_vertical"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true">
</TextView> </TextView>
<TextView <TextView
style="?android:attr/windowTitleStyle"
android:id="@+id/title_text" android:id="@+id/title_text"
android:layout_weight="1" style="?android:attr/windowTitleStyle"
android:text="@string/app_name"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:gravity="center" android:layout_height="wrap_content"
android:layout_height="wrap_content"> android:layout_weight="1"
android:gravity="center|center_vertical"
android:text="@string/app_name">
</TextView> </TextView>
<TextView <TextView
style="?android:attr/windowTitleStyle"
android:id="@+id/black_clock" android:id="@+id/black_clock"
android:layout_weight="1" style="?android:attr/windowTitleStyle"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:gravity="right" android:layout_height="match_parent"
android:layout_height="wrap_content"> android:layout_weight="1"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="right|center_vertical"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true">
</TextView> </TextView>
</LinearLayout> </LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/second_title_line"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical">
<TextView
android:id="@+id/white_pieces"
style="?android:attr/windowTitleStyle"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center|center_vertical"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold">
</TextView>
<TextView
android:id="@+id/title_text_summary"
style="?android:attr/windowTitleStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center|center_vertical"
android:text="">
</TextView>
<TextView
android:id="@+id/black_pieces"
style="?android:attr/windowTitleStyle"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center|center_vertical"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold">
</TextView>
</LinearLayout>
</LinearLayout>

View File

@@ -200,6 +200,8 @@ you are not actively using the program.\
<string name="start_new_game">Start New Game?</string> <string name="start_new_game">Start New Game?</string>
<string name="strength_cuckoo_hint">Use the CuckooChess engine for even lower strength.</string> <string name="strength_cuckoo_hint">Use the CuckooChess engine for even lower strength.</string>
<string name="piece_names">P N B R Q K</string> <string name="piece_names">P N B R Q K</string>
<string name="material_diff_summary">Displays an additional subtitle for captured pieces</string>
<string name="material_diff_title">Show Material Difference</string>
<string name="err_too_few_spaces">Too few spaces</string> <string name="err_too_few_spaces">Too few spaces</string>
<string name="err_invalid_piece">Invalid piece</string> <string name="err_invalid_piece">Invalid piece</string>
<string name="err_invalid_side">Invalid side</string> <string name="err_invalid_side">Invalid side</string>

View File

@@ -196,6 +196,11 @@
android:entries="@array/viewPieceType_texts" android:entries="@array/viewPieceType_texts"
android:defaultValue="@string/viewPieceType_default"> android:defaultValue="@string/viewPieceType_default">
</ListPreference> </ListPreference>
<CheckBoxPreference
android:key="materialDiff"
android:summary="@string/material_diff_summary"
android:title="@string/material_diff_title" >
</CheckBoxPreference>
<PreferenceScreen <PreferenceScreen
android:key="buttonSettings" android:key="buttonSettings"
android:title="@string/prefs_buttonSettings_title" android:title="@string/prefs_buttonSettings_title"

View File

@@ -140,9 +140,9 @@ public class ChessBoardPlay extends ChessBoard {
int p = pos.getPiece(sq); int p = pos.getPiece(sq);
if (myColor(p)) { if (myColor(p)) {
String msg = getContext().getString(R.string.piece_can_not_be_moved); String msg = getContext().getString(R.string.piece_can_not_be_moved);
boolean localized = (pgnOptions != null) && int pieceType = (pgnOptions == null) ? PGNOptions.PT_LOCAL
(pgnOptions.view.pieceType != PGNOptions.PT_ENGLISH); : pgnOptions.view.pieceType;
msg += ": " + TextIO.pieceAndSquareToString(localized, p, sq); msg += ": " + TextIO.pieceAndSquareToString(pieceType, p, sq);
Toast.makeText(getContext(), msg, Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), msg, Toast.LENGTH_SHORT).show();
} }
} }

View File

@@ -1,6 +1,7 @@
/* /*
DroidFish - An Android chess program. DroidFish - An Android chess program.
Copyright (C) 2011-2012 Peter Österlund, peterosterlund2@gmail.com Copyright (C) 2011-2012 Peter Österlund, peterosterlund2@gmail.com
Copyright (C) 2012 Leo Mayer
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@@ -47,6 +48,7 @@ import org.petero.droidfish.gamelogic.DroidChessController;
import org.petero.droidfish.gamelogic.ChessParseError; import org.petero.droidfish.gamelogic.ChessParseError;
import org.petero.droidfish.gamelogic.Move; import org.petero.droidfish.gamelogic.Move;
import org.petero.droidfish.gamelogic.Pair; import org.petero.droidfish.gamelogic.Pair;
import org.petero.droidfish.gamelogic.Piece;
import org.petero.droidfish.gamelogic.Position; import org.petero.droidfish.gamelogic.Position;
import org.petero.droidfish.gamelogic.TextIO; import org.petero.droidfish.gamelogic.TextIO;
import org.petero.droidfish.gamelogic.PgnToken; import org.petero.droidfish.gamelogic.PgnToken;
@@ -177,6 +179,8 @@ public class DroidFish extends Activity implements GUIInterface {
private ImageButton modeButton, undoButton, redoButton; private ImageButton modeButton, undoButton, redoButton;
private ButtonActions custom1ButtonActions, custom2ButtonActions, custom3ButtonActions; private ButtonActions custom1ButtonActions, custom2ButtonActions, custom3ButtonActions;
private TextView whiteTitleText, blackTitleText, engineTitleText; private TextView whiteTitleText, blackTitleText, engineTitleText;
private View secondTitleLine;
private TextView whiteFigText, blackFigText, summaryTitleText;
SharedPreferences settings; SharedPreferences settings;
@@ -187,6 +191,7 @@ public class DroidFish extends Activity implements GUIInterface {
private MediaPlayer moveSound; private MediaPlayer moveSound;
private boolean vibrateEnabled; private boolean vibrateEnabled;
private boolean animateMoves; private boolean animateMoves;
private boolean showMaterialDiff;
private final static String bookDir = "DroidFish"; private final static String bookDir = "DroidFish";
private final static String pgnDir = "DroidFish" + File.separator + "pgn"; private final static String pgnDir = "DroidFish" + File.separator + "pgn";
@@ -357,8 +362,10 @@ public class DroidFish extends Activity implements GUIInterface {
custom3ButtonActions = new ButtonActions("custom3", CUSTOM3_BUTTON_DIALOG, custom3ButtonActions = new ButtonActions("custom3", CUSTOM3_BUTTON_DIALOG,
R.string.select_action); R.string.select_action);
figNotation = Typeface.createFromAsset(getAssets(), "fonts/DroidFishChessNotationDark.otf");
setPieceNames(PGNOptions.PT_LOCAL); setPieceNames(PGNOptions.PT_LOCAL);
initUI(true); requestWindowFeature(Window.FEATURE_NO_TITLE);
initUI();
gameTextListener = new PgnScreenText(pgnOptions); gameTextListener = new PgnScreenText(pgnOptions);
if (ctrl != null) if (ctrl != null)
@@ -393,10 +400,17 @@ public class DroidFish extends Activity implements GUIInterface {
} }
} }
// Unicode code points for chess pieces
private static final String figurinePieceNames = Piece.NOTATION_PAWN + " " +
Piece.NOTATION_KNIGHT + " " +
Piece.NOTATION_BISHOP + " " +
Piece.NOTATION_ROOK + " " +
Piece.NOTATION_QUEEN + " " +
Piece.NOTATION_KING;
private final void setPieceNames(int pieceType) { private final void setPieceNames(int pieceType) {
if (pieceType == PGNOptions.PT_FIGURINE) { if (pieceType == PGNOptions.PT_FIGURINE) {
// Unicode code points for chess pieces TextIO.setPieceNames(figurinePieceNames);
TextIO.setPieceNames("\u2659 \u2658 \u2657 \u2656 \u2655 \u2654");
} else { } else {
TextIO.setPieceNames(getString(R.string.piece_names)); TextIO.setPieceNames(getString(R.string.piece_names));
} }
@@ -481,7 +495,7 @@ public class DroidFish extends Activity implements GUIInterface {
super.onConfigurationChanged(newConfig); super.onConfigurationChanged(newConfig);
ChessBoardPlay oldCB = cb; ChessBoardPlay oldCB = cb;
String statusStr = status.getText().toString(); String statusStr = status.getText().toString();
initUI(false); initUI();
readPrefs(); readPrefs();
cb.cursorX = oldCB.cursorX; cb.cursorX = oldCB.cursorX;
cb.cursorY = oldCB.cursorY; cb.cursorY = oldCB.cursorY;
@@ -496,20 +510,35 @@ public class DroidFish extends Activity implements GUIInterface {
setStatusString(statusStr); setStatusString(statusStr);
moveListUpdated(); moveListUpdated();
updateThinkingInfo(); updateThinkingInfo();
ctrl.updateRemainingTime();
ctrl.updateMaterialDiffList();
} }
private final void initUI(boolean initTitle) { private final void initUI() {
if (initTitle)
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
Configuration config = getResources().getConfiguration(); Configuration config = getResources().getConfiguration();
// The Android app title is removed with the style, but remains
// individually in the Layout cause we need it to have in 2 lines +
// landscape and portrait differ quite much
boolean leftHanded = this.leftHanded && (config.orientation == Configuration.ORIENTATION_LANDSCAPE); boolean leftHanded = this.leftHanded && (config.orientation == Configuration.ORIENTATION_LANDSCAPE);
setContentView(leftHanded ? R.layout.main_left_handed : R.layout.main); setContentView(leftHanded ? R.layout.main_left_handed : R.layout.main);
if (initTitle) {
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title); // title lines need to be regenerated every time due to layout changes (rotations)
secondTitleLine = findViewById(R.id.second_title_line);
whiteTitleText = (TextView)findViewById(R.id.white_clock); whiteTitleText = (TextView)findViewById(R.id.white_clock);
whiteTitleText.setSelected(true);
blackTitleText = (TextView)findViewById(R.id.black_clock); blackTitleText = (TextView)findViewById(R.id.black_clock);
blackTitleText.setSelected(true);
engineTitleText = (TextView)findViewById(R.id.title_text); engineTitleText = (TextView)findViewById(R.id.title_text);
} whiteFigText = (TextView)findViewById(R.id.white_pieces);
whiteFigText.setTypeface(figNotation);
whiteFigText.setSelected(true);
whiteFigText.setTextColor(whiteTitleText.getTextColors());
blackFigText = (TextView)findViewById(R.id.black_pieces);
blackFigText.setTypeface(figNotation);
blackFigText.setSelected(true);
blackFigText.setTextColor(blackTitleText.getTextColors());
summaryTitleText = (TextView)findViewById(R.id.title_text_summary);
status = (TextView)findViewById(R.id.status); status = (TextView)findViewById(R.id.status);
moveListScroll = (ScrollView)findViewById(R.id.scrollView); moveListScroll = (ScrollView)findViewById(R.id.scrollView);
moveList = (TextView)findViewById(R.id.moveList); moveList = (TextView)findViewById(R.id.moveList);
@@ -778,6 +807,7 @@ public class DroidFish extends Activity implements GUIInterface {
int movesPerSession = getIntSetting("movesPerSession", 60); int movesPerSession = getIntSetting("movesPerSession", 60);
int timeIncrement = getIntSetting("timeIncrement", 0); int timeIncrement = getIntSetting("timeIncrement", 0);
ctrl.setTimeLimit(timeControl, movesPerSession, timeIncrement); ctrl.setTimeLimit(timeControl, movesPerSession, timeIncrement);
setSummaryTitle();
scrollSensitivity = Float.parseFloat(settings.getString("scrollSensitivity", "2")); scrollSensitivity = Float.parseFloat(settings.getString("scrollSensitivity", "2"));
invertScrollDirection = settings.getBoolean("invertScrollDirection", false); invertScrollDirection = settings.getBoolean("invertScrollDirection", false);
@@ -788,7 +818,6 @@ public class DroidFish extends Activity implements GUIInterface {
setWakeLock(useWakeLock); setWakeLock(useWakeLock);
int fontSize = getIntSetting("fontSize", 12); int fontSize = getIntSetting("fontSize", 12);
figNotation = Typeface.createFromAsset(getAssets(), "fonts/DroidFishChessNotationDark.otf");
int statusFontSize = fontSize; int statusFontSize = fontSize;
Configuration config = getResources().getConfiguration(); Configuration config = getResources().getConfiguration();
if (config.orientation == Configuration.ORIENTATION_PORTRAIT) if (config.orientation == Configuration.ORIENTATION_PORTRAIT)
@@ -853,6 +882,9 @@ public class DroidFish extends Activity implements GUIInterface {
// update the typeset in case of a change anyway, cause it could occur // update the typeset in case of a change anyway, cause it could occur
// as well in rotation // as well in rotation
setFigurineNotation(pgnOptions.view.pieceType == PGNOptions.PT_FIGURINE, fontSize); setFigurineNotation(pgnOptions.view.pieceType == PGNOptions.PT_FIGURINE, fontSize);
showMaterialDiff = settings.getBoolean("materialDiff", false);
secondTitleLine.setVisibility(showMaterialDiff ? View.VISIBLE : View.GONE);
} }
/** /**
@@ -953,6 +985,25 @@ public class DroidFish extends Activity implements GUIInterface {
} }
} }
/** Update center field in second header line. */
private final void setSummaryTitle() {
int[] tmpInfo = ctrl.getTimeLimit();
StringBuilder sb = new StringBuilder();
int tc = tmpInfo[0];
int mps = tmpInfo[1];
int inc = tmpInfo[2];
if (mps > 0) {
sb.append(mps);
sb.append(" / ");
}
sb.append(timeToString(tc));
if ((inc > 0) || (mps <= 0)) {
sb.append(" + ");
sb.append(tmpInfo[2] / 1000);
}
summaryTitleText.setText(sb.toString());
}
@Override @Override
public void updateEngineTitle() { public void updateEngineTitle() {
String engine = settings.getString("engine", "stockfish"); String engine = settings.getString("engine", "stockfish");
@@ -960,6 +1011,13 @@ public class DroidFish extends Activity implements GUIInterface {
setEngineTitle(engine, strength); setEngineTitle(engine, strength);
} }
@Override
public void updateMaterialDifferenceTitle(CharSequence whitePieces,
CharSequence blackPieces) {
whiteFigText.setText(whitePieces);
blackFigText.setText(blackPieces);
}
private final void setFullScreenMode(boolean fullScreenMode) { private final void setFullScreenMode(boolean fullScreenMode) {
WindowManager.LayoutParams attrs = getWindow().getAttributes(); WindowManager.LayoutParams attrs = getWindow().getAttributes();
if (fullScreenMode) { if (fullScreenMode) {

View File

@@ -80,6 +80,10 @@ public interface GUIInterface {
/** Update engine title text. */ /** Update engine title text. */
public void updateEngineTitle(); public void updateEngineTitle();
/** Update title with the material difference. */
public void updateMaterialDifferenceTitle(CharSequence whitePieces,
CharSequence blackPieces);
/** Report a move made that is a candidate for GUI animation. */ /** Report a move made that is a candidate for GUI animation. */
public void setAnimMove(Position sourcePos, Move move, boolean forward); public void setAnimMove(Position sourcePos, Move move, boolean forward);

View File

@@ -111,6 +111,17 @@ public class DroidChessController {
game.timeController.setTimeControl(timeControl, movesPerSession, timeIncrement); game.timeController.setTimeControl(timeControl, movesPerSession, timeIncrement);
} }
/**
* @return Array containing time control, moves per session and time increment.
*/
public final int[] getTimeLimit() {
int[] ret = new int[3];
ret[0] = timeControl;
ret[1] = movesPerSession;
ret[2] = timeIncrement;
return ret;
}
/** The chess clocks are stopped when the GUI is paused. */ /** The chess clocks are stopped when the GUI is paused. */
public final synchronized void setGuiPaused(boolean paused) { public final synchronized void setGuiPaused(boolean paused) {
guiPaused = paused; guiPaused = paused;
@@ -1020,6 +1031,25 @@ public class DroidChessController {
gui.setPosition(game.currPos(), sb.toString(), game.tree.variations()); gui.setPosition(game.currPos(), sb.toString(), game.tree.variations());
updateRemainingTime(); updateRemainingTime();
updateMaterialDiffList();
}
public final void updateMaterialDiffList() {
Position pos = game.currPos();
StringBuilder whiteString = new StringBuilder();
StringBuilder blackString = new StringBuilder();
for (int p = Piece.WPAWN; p >= Piece.WQUEEN; p--) {
int diff = pos.nPieces(p) - pos.nPieces(Piece.swapColor(p));
while (diff < 0) {
whiteString.append(Piece.toUniCode(Piece.swapColor(p)));
diff++;
}
while (diff > 0) {
blackString.append(Piece.toUniCode(p));
diff--;
}
}
gui.updateMaterialDifferenceTitle(whiteString, blackString);
} }
private final synchronized void setThinkingInfo(int id, ArrayList<ArrayList<Move>> pvMoves, String pvStr, private final synchronized void setThinkingInfo(int id, ArrayList<ArrayList<Move>> pvMoves, String pvStr,

View File

@@ -1,6 +1,7 @@
/* /*
DroidFish - An Android chess program. DroidFish - An Android chess program.
Copyright (C) 2011 Peter Österlund, peterosterlund2@gmail.com Copyright (C) 2011 Peter Österlund, peterosterlund2@gmail.com
Copyright (C) 2012 Leo Mayer
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@@ -41,6 +42,30 @@ public class Piece {
public static final int nPieceTypes = 13; public static final int nPieceTypes = 13;
// Unicode for color neutral chess pieces
public static final char NOTATION_KING = 0xe050;
public static final char NOTATION_QUEEN = 0xe051;
public static final char NOTATION_ROOK = 0xe052;
public static final char NOTATION_BISHOP = 0xe053;
public static final char NOTATION_KNIGHT = 0xe054;
public static final char NOTATION_PAWN = 0xe055;
// Unicode for white chess pieces
public static final char WHITE_KING = 0x2654;
public static final char WHITE_QUEEN = 0x2655;
public static final char WHITE_ROOK = 0x2656;
public static final char WHITE_BISHOP = 0x2657;
public static final char WHITE_KNIGHT = 0x2658;
public static final char WHITE_PAWN = 0x2659;
// Unicode for black chess pieces
public static final char BLACK_KING = 0x265A;
public static final char BLACK_QUEEN = 0x265B;
public static final char BLACK_ROOK = 0x265C;
public static final char BLACK_BISHOP = 0x265D;
public static final char BLACK_KNIGHT = 0x265E;
public static final char BLACK_PAWN = 0x265F;
/** /**
* Return true if p is a white piece, false otherwise. * Return true if p is a white piece, false otherwise.
* Note that if p is EMPTY, an unspecified value is returned. * Note that if p is EMPTY, an unspecified value is returned.
@@ -59,4 +84,10 @@ public class Piece {
return EMPTY; return EMPTY;
return isWhite(pType) ? pType + (BKING - WKING) : pType - (BKING - WKING); return isWhite(pType) ? pType + (BKING - WKING) : pType - (BKING - WKING);
} }
/** Converts the piece into a character for the material diff. */
public final static char toUniCode(int p) {
// As we assume, the coding of the pieces is sequential, lets do some math.
return (char)(WHITE_KING + p - 1);
}
} }

View File

@@ -21,6 +21,7 @@ package org.petero.droidfish.gamelogic;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.petero.droidfish.PGNOptions;
import org.petero.droidfish.R; import org.petero.droidfish.R;
@@ -729,14 +730,19 @@ public class TextIO {
} }
/** Convert a piece and a square to a string, such as Nf3. */ /** Convert a piece and a square to a string, such as Nf3. */
public final static String pieceAndSquareToString(boolean localized, int p, int sq) { public final static String pieceAndSquareToString(int currentPieceType, int p, int sq) {
String ret; StringBuilder ret = new StringBuilder();
if (currentPieceType == PGNOptions.PT_FIGURINE) {
ret.append(Piece.toUniCode(p));
} else {
boolean localized = (currentPieceType != PGNOptions.PT_ENGLISH);
if ((p == Piece.WPAWN) || (p == Piece.BPAWN)) if ((p == Piece.WPAWN) || (p == Piece.BPAWN))
ret = localized ? pieceNames[0] : "P"; ret.append(localized ? pieceNames[0] : "P");
else else
ret = localized ? pieceToCharLocalized(p) : pieceToChar(p); ret.append(localized ? pieceToCharLocalized(p) : pieceToChar(p));
ret += squareToString(sq); }
return ret; ret.append(squareToString(sq));
return ret.toString();
} }
private final static String pieceToChar(int p) { private final static String pieceToChar(int p) {