mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-12-20 04:32:17 +01:00
DroidFish: Moved computation of material difference to the Util class, so that it can be reused by the EditBoard activity.
This commit is contained in:
@@ -1012,10 +1012,9 @@ public class DroidFish extends Activity implements GUIInterface {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMaterialDifferenceTitle(CharSequence whitePieces,
|
||||
CharSequence blackPieces) {
|
||||
whiteFigText.setText(whitePieces);
|
||||
blackFigText.setText(blackPieces);
|
||||
public void updateMaterialDifferenceTitle(Util.MaterialDiff diff) {
|
||||
whiteFigText.setText(diff.white);
|
||||
blackFigText.setText(diff.black);
|
||||
}
|
||||
|
||||
private final void setFullScreenMode(boolean fullScreenMode) {
|
||||
|
||||
@@ -81,8 +81,7 @@ public interface GUIInterface {
|
||||
public void updateEngineTitle();
|
||||
|
||||
/** Update title with the material difference. */
|
||||
public void updateMaterialDifferenceTitle(CharSequence whitePieces,
|
||||
CharSequence blackPieces);
|
||||
public void updateMaterialDifferenceTitle(Util.MaterialDiff diff);
|
||||
|
||||
/** Report a move made that is a candidate for GUI animation. */
|
||||
public void setAnimMove(Position sourcePos, Move move, boolean forward);
|
||||
|
||||
@@ -7,6 +7,9 @@ import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.petero.droidfish.gamelogic.Piece;
|
||||
import org.petero.droidfish.gamelogic.Position;
|
||||
|
||||
import android.os.Build;
|
||||
|
||||
public final class Util {
|
||||
@@ -38,4 +41,32 @@ public final class Util {
|
||||
inBuf.close();
|
||||
return ret.toArray(new String[ret.size()]);
|
||||
}
|
||||
|
||||
/** Represent materiel difference as two unicode strings. */
|
||||
public final static class MaterialDiff {
|
||||
public CharSequence white;
|
||||
public CharSequence black;
|
||||
MaterialDiff(CharSequence w, CharSequence b) {
|
||||
white = w;
|
||||
black = b;
|
||||
}
|
||||
}
|
||||
|
||||
/** Compute material difference for a position. */
|
||||
public static MaterialDiff getMaterialDiff(Position pos) {
|
||||
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--;
|
||||
}
|
||||
}
|
||||
return new MaterialDiff(whiteString, blackString);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1035,21 +1035,7 @@ public class DroidChessController {
|
||||
}
|
||||
|
||||
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);
|
||||
gui.updateMaterialDifferenceTitle(Util.getMaterialDiff(game.currPos()));
|
||||
}
|
||||
|
||||
private final synchronized void setThinkingInfo(int id, ArrayList<ArrayList<Move>> pvMoves, String pvStr,
|
||||
|
||||
Reference in New Issue
Block a user