DroidFish: Changed some variables from long to int.

This commit is contained in:
Peter Osterlund
2013-04-14 14:07:14 +00:00
parent 26ac3b6ab5
commit ca757cebd7
8 changed files with 43 additions and 41 deletions

View File

@@ -3187,7 +3187,7 @@ public class DroidFish extends Activity implements GUIInterface {
}
}
private final String timeToString(long time) {
private final String timeToString(int time) {
int secs = (int)Math.floor((time + 999) / 1000.0);
boolean neg = false;
if (secs < 0) {
@@ -3213,7 +3213,7 @@ public class DroidFish extends Activity implements GUIInterface {
};
@Override
public void setRemainingTime(long wTime, long bTime, long nextUpdate) {
public void setRemainingTime(int wTime, int bTime, int nextUpdate) {
if (ctrl.getGameMode().clocksActive()) {
whiteTitleText.setText(getString(R.string.white_square_character) + " " + timeToString(wTime));
blackTitleText.setText(getString(R.string.black_square_character) + " " + timeToString(bTime));

View File

@@ -75,7 +75,7 @@ public interface GUIInterface {
public void computerMoveMade();
/** Report remaining thinking time to GUI. */
public void setRemainingTime(long wTime, long bTime, long nextUpdate);
public void setRemainingTime(int wTime, int bTime, int nextUpdate);
/** Update engine title text. */
public void updateEngineTitle();

View File

@@ -205,7 +205,7 @@ public class DroidChessController {
/** Serialize to byte array. */
public final synchronized byte[] toByteArray() {
return game.tree.toByteArray();
return game.toByteArray();
}
/** Return FEN string corresponding to a current position. */
@@ -479,11 +479,11 @@ public class DroidChessController {
/** Update remaining time and trigger GUI update of clocks. */
public final synchronized void updateRemainingTime() {
long now = System.currentTimeMillis();
long wTime = game.timeController.getRemainingTime(true, now);
long bTime = game.timeController.getRemainingTime(false, now);
long nextUpdate = 0;
int wTime = game.timeController.getRemainingTime(true, now);
int bTime = game.timeController.getRemainingTime(false, now);
int nextUpdate = 0;
if (game.timeController.clockRunning()) {
long t = game.currPos().whiteMove ? wTime : bTime;
int t = game.currPos().whiteMove ? wTime : bTime;
nextUpdate = t % 1000;
if (nextUpdate < 0) nextUpdate += 1000;
nextUpdate += 1;

View File

@@ -53,6 +53,11 @@ public class Game {
updateTimeControl(true);
}
/** Serialize to byte array. */
final synchronized byte[] toByteArray() {
return tree.toByteArray();
}
public final void setGamePaused(boolean gamePaused) {
if (gamePaused != this.gamePaused) {
this.gamePaused = gamePaused;

View File

@@ -1598,7 +1598,7 @@ public class GameTree {
sb.append('/');
}
sb.append(t.timeControl / 1000);
int ms = (int)t.timeControl % 1000;
int ms = t.timeControl % 1000;
if (ms > 0) {
sb.append('.');
sb.append(String.format(Locale.US, "%03d", ms));
@@ -1606,7 +1606,7 @@ public class GameTree {
if (t.increment > 0) {
sb.append('+');
sb.append(t.increment / 1000);
ms = (int)t.increment % 1000;
ms = t.increment % 1000;
if (ms > 0) {
sb.append('.');
sb.append(String.format(Locale.US, "%03d", ms));

View File

@@ -26,13 +26,13 @@ import org.petero.droidfish.gamelogic.TimeControlData.TimeControlField;
public class TimeControl {
TimeControlData tcData;
private long whiteBaseTime; // Current remaining time, or remaining time when clock started
private long blackBaseTime; // Current remaining time, or remaining time when clock started
private int whiteBaseTime; // Current remaining time, or remaining time when clock started
private int blackBaseTime; // Current remaining time, or remaining time when clock started
int currentMove;
boolean whiteToMove;
private long elapsed; // Accumulated elapsed time for this move.
private int elapsed; // Accumulated elapsed time for this move.
private long timerT0; // Time when timer started. 0 if timer is stopped.
@@ -54,7 +54,7 @@ public class TimeControl {
this.tcData = tcData;
}
public final void setCurrentMove(int move, boolean whiteToMove, long whiteBaseTime, long blackBaseTime) {
public final void setCurrentMove(int move, boolean whiteToMove, int whiteBaseTime, int blackBaseTime) {
currentMove = move;
this.whiteToMove = whiteToMove;
this.whiteBaseTime = whiteBaseTime;
@@ -75,14 +75,12 @@ public class TimeControl {
public final void stopTimer(long now) {
if (clockRunning()) {
long timerT1 = now;
long currElapsed = timerT1 - timerT0;
int currElapsed = (int)(now - timerT0);
timerT0 = 0;
if (currElapsed > 0) {
if (currElapsed > 0)
elapsed += currElapsed;
}
}
}
/** Compute new remaining time after a move is made. */
public final int moveMade(long now, boolean useIncrement) {
@@ -93,7 +91,7 @@ public class TimeControl {
int tcIdx = tcInfo.first;
int movesToTc = tcInfo.second;
long remaining = getRemainingTime(whiteToMove, now);
int remaining = getRemainingTime(whiteToMove, now);
if (useIncrement) {
remaining += tc.get(tcIdx).increment;
if (movesToTc == 1) {
@@ -103,32 +101,31 @@ public class TimeControl {
}
}
elapsed = 0;
return (int)remaining;
return remaining;
}
/** Get remaining time */
public final int getRemainingTime(boolean whiteToMove, long now) {
long remaining = whiteToMove ? whiteBaseTime : blackBaseTime;
int remaining = whiteToMove ? whiteBaseTime : blackBaseTime;
if (whiteToMove == this.whiteToMove) {
remaining -= elapsed;
if (timerT0 != 0) {
if (timerT0 != 0)
remaining -= now - timerT0;
}
}
return (int)remaining;
return remaining;
}
/** Get initial thinking time in milliseconds. */
public final int getInitialTime(boolean whiteMove) {
ArrayList<TimeControlField> tc = tcData.getTC(whiteMove);
return (int)tc.get(0).timeControl;
return tc.get(0).timeControl;
}
/** Get time increment in milliseconds after playing next move. */
public final int getIncrement(boolean whiteMove) {
ArrayList<TimeControlField> tc = tcData.getTC(whiteMove);
int tcIdx = getCurrentTC(whiteMove).first;
return (int)tc.get(tcIdx).increment;
return tc.get(tcIdx).increment;
}
/** Return number of moves to the next time control, or 0 if "sudden death". */
@@ -141,7 +138,7 @@ public class TimeControl {
ArrayList<TimeControlField> tc = tcData.getTC(whiteMove);
int tcIdx = getCurrentTC(whiteMove).first;
TimeControlField t = tc.get(tcIdx);
return new int[]{(int)t.timeControl, t.movesPerSession, (int)t.increment};
return new int[]{t.timeControl, t.movesPerSession, t.increment};
}
/** Return the current active time control index and number of moves to next time control. */

View File

@@ -4,11 +4,11 @@ import java.util.ArrayList;
public final class TimeControlData {
public static final class TimeControlField {
long timeControl; // Time in milliseconds
int timeControl; // Time in milliseconds
int movesPerSession;
long increment; // Increment in milliseconds
int increment; // Increment in milliseconds
public TimeControlField(long time, int moves, long inc) {
public TimeControlField(int time, int moves, int inc) {
timeControl = time;
movesPerSession = moves;
increment = inc;
@@ -26,7 +26,7 @@ public final class TimeControlData {
}
/** Set a single time control for both white and black. */
public final void setTimeControl(long time, int moves, long inc) {
public final void setTimeControl(int time, int moves, int inc) {
tcW = new ArrayList<TimeControlField>();
tcW.add(new TimeControlField(time, moves, inc));
tcB = new ArrayList<TimeControlField>();

View File

@@ -31,7 +31,7 @@ public class TimeControlTest extends TestCase {
public void testElapsedTime() {
TimeControl tc = new TimeControl();
long totTime = 5 * 60 * 1000;
int totTime = 5 * 60 * 1000;
long t0 = 1000;
TimeControlData tcData = new TimeControlData();
tcData.setTimeControl(totTime, 0, 0);
@@ -113,7 +113,7 @@ public class TimeControlTest extends TestCase {
assertEquals(40, tc.getMovesToTC(false));
}
private TimeControlField tcf(long time, int moves, long inc) {
private TimeControlField tcf(int time, int moves, int inc) {
return new TimeControlField(time, moves, inc);
}
@@ -159,8 +159,8 @@ public class TimeControlTest extends TestCase {
assertEquals(1000, tc.getIncrement(false));
long wBaseTime = 60*1000;
long bBaseTime = 50*1000;
int wBaseTime = 60*1000;
int bBaseTime = 50*1000;
tc.setCurrentMove(30, true, wBaseTime, bBaseTime);
tc.startTimer(1500);
wBaseTime = tc.moveMade(1500 + 3000, true);
@@ -179,15 +179,15 @@ public class TimeControlTest extends TestCase {
public void testExtraTime() {
TimeControl tc = new TimeControl();
final long timeCont = 60 * 1000;
int wBaseTime = (int)timeCont;
int bBaseTime = (int)timeCont;
final long inc = 700;
final int timeCont = 60 * 1000;
int wBaseTime = timeCont;
int bBaseTime = timeCont;
final int inc = 700;
TimeControlData tcData = new TimeControlData();
tcData.setTimeControl(timeCont, 5, inc);
tc.setTimeControl(tcData);
tc.setCurrentMove(5, true, wBaseTime, bBaseTime);
long t0 = 1342134;
int t0 = 1342134;
assertEquals(timeCont, tc.getRemainingTime(true, t0 + 4711));
assertEquals(timeCont, tc.getRemainingTime(false, t0 + 4711));
@@ -219,7 +219,7 @@ public class TimeControlTest extends TestCase {
// No extra time when passing time control in analysis mode
tcData.setTimeControl(timeCont, 1, inc);
tc.setTimeControl(tcData);
wBaseTime = bBaseTime = (int)timeCont;
wBaseTime = bBaseTime = timeCont;
tc.setCurrentMove(1, true, wBaseTime, bBaseTime);
tc.startTimer(t0 + 1000);
wBaseTime = tc.moveMade(t0 + 3000, false);