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
public void requestPromotePiece() {
runOnUIThread(new Runnable() {
public void run() {
showDialog(PROMOTE_DIALOG);
}
});
showDialog(PROMOTE_DIALOG);
}
@Override

View File

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

View File

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

View File

@@ -36,7 +36,7 @@ public class GameTest extends TestCase {
* Test of haveDrawOffer method, of class Game.
*/
public void testHaveDrawOffer() {
Game game = new Game(null, null, 0, 0, 0);
Game game = new Game(null, 0, 0, 0);
assertEquals(false, game.haveDrawOffer());
boolean res = game.processString("e4");
@@ -124,7 +124,7 @@ public class GameTest extends TestCase {
* Test of draw by 50 move rule, of class Game.
*/
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());
boolean res = game.processString("draw 50");
assertEquals(true, res);
@@ -179,7 +179,7 @@ public class GameTest extends TestCase {
* Test of draw by repetition, of class Game.
*/
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());
game.processString("Nc3");
game.processString("Nc6");
@@ -251,7 +251,7 @@ public class GameTest extends TestCase {
* Test of draw offer/accept/request command.
*/
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());
game.processString("e4");
game.processString("c5");
@@ -269,7 +269,7 @@ public class GameTest extends TestCase {
* Test of resign command, of class Game.
*/
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());
game.processString("f3");
assertEquals(Game.GameState.ALIVE, game.getGameState());
@@ -299,7 +299,7 @@ public class GameTest extends TestCase {
* Test of processString method, of class Game.
*/
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()));
boolean res = game.processString("Nf3");
assertEquals(true, res);
@@ -348,7 +348,7 @@ public class GameTest extends TestCase {
* Test of getGameState method, of class Game.
*/
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());
game.processString("f3");
game.processString("e5");
@@ -364,7 +364,7 @@ public class GameTest extends TestCase {
* Test of insufficientMaterial method, of class Game.
*/
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());
game.setPos(TextIO.readFEN("4k3/8/8/8/8/8/8/4K3 w - - 0 1"));
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.
* We can't expect engines to handle null moves, for example. */
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();
assertEquals(0, hist.second.size());