DroidFish: Don't clear hash table inside the Game class.

This commit is contained in:
Peter Osterlund
2011-12-28 12:00:08 +00:00
parent af932e3a54
commit b78c6e7849
4 changed files with 26 additions and 37 deletions

View File

@@ -1751,11 +1751,7 @@ public class DroidFish extends Activity implements GUIInterface {
@Override @Override
public void requestPromotePiece() { public void requestPromotePiece() {
runOnUIThread(new Runnable() { showDialog(PROMOTE_DIALOG);
public void run() {
showDialog(PROMOTE_DIALOG);
}
});
} }
@Override @Override

View File

@@ -72,7 +72,7 @@ public class DroidChessController {
} }
/** Start a new game. */ /** Start a new game. */
public final void newGame(GameMode gameMode) { public final synchronized void newGame(GameMode gameMode) {
ss.searchResultWanted = false; ss.searchResultWanted = false;
boolean updateGui = stopComputerThinking(); boolean updateGui = stopComputerThinking();
updateGui |= stopAnalysis(); updateGui |= stopAnalysis();
@@ -85,13 +85,14 @@ public class DroidChessController {
computerPlayer.setListener(listener); computerPlayer.setListener(listener);
computerPlayer.setBookOptions(bookOptions); computerPlayer.setBookOptions(bookOptions);
} }
game = new Game(computerPlayer, gameTextListener, timeControl, movesPerSession, timeIncrement); game = new Game(gameTextListener, timeControl, movesPerSession, timeIncrement);
computerPlayer.clearTT();
setPlayerNames(game); setPlayerNames(game);
updateGameMode(); updateGameMode();
} }
/** Start playing a new game. Should be called after newGame(). */ /** Start playing a new game. Should be called after newGame(). */
public final void startGame() { public final synchronized void startGame() {
updateComputeThreads(true); updateComputeThreads(true);
setSelection(); setSelection();
updateGUI(); updateGUI();
@@ -108,13 +109,13 @@ public class DroidChessController {
} }
/** The chess clocks are stopped when the GUI is paused. */ /** The chess clocks are stopped when the GUI is paused. */
public final void setGuiPaused(boolean paused) { public final synchronized void setGuiPaused(boolean paused) {
guiPaused = paused; guiPaused = paused;
updateGameMode(); updateGameMode();
} }
/** Set game mode. */ /** Set game mode. */
public final void setGameMode(GameMode newMode) { public final synchronized void setGameMode(GameMode newMode) {
if (!gameMode.equals(newMode)) { if (!gameMode.equals(newMode)) {
if (newMode.humansTurn(game.currPos().whiteMove)) if (newMode.humansTurn(game.currPos().whiteMove))
ss.searchResultWanted = false; ss.searchResultWanted = false;
@@ -166,35 +167,35 @@ public class DroidChessController {
} }
/** Notify controller that preferences has changed. */ /** Notify controller that preferences has changed. */
public final void prefsChanged() { public final synchronized void prefsChanged() {
updateBookHints(); updateBookHints();
updateMoveList(); updateMoveList();
listener.prefsChanged(); listener.prefsChanged();
} }
/** De-serialize from byte array. */ /** De-serialize from byte array. */
public final void fromByteArray(byte[] data) { public final synchronized void fromByteArray(byte[] data) {
game.fromByteArray(data); game.fromByteArray(data);
} }
/** Serialize to byte array. */ /** Serialize to byte array. */
public final byte[] toByteArray() { public final synchronized byte[] toByteArray() {
return game.tree.toByteArray(); return game.tree.toByteArray();
} }
/** Return FEN string corresponding to a current position. */ /** Return FEN string corresponding to a current position. */
public final String getFEN() { public final synchronized String getFEN() {
return TextIO.toFEN(game.tree.currentPos); return TextIO.toFEN(game.tree.currentPos);
} }
/** Convert current game to PGN format. */ /** Convert current game to PGN format. */
public final String getPGN() { public final synchronized String getPGN() {
return game.tree.toPGN(pgnOptions); return game.tree.toPGN(pgnOptions);
} }
/** Parse a string as FEN or PGN data. */ /** Parse a string as FEN or PGN data. */
public final void setFENOrPGN(String fenPgn) throws ChessParseError { public final synchronized void setFENOrPGN(String fenPgn) throws ChessParseError {
Game newGame = new Game(null, gameTextListener, timeControl, movesPerSession, timeIncrement); Game newGame = new Game(gameTextListener, timeControl, movesPerSession, timeIncrement);
try { try {
Position pos = TextIO.readFEN(fenPgn); Position pos = TextIO.readFEN(fenPgn);
newGame.setPos(pos); newGame.setPos(pos);
@@ -206,7 +207,8 @@ public class DroidChessController {
} }
ss.searchResultWanted = false; ss.searchResultWanted = false;
game = newGame; game = newGame;
game.setComputerPlayer(computerPlayer); if (computerPlayer != null)
computerPlayer.clearTT();
gameTextListener.clear(); gameTextListener.clear();
updateGameMode(); updateGameMode();
stopAnalysis(); stopAnalysis();

View File

@@ -22,7 +22,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.petero.droidfish.PGNOptions; import org.petero.droidfish.PGNOptions;
import org.petero.droidfish.engine.DroidComputerPlayer;
import org.petero.droidfish.gamelogic.GameTree.Node; import org.petero.droidfish.gamelogic.GameTree.Node;
/** /**
@@ -32,7 +31,6 @@ import org.petero.droidfish.gamelogic.GameTree.Node;
public class Game { public class Game {
boolean pendingDrawOffer; boolean pendingDrawOffer;
GameTree tree; GameTree tree;
private DroidComputerPlayer computerPlayer;
TimeControl timeController; TimeControl timeController;
private boolean gamePaused; private boolean gamePaused;
/** If true, add new moves as mainline moves. */ /** If true, add new moves as mainline moves. */
@@ -40,9 +38,8 @@ public class Game {
PgnToken.PgnTokenReceiver gameTextListener; PgnToken.PgnTokenReceiver gameTextListener;
public Game(DroidComputerPlayer computerPlayer, PgnToken.PgnTokenReceiver gameTextListener, public Game(PgnToken.PgnTokenReceiver gameTextListener,
int timeControl, int movesPerSession, int timeIncrement) { int timeControl, int movesPerSession, int timeIncrement) {
this.computerPlayer = computerPlayer;
this.gameTextListener = gameTextListener; this.gameTextListener = gameTextListener;
tree = new GameTree(gameTextListener); tree = new GameTree(gameTextListener);
timeController = new TimeControl(); timeController = new TimeControl();
@@ -57,10 +54,6 @@ public class Game {
updateTimeControl(true); updateTimeControl(true);
} }
public final void setComputerPlayer(DroidComputerPlayer computerPlayer) {
this.computerPlayer = computerPlayer;
}
public final void setGamePaused(boolean gamePaused) { public final void setGamePaused(boolean gamePaused) {
if (gamePaused != this.gamePaused) { if (gamePaused != this.gamePaused) {
this.gamePaused = gamePaused; this.gamePaused = gamePaused;
@@ -344,8 +337,6 @@ public class Game {
public final void newGame() { public final void newGame() {
tree = new GameTree(gameTextListener); tree = new GameTree(gameTextListener);
if (computerPlayer != null)
computerPlayer.clearTT();
timeController.reset(); timeController.reset();
pendingDrawOffer = false; pendingDrawOffer = false;
updateTimeControl(true); updateTimeControl(true);

View File

@@ -36,7 +36,7 @@ public class GameTest extends TestCase {
* Test of haveDrawOffer method, of class Game. * Test of haveDrawOffer method, of class Game.
*/ */
public void testHaveDrawOffer() { public void testHaveDrawOffer() {
Game game = new Game(null, null, 0, 0, 0); Game game = new Game(null, 0, 0, 0);
assertEquals(false, game.haveDrawOffer()); assertEquals(false, game.haveDrawOffer());
boolean res = game.processString("e4"); boolean res = game.processString("e4");
@@ -124,7 +124,7 @@ public class GameTest extends TestCase {
* Test of draw by 50 move rule, of class Game. * Test of draw by 50 move rule, of class Game.
*/ */
public void testDraw50() throws ChessParseError { public void testDraw50() throws ChessParseError {
Game game = new Game(null, null, 0, 0, 0); Game game = new Game(null, 0, 0, 0);
assertEquals(false, game.haveDrawOffer()); assertEquals(false, game.haveDrawOffer());
boolean res = game.processString("draw 50"); boolean res = game.processString("draw 50");
assertEquals(true, res); assertEquals(true, res);
@@ -179,7 +179,7 @@ public class GameTest extends TestCase {
* Test of draw by repetition, of class Game. * Test of draw by repetition, of class Game.
*/ */
public void testDrawRep() throws ChessParseError { public void testDrawRep() throws ChessParseError {
Game game = new Game(null, null, 0, 0, 0); Game game = new Game(null, 0, 0, 0);
assertEquals(false, game.haveDrawOffer()); assertEquals(false, game.haveDrawOffer());
game.processString("Nc3"); game.processString("Nc3");
game.processString("Nc6"); game.processString("Nc6");
@@ -251,7 +251,7 @@ public class GameTest extends TestCase {
* Test of draw offer/accept/request command. * Test of draw offer/accept/request command.
*/ */
public void testDrawBug() throws ChessParseError { public void testDrawBug() throws ChessParseError {
Game game = new Game(null, null, 0, 0, 0); Game game = new Game(null, 0, 0, 0);
assertEquals(false, game.haveDrawOffer()); assertEquals(false, game.haveDrawOffer());
game.processString("e4"); game.processString("e4");
game.processString("c5"); game.processString("c5");
@@ -269,7 +269,7 @@ public class GameTest extends TestCase {
* Test of resign command, of class Game. * Test of resign command, of class Game.
*/ */
public void testResign() throws ChessParseError { public void testResign() throws ChessParseError {
Game game = new Game(null, null, 0, 0, 0); Game game = new Game(null, 0, 0, 0);
assertEquals(Game.GameState.ALIVE, game.getGameState()); assertEquals(Game.GameState.ALIVE, game.getGameState());
game.processString("f3"); game.processString("f3");
assertEquals(Game.GameState.ALIVE, game.getGameState()); assertEquals(Game.GameState.ALIVE, game.getGameState());
@@ -299,7 +299,7 @@ public class GameTest extends TestCase {
* Test of processString method, of class Game. * Test of processString method, of class Game.
*/ */
public void testProcessString() throws ChessParseError { public void testProcessString() throws ChessParseError {
Game game = new Game(null, null, 0, 0, 0); Game game = new Game(null, 0, 0, 0);
assertEquals(TextIO.startPosFEN, TextIO.toFEN(game.currPos())); assertEquals(TextIO.startPosFEN, TextIO.toFEN(game.currPos()));
boolean res = game.processString("Nf3"); boolean res = game.processString("Nf3");
assertEquals(true, res); assertEquals(true, res);
@@ -348,7 +348,7 @@ public class GameTest extends TestCase {
* Test of getGameState method, of class Game. * Test of getGameState method, of class Game.
*/ */
public void testGetGameState() throws ChessParseError { public void testGetGameState() throws ChessParseError {
Game game = new Game(null, null, 0, 0, 0); Game game = new Game(null, 0, 0, 0);
assertEquals(Game.GameState.ALIVE, game.getGameState()); assertEquals(Game.GameState.ALIVE, game.getGameState());
game.processString("f3"); game.processString("f3");
game.processString("e5"); game.processString("e5");
@@ -364,7 +364,7 @@ public class GameTest extends TestCase {
* Test of insufficientMaterial method, of class Game. * Test of insufficientMaterial method, of class Game.
*/ */
public void testInsufficientMaterial() throws ChessParseError { public void testInsufficientMaterial() throws ChessParseError {
Game game = new Game(null, null, 0, 0, 0); Game game = new Game(null, 0, 0, 0);
assertEquals(Game.GameState.ALIVE, game.getGameState()); assertEquals(Game.GameState.ALIVE, game.getGameState());
game.setPos(TextIO.readFEN("4k3/8/8/8/8/8/8/4K3 w - - 0 1")); game.setPos(TextIO.readFEN("4k3/8/8/8/8/8/8/4K3 w - - 0 1"));
assertEquals(Game.GameState.DRAW_NO_MATE, game.getGameState()); assertEquals(Game.GameState.DRAW_NO_MATE, game.getGameState());
@@ -407,7 +407,7 @@ public class GameTest extends TestCase {
/** Test that UCI history is not longer than necessary. /** Test that UCI history is not longer than necessary.
* We can't expect engines to handle null moves, for example. */ * We can't expect engines to handle null moves, for example. */
public void testUCIHistory() throws ChessParseError { public void testUCIHistory() throws ChessParseError {
Game game = new Game(null, null, 0, 0, 0); Game game = new Game(null, 0, 0, 0);
Pair<Position, ArrayList<Move>> hist = game.getUCIHistory(); Pair<Position, ArrayList<Move>> hist = game.getUCIHistory();
assertEquals(0, hist.second.size()); assertEquals(0, hist.second.size());