From bdb55f5677b79426e2e18cc94b04f84c8a6ed272 Mon Sep 17 00:00:00 2001 From: Peter Osterlund Date: Sat, 24 Dec 2011 08:00:07 +0000 Subject: [PATCH] DroidFish: Made it possible to hide engine statistics. --- DroidFish/res/values/strings.xml | 2 ++ .../src/org/petero/droidfish/DroidFish.java | 32 ++++++++++++++++--- .../org/petero/droidfish/GUIInterface.java | 3 +- .../gamelogic/DroidChessController.java | 11 +++---- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/DroidFish/res/values/strings.xml b/DroidFish/res/values/strings.xml index 0612788..d37278d 100644 --- a/DroidFish/res/values/strings.xml +++ b/DroidFish/res/values/strings.xml @@ -365,6 +365,8 @@ you are not actively using the program.\ Add Analysis Fewer Variations More Variations + Hide statistics + Show statistics Heavy CPU usage Background processing DroidFish is using a lot of CPU power diff --git a/DroidFish/src/org/petero/droidfish/DroidFish.java b/DroidFish/src/org/petero/droidfish/DroidFish.java index 7e71764..58c0fec 100644 --- a/DroidFish/src/org/petero/droidfish/DroidFish.java +++ b/DroidFish/src/org/petero/droidfish/DroidFish.java @@ -132,6 +132,7 @@ public class DroidFish extends Activity implements GUIInterface { private ChessBoard cb; private static DroidChessController ctrl = null; private boolean mShowThinking; + private boolean mShowStats; private boolean mWhiteBasedScores; private boolean mShowBookHints; private int maxNumArrows; @@ -532,6 +533,7 @@ public class DroidFish extends Activity implements GUIInterface { cb.oneTouchMoves = settings.getBoolean("oneTouchMoves", false); mShowThinking = settings.getBoolean("showThinking", false); + mShowStats = settings.getBoolean("showStats", true); mWhiteBasedScores = settings.getBoolean("whiteBasedScores", false); maxNumArrows = getIntSetting("thinkingArrows", 2); mShowBookHints = settings.getBoolean("bookHints", false); @@ -912,7 +914,8 @@ public class DroidFish extends Activity implements GUIInterface { updateThinkingInfo(); } - private String thinkingStr = ""; + private String thinkingStr1 = ""; + private String thinkingStr2 = ""; private String bookInfoStr = ""; private String variantStr = ""; private ArrayList> pvMoves = new ArrayList>(); @@ -920,9 +923,10 @@ public class DroidFish extends Activity implements GUIInterface { private List variantMoves = null; @Override - public void setThinkingInfo(String pvStr, String bookInfo, + public void setThinkingInfo(String pvStr, String statStr, String bookInfo, ArrayList> pvMoves, List bookMoves) { - thinkingStr = pvStr; + thinkingStr1 = pvStr; + thinkingStr2 = statStr; bookInfoStr = bookInfo; this.pvMoves = pvMoves; this.bookMoves = bookMoves; @@ -941,7 +945,9 @@ public class DroidFish extends Activity implements GUIInterface { { String s = ""; if (mShowThinking || gameMode.analysisMode()) { - s = thinkingStr; + s = thinkingStr1; + if (mShowStats) + s += "\n" + thinkingStr2; } thinking.setText(s, TextView.BufferType.SPANNABLE); if (s.length() > 0) thinkingEmpty = false; @@ -1508,6 +1514,8 @@ public class DroidFish extends Activity implements GUIInterface { final int ADD_ANALYSIS = 0; final int MULTIPV_DEC = 1; final int MULTIPV_INC = 2; + final int HIDE_STATISTICS = 3; + final int SHOW_STATISTICS = 4; List lst = new ArrayList(); List actions = new ArrayList(); lst.add(getString(R.string.add_analysis)); actions.add(ADD_ANALYSIS); @@ -1520,6 +1528,11 @@ public class DroidFish extends Activity implements GUIInterface { if (numPV < maxPV) { lst.add(getString(R.string.more_variations)); actions.add(MULTIPV_INC); } + if (mShowStats) { + lst.add(getString(R.string.hide_statistics)); actions.add(HIDE_STATISTICS); + } else { + lst.add(getString(R.string.show_statistics)); actions.add(SHOW_STATISTICS); + } } final List finalActions = actions; AlertDialog.Builder builder = new AlertDialog.Builder(this); @@ -1529,7 +1542,7 @@ public class DroidFish extends Activity implements GUIInterface { switch (finalActions.get(item)) { case ADD_ANALYSIS: { ArrayList> pvMovesTmp = pvMoves; - String[] pvStrs = thinkingStr.split("\n"); + String[] pvStrs = thinkingStr1.split("\n"); for (int i = 0; i < pvMovesTmp.size(); i++) { ArrayList pv = pvMovesTmp.get(i); StringBuilder preComment = new StringBuilder(); @@ -1554,6 +1567,15 @@ public class DroidFish extends Activity implements GUIInterface { case MULTIPV_INC: ctrl.setMultiPVMode(numPV + 1); break; + case HIDE_STATISTICS: + case SHOW_STATISTICS: { + mShowStats = finalActions.get(item) == SHOW_STATISTICS; + Editor editor = settings.edit(); + editor.putBoolean("showStats", mShowStats); + editor.commit(); + updateThinkingInfo(); + break; + } } } }); diff --git a/DroidFish/src/org/petero/droidfish/GUIInterface.java b/DroidFish/src/org/petero/droidfish/GUIInterface.java index 0b74f4f..5cd68b9 100644 --- a/DroidFish/src/org/petero/droidfish/GUIInterface.java +++ b/DroidFish/src/org/petero/droidfish/GUIInterface.java @@ -51,7 +51,8 @@ public interface GUIInterface { public void moveListUpdated(); /** Update the computer thinking information. */ - public void setThinkingInfo(String pvStr, String bookInfo, ArrayList> pvMoves, List bookMoves); + public void setThinkingInfo(String pvStr, String statStr, String bookInfo, + ArrayList> pvMoves, List bookMoves); /** Ask what to promote a pawn to. Should call reportPromotePiece() when done. */ public void requestPromotePiece(); diff --git a/DroidFish/src/org/petero/droidfish/gamelogic/DroidChessController.java b/DroidFish/src/org/petero/droidfish/gamelogic/DroidChessController.java index b105513..69e8df0 100644 --- a/DroidFish/src/org/petero/droidfish/gamelogic/DroidChessController.java +++ b/DroidFish/src/org/petero/droidfish/gamelogic/DroidChessController.java @@ -96,12 +96,11 @@ public class DroidChessController { } buf.append(pvi.pvStr); - buf.append("\n"); - } - if (currDepth > 0) { - buf.append(String.format("d:%d %d:%s t:%.2f n:%d nps:%d", currDepth, - currMoveNr, currMove, currTime / 1000.0, currNodes, currNps)); } + final String statStr = (currDepth > 0) ? + String.format("d:%d %d:%s t:%.2f n:%d nps:%d", currDepth, currMoveNr, currMove, + currTime / 1000.0, currNodes, currNps) + : ""; final String newPV = buf.toString(); final String newBookInfo = bookInfo; final SearchStatus localSS = ss; @@ -112,7 +111,7 @@ public class DroidChessController { ArrayList> pvMoves = new ArrayList>(); for (int i = 0; i < pvInfoV.size(); i++) pvMoves.add(pvInfoV.get(i).pv); - gui.setThinkingInfo(newPV, newBookInfo, pvMoves, bookMoves); + gui.setThinkingInfo(newPV, statStr, newBookInfo, pvMoves, bookMoves); } }); }