diff --git a/DroidFish/res/values/strings.xml b/DroidFish/res/values/strings.xml index 9b94ebe..01b1063 100644 --- a/DroidFish/res/values/strings.xml +++ b/DroidFish/res/values/strings.xml @@ -337,4 +337,18 @@ you are not actively using the program.\ Before: Move: After: + White\'s move + Black\'s move + ponder + thinking + analyzing + Game over, white mates! + Game over, black mates! + Game over, draw by stalemate! + Game over, draw by repetition! + Game over, draw by 50 move rule! + Game over, draw by impossibility of mate! + Game over, draw by agreement! + Game over, white resigns! + Game over, black resigns! diff --git a/DroidFish/src/org/petero/droidfish/DroidFish.java b/DroidFish/src/org/petero/droidfish/DroidFish.java index db3ed48..18daa92 100644 --- a/DroidFish/src/org/petero/droidfish/DroidFish.java +++ b/DroidFish/src/org/petero/droidfish/DroidFish.java @@ -112,7 +112,6 @@ public class DroidFish extends Activity implements GUIInterface { // FIXME!!! Online play on FICS // FIXME!!! Add chess960 support - // FIXME!!! Make program translatable // FIXME!!! Implement "hint" feature // FIXME!!! Don't send "stop" command when engine is already stopped @@ -800,7 +799,60 @@ public class DroidFish extends Activity implements GUIInterface { } @Override - public void setStatusString(String str) { + public void setStatus(GameStatus s) { + String str; + switch (s.state) { + case ALIVE: + str = Integer.valueOf(s.moveNr).toString(); + if (s.white) + str += ". " + getString(R.string.whites_move); + else + str += "... " + getString(R.string.blacks_move); + if (s.ponder) str += " (" + getString(R.string.ponder) + ")"; + if (s.thinking) str += " (" + getString(R.string.thinking) + ")"; + if (s.analyzing) str += " (" + getString(R.string.analyzing) + ")"; + break; + case WHITE_MATE: + str = getString(R.string.white_mate); + break; + case BLACK_MATE: + str = getString(R.string.black_mate); + break; + case WHITE_STALEMATE: + case BLACK_STALEMATE: + str = getString(R.string.stalemate); + break; + case DRAW_REP: { + str = getString(R.string.draw_rep); + if (s.drawInfo.length() > 0) + str = str + " [" + s.drawInfo + "]"; + break; + } + case DRAW_50: { + str = getString(R.string.draw_50); + if (s.drawInfo.length() > 0) + str = str + " [" + s.drawInfo + "]"; + break; + } + case DRAW_NO_MATE: + str = getString(R.string.draw_no_mate); + break; + case DRAW_AGREE: + str = getString(R.string.draw_agree); + break; + case RESIGN_WHITE: + str = getString(R.string.resign_white); + break; + case RESIGN_BLACK: + str = getString(R.string.resign_black); + break; + default: + throw new RuntimeException(); + } + setStatusString(str); + } + + private final void setStatusString(String str) { status.setText(str); } diff --git a/DroidFish/src/org/petero/droidfish/GUIInterface.java b/DroidFish/src/org/petero/droidfish/GUIInterface.java index 8333e29..0b74f4f 100644 --- a/DroidFish/src/org/petero/droidfish/GUIInterface.java +++ b/DroidFish/src/org/petero/droidfish/GUIInterface.java @@ -21,10 +21,10 @@ package org.petero.droidfish; import java.util.ArrayList; import java.util.List; +import org.petero.droidfish.gamelogic.Game; import org.petero.droidfish.gamelogic.Move; import org.petero.droidfish.gamelogic.Position; - /** Interface between the GUI and the ChessController. */ public interface GUIInterface { @@ -34,8 +34,18 @@ public interface GUIInterface { /** Mark square i as selected. Set to -1 to clear selection. */ public void setSelection(int sq); + final static class GameStatus { + public Game.GameState state = Game.GameState.ALIVE; + public int moveNr = 0; + public String drawInfo = ""; // Move required to claim draw, or empty string + public boolean white = false; + public boolean ponder = false; + public boolean thinking = false; + public boolean analyzing = false; + } + /** Set the status text. */ - public void setStatusString(String str); + public void setStatus(GameStatus status); /** Update the list of moves. */ public void moveListUpdated(); diff --git a/DroidFish/src/org/petero/droidfish/gamelogic/DroidChessController.java b/DroidFish/src/org/petero/droidfish/gamelogic/DroidChessController.java index 648d4c3..c34b311 100644 --- a/DroidFish/src/org/petero/droidfish/gamelogic/DroidChessController.java +++ b/DroidFish/src/org/petero/droidfish/gamelogic/DroidChessController.java @@ -614,17 +614,23 @@ public class DroidChessController { } final private void updateGUI() { - String str; - if (game.getGameState() == Game.GameState.ALIVE) { - str = Integer.valueOf(game.currPos().fullMoveCounter).toString(); - str += game.currPos().whiteMove ? ". White's move" : "... Black's move"; + GUIInterface.GameStatus s = new GUIInterface.GameStatus(); + s.state = game.getGameState(); + if (s.state == Game.GameState.ALIVE) { + s.moveNr = game.currPos().fullMoveCounter; + s.white = game.currPos().whiteMove; if (computerThread != null) - str += humansTurn() ? " (ponder)" : " (thinking)"; - if (analysisThread != null) str += " (analyzing)"; + if (humansTurn()) + s.ponder = true; + else + s.thinking = true; + if (analysisThread != null) + s.analyzing = true; } else { - str = game.getGameStateString(); + if ((s.state == GameState.DRAW_REP) || (s.state == GameState.DRAW_50)) + s.drawInfo = game.getDrawInfo(); } - gui.setStatusString(str); + gui.setStatus(s); updateMoveList(); StringBuilder sb = new StringBuilder(); diff --git a/DroidFish/src/org/petero/droidfish/gamelogic/Game.java b/DroidFish/src/org/petero/droidfish/gamelogic/Game.java index d7b2feb..db28395 100644 --- a/DroidFish/src/org/petero/droidfish/gamelogic/Game.java +++ b/DroidFish/src/org/petero/droidfish/gamelogic/Game.java @@ -200,46 +200,8 @@ public class Game { } } - public final String getGameStateString() { - switch (getGameState()) { - case ALIVE: - return ""; - case WHITE_MATE: - return "Game over, white mates!"; - case BLACK_MATE: - return "Game over, black mates!"; - case WHITE_STALEMATE: - case BLACK_STALEMATE: - return "Game over, draw by stalemate!"; - case DRAW_REP: - { - String ret = "Game over, draw by repetition!"; - String drawInfo = tree.getGameStateInfo(); - if (drawInfo.length() > 0) { - ret = ret + " [" + drawInfo+ "]"; - } - return ret; - } - case DRAW_50: - { - String ret = "Game over, draw by 50 move rule!"; - String drawInfo = tree.getGameStateInfo(); - if (drawInfo.length() > 0) { - ret = ret + " [" + drawInfo + "]"; - } - return ret; - } - case DRAW_NO_MATE: - return "Game over, draw by impossibility of mate!"; - case DRAW_AGREE: - return "Game over, draw by agreement!"; - case RESIGN_WHITE: - return "Game over, white resigns!"; - case RESIGN_BLACK: - return "Game over, black resigns!"; - default: - throw new RuntimeException(); - } + public final String getDrawInfo() { + return tree.getGameStateInfo(); } /**