mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-12-08 15:12:40 +01:00
Fix some Android Studio warnings.
This commit is contained in:
@@ -127,7 +127,7 @@ public class ChessBoardPainter extends JLabel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void drawPiece(Graphics2D g, int xCrd, int yCrd, int p) {
|
private void drawPiece(Graphics2D g, int xCrd, int yCrd, int p) {
|
||||||
g.setColor(Piece.isWhite(p) ? Color.WHITE : Color.BLACK);
|
g.setColor(Piece.isWhite(p) ? Color.WHITE : Color.BLACK);
|
||||||
String ps;
|
String ps;
|
||||||
switch (p) {
|
switch (p) {
|
||||||
@@ -195,10 +195,10 @@ public class ChessBoardPainter extends JLabel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int getXCrd(int x) {
|
private int getXCrd(int x) {
|
||||||
return x0 + sqSize * (flipped ? 7 - x : x);
|
return x0 + sqSize * (flipped ? 7 - x : x);
|
||||||
}
|
}
|
||||||
private final int getYCrd(int y) {
|
private int getYCrd(int y) {
|
||||||
return y0 + sqSize * (flipped ? y : (7 - y));
|
return y0 + sqSize * (flipped ? y : (7 - y));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -275,7 +275,7 @@ public class EngineControl {
|
|||||||
engineThread.start();
|
engineThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void stopThread() {
|
private void stopThread() {
|
||||||
Thread myThread;
|
Thread myThread;
|
||||||
Search mySearch;
|
Search mySearch;
|
||||||
synchronized (threadMutex) {
|
synchronized (threadMutex) {
|
||||||
@@ -295,13 +295,13 @@ public class EngineControl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private final void setupTT() {
|
private void setupTT() {
|
||||||
int nEntries = hashSizeMB > 0 ? hashSizeMB * (1 << 20) / 24 : 1024;
|
int nEntries = hashSizeMB > 0 ? hashSizeMB * (1 << 20) / 24 : 1024;
|
||||||
int logSize = (int) Math.floor(Math.log(nEntries) / Math.log(2));
|
int logSize = (int) Math.floor(Math.log(nEntries) / Math.log(2));
|
||||||
tt = new TranspositionTable(logSize);
|
tt = new TranspositionTable(logSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void setupPosition(Position pos, List<Move> moves) {
|
private void setupPosition(Position pos, List<Move> moves) {
|
||||||
UndoInfo ui = new UndoInfo();
|
UndoInfo ui = new UndoInfo();
|
||||||
posHashList = new long[200 + moves.size()];
|
posHashList = new long[200 + moves.size()];
|
||||||
posHashListSize = 0;
|
posHashListSize = 0;
|
||||||
@@ -315,7 +315,7 @@ public class EngineControl {
|
|||||||
/**
|
/**
|
||||||
* Try to find a move to ponder from the transposition table.
|
* Try to find a move to ponder from the transposition table.
|
||||||
*/
|
*/
|
||||||
private final Move getPonderMove(Position pos, Move m) {
|
private Move getPonderMove(Position pos, Move m) {
|
||||||
if (m == null) return null;
|
if (m == null) return null;
|
||||||
Move ret = null;
|
Move ret = null;
|
||||||
UndoInfo ui = new UndoInfo();
|
UndoInfo ui = new UndoInfo();
|
||||||
|
|||||||
@@ -37,6 +37,6 @@ public class SearchParams {
|
|||||||
boolean infinite;
|
boolean infinite;
|
||||||
|
|
||||||
public SearchParams() {
|
public SearchParams() {
|
||||||
searchMoves = new ArrayList<Move>();
|
searchMoves = new ArrayList<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class UCIProtocol {
|
|||||||
|
|
||||||
public UCIProtocol() {
|
public UCIProtocol() {
|
||||||
pos = null;
|
pos = null;
|
||||||
moves = new ArrayList<Move>();
|
moves = new ArrayList<>();
|
||||||
quit = false;
|
quit = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ public class ChessBoard extends View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void drawPiece(Canvas canvas, int xCrd, int yCrd, int p) {
|
private void drawPiece(Canvas canvas, int xCrd, int yCrd, int p) {
|
||||||
String ps;
|
String ps;
|
||||||
switch (p) {
|
switch (p) {
|
||||||
case Piece.EMPTY:
|
case Piece.EMPTY:
|
||||||
@@ -218,10 +218,10 @@ public class ChessBoard extends View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int getXCrd(int x) {
|
private int getXCrd(int x) {
|
||||||
return x0 + sqSize * (flipped ? 7 - x : x);
|
return x0 + sqSize * (flipped ? 7 - x : x);
|
||||||
}
|
}
|
||||||
private final int getYCrd(int y) {
|
private int getYCrd(int y) {
|
||||||
return y0 + sqSize * (flipped ? y : (7 - y));
|
return y0 + sqSize * (flipped ? y : (7 - y));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ public class CuckooChess extends Activity implements GUIInterface {
|
|||||||
tmp = settings.getString("numUndo", null);
|
tmp = settings.getString("numUndo", null);
|
||||||
if (tmp != null) numUndo = tmp;
|
if (tmp != null) numUndo = tmp;
|
||||||
}
|
}
|
||||||
List<String> posHistStr = new ArrayList<String>();
|
List<String> posHistStr = new ArrayList<>();
|
||||||
posHistStr.add(fen);
|
posHistStr.add(fen);
|
||||||
posHistStr.add(moves);
|
posHistStr.add(moves);
|
||||||
posHistStr.add(numUndo);
|
posHistStr.add(numUndo);
|
||||||
|
|||||||
@@ -54,13 +54,13 @@ public class Book {
|
|||||||
if (numBookMoves >= 0)
|
if (numBookMoves >= 0)
|
||||||
return;
|
return;
|
||||||
long t0 = System.currentTimeMillis();
|
long t0 = System.currentTimeMillis();
|
||||||
bookMap = new HashMap<Long, List<BookEntry>>();
|
bookMap = new HashMap<>();
|
||||||
rndGen = new SecureRandom();
|
rndGen = new SecureRandom();
|
||||||
rndGen.setSeed(System.currentTimeMillis());
|
rndGen.setSeed(System.currentTimeMillis());
|
||||||
numBookMoves = 0;
|
numBookMoves = 0;
|
||||||
try {
|
try {
|
||||||
InputStream inStream = getClass().getResourceAsStream("/book.bin");
|
InputStream inStream = getClass().getResourceAsStream("/book.bin");
|
||||||
List<Byte> buf = new ArrayList<Byte>(8192);
|
List<Byte> buf = new ArrayList<>(8192);
|
||||||
byte[] tmpBuf = new byte[1024];
|
byte[] tmpBuf = new byte[1024];
|
||||||
while (true) {
|
while (true) {
|
||||||
int len = inStream.read(tmpBuf);
|
int len = inStream.read(tmpBuf);
|
||||||
@@ -106,7 +106,7 @@ public class Book {
|
|||||||
private void addToBook(Position pos, Move moveToAdd) {
|
private void addToBook(Position pos, Move moveToAdd) {
|
||||||
List<BookEntry> ent = bookMap.get(pos.zobristHash());
|
List<BookEntry> ent = bookMap.get(pos.zobristHash());
|
||||||
if (ent == null) {
|
if (ent == null) {
|
||||||
ent = new ArrayList<BookEntry>();
|
ent = new ArrayList<>();
|
||||||
bookMap.put(pos.zobristHash(), ent);
|
bookMap.put(pos.zobristHash(), ent);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < ent.size(); i++) {
|
for (int i = 0; i < ent.size(); i++) {
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ public class ComputerPlayer implements Player {
|
|||||||
// tt.printStats();
|
// tt.printStats();
|
||||||
|
|
||||||
// Return best move and PV
|
// Return best move and PV
|
||||||
return new TwoReturnValues<Move, String>(bestM, PV);
|
return new TwoReturnValues<>(bestM, PV);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Move findSemiRandomMove(Search sc, MoveGen.MoveList moves) {
|
private Move findSemiRandomMove(Search sc, MoveGen.MoveList moves) {
|
||||||
@@ -237,7 +237,7 @@ public class ComputerPlayer implements Player {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static int moveProbWeight(int moveScore, int bestScore) {
|
private static int moveProbWeight(int moveScore, int bestScore) {
|
||||||
double d = (bestScore - moveScore) / 100.0;
|
double d = (bestScore - moveScore) / 100.0;
|
||||||
double w = 100*Math.exp(-d*d/2);
|
double w = 100*Math.exp(-d*d/2);
|
||||||
return (int)Math.ceil(w);
|
return (int)Math.ceil(w);
|
||||||
|
|||||||
@@ -290,12 +290,12 @@ public class Evaluate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Compute white_material - black_material. */
|
/** Compute white_material - black_material. */
|
||||||
static final int material(Position pos) {
|
static int material(Position pos) {
|
||||||
return pos.wMtrl - pos.bMtrl;
|
return pos.wMtrl - pos.bMtrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute score based on piece square tables. Positive values are good for white. */
|
/** Compute score based on piece square tables. Positive values are good for white. */
|
||||||
private final int pieceSquareEval(Position pos) {
|
private int pieceSquareEval(Position pos) {
|
||||||
int score = 0;
|
int score = 0;
|
||||||
final int wMtrl = pos.wMtrl;
|
final int wMtrl = pos.wMtrl;
|
||||||
final int bMtrl = pos.bMtrl;
|
final int bMtrl = pos.bMtrl;
|
||||||
@@ -405,7 +405,7 @@ public class Evaluate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Implement the "when ahead trade pieces, when behind trade pawns" rule. */
|
/** Implement the "when ahead trade pieces, when behind trade pawns" rule. */
|
||||||
private final int tradeBonus(Position pos) {
|
private int tradeBonus(Position pos) {
|
||||||
final int wM = pos.wMtrl;
|
final int wM = pos.wMtrl;
|
||||||
final int bM = pos.bMtrl;
|
final int bM = pos.bMtrl;
|
||||||
final int wPawn = pos.wMtrlPawns;
|
final int wPawn = pos.wMtrlPawns;
|
||||||
@@ -436,7 +436,7 @@ public class Evaluate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Score castling ability. */
|
/** Score castling ability. */
|
||||||
private final int castleBonus(Position pos) {
|
private int castleBonus(Position pos) {
|
||||||
if (pos.getCastleMask() == 0) return 0;
|
if (pos.getCastleMask() == 0) return 0;
|
||||||
|
|
||||||
final int k1 = kt1b[7*8+6] - kt1b[7*8+4];
|
final int k1 = kt1b[7*8+6] - kt1b[7*8+4];
|
||||||
@@ -464,7 +464,7 @@ public class Evaluate {
|
|||||||
return wBonus - bBonus;
|
return wBonus - bBonus;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int pawnBonus(Position pos) {
|
private int pawnBonus(Position pos) {
|
||||||
long key = pos.pawnZobristHash();
|
long key = pos.pawnZobristHash();
|
||||||
PawnHashData phd = pawnHash[(int)key & (pawnHash.length - 1)];
|
PawnHashData phd = pawnHash[(int)key & (pawnHash.length - 1)];
|
||||||
if (phd.key != key)
|
if (phd.key != key)
|
||||||
@@ -562,7 +562,7 @@ public class Evaluate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Compute pawn hash data for pos. */
|
/** Compute pawn hash data for pos. */
|
||||||
private final void computePawnHashData(Position pos, PawnHashData ph) {
|
private void computePawnHashData(Position pos, PawnHashData ph) {
|
||||||
int score = 0;
|
int score = 0;
|
||||||
|
|
||||||
// Evaluate double pawns and pawn islands
|
// Evaluate double pawns and pawn islands
|
||||||
@@ -658,7 +658,7 @@ public class Evaluate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Compute rook bonus. Rook on open/half-open file. */
|
/** Compute rook bonus. Rook on open/half-open file. */
|
||||||
private final int rookBonus(Position pos) {
|
private int rookBonus(Position pos) {
|
||||||
int score = 0;
|
int score = 0;
|
||||||
final long wPawns = pos.pieceTypeBB[Piece.WPAWN];
|
final long wPawns = pos.pieceTypeBB[Piece.WPAWN];
|
||||||
final long bPawns = pos.pieceTypeBB[Piece.BPAWN];
|
final long bPawns = pos.pieceTypeBB[Piece.BPAWN];
|
||||||
@@ -703,7 +703,7 @@ public class Evaluate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Compute bishop evaluation. */
|
/** Compute bishop evaluation. */
|
||||||
private final int bishopEval(Position pos, int oldScore) {
|
private int bishopEval(Position pos, int oldScore) {
|
||||||
int score = 0;
|
int score = 0;
|
||||||
final long occupied = pos.whiteBB | pos.blackBB;
|
final long occupied = pos.whiteBB | pos.blackBB;
|
||||||
long wBishops = pos.pieceTypeBB[Piece.WBISHOP];
|
long wBishops = pos.pieceTypeBB[Piece.WBISHOP];
|
||||||
@@ -828,7 +828,7 @@ public class Evaluate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Compute king safety for both kings. */
|
/** Compute king safety for both kings. */
|
||||||
private final int kingSafety(Position pos) {
|
private int kingSafety(Position pos) {
|
||||||
final int minM = rV + bV;
|
final int minM = rV + bV;
|
||||||
final int m = (pos.wMtrl - pos.wMtrlPawns + pos.bMtrl - pos.bMtrlPawns) / 2;
|
final int m = (pos.wMtrl - pos.wMtrlPawns + pos.bMtrl - pos.bMtrlPawns) / 2;
|
||||||
if (m <= minM)
|
if (m <= minM)
|
||||||
@@ -884,7 +884,7 @@ public class Evaluate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int kingSafetyKPPart(Position pos) {
|
private int kingSafetyKPPart(Position pos) {
|
||||||
final long key = pos.pawnZobristHash() ^ pos.kingZobristHash();
|
final long key = pos.pawnZobristHash() ^ pos.kingZobristHash();
|
||||||
KingSafetyHashData ksh = kingSafetyHash[(int)key & (kingSafetyHash.length - 1)];
|
KingSafetyHashData ksh = kingSafetyHash[(int)key & (kingSafetyHash.length - 1)];
|
||||||
if (ksh.key != key) {
|
if (ksh.key != key) {
|
||||||
@@ -958,7 +958,7 @@ public class Evaluate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Implements special knowledge for some endgame situations. */
|
/** Implements special knowledge for some endgame situations. */
|
||||||
private final int endGameEval(Position pos, int oldScore) {
|
private int endGameEval(Position pos, int oldScore) {
|
||||||
int score = oldScore;
|
int score = oldScore;
|
||||||
if (pos.wMtrl + pos.bMtrl > 6 * rV)
|
if (pos.wMtrl + pos.bMtrl > 6 * rV)
|
||||||
return score;
|
return score;
|
||||||
|
|||||||
@@ -182,9 +182,9 @@ public class Game {
|
|||||||
*/
|
*/
|
||||||
protected boolean handleCommand(String moveStr) {
|
protected boolean handleCommand(String moveStr) {
|
||||||
if (moveStr.equals("new")) {
|
if (moveStr.equals("new")) {
|
||||||
moveList = new ArrayList<Move>();
|
moveList = new ArrayList<>();
|
||||||
uiInfoList = new ArrayList<UndoInfo>();
|
uiInfoList = new ArrayList<>();
|
||||||
drawOfferList = new ArrayList<Boolean>();
|
drawOfferList = new ArrayList<>();
|
||||||
currentMove = 0;
|
currentMove = 0;
|
||||||
pendingDrawOffer = false;
|
pendingDrawOffer = false;
|
||||||
drawState = GameState.ALIVE;
|
drawState = GameState.ALIVE;
|
||||||
@@ -305,7 +305,7 @@ public class Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getPosHistory() {
|
public List<String> getPosHistory() {
|
||||||
List<String> ret = new ArrayList<String>();
|
List<String> ret = new ArrayList<>();
|
||||||
|
|
||||||
Position pos = new Position(this.pos);
|
Position pos = new Position(this.pos);
|
||||||
for (int i = currentMove; i > 0; i--) {
|
for (int i = currentMove; i > 0; i--) {
|
||||||
@@ -423,7 +423,7 @@ public class Game {
|
|||||||
|
|
||||||
/** Return a list of previous positions in this game, back to the last "zeroing" move. */
|
/** Return a list of previous positions in this game, back to the last "zeroing" move. */
|
||||||
public ArrayList<Position> getHistory() {
|
public ArrayList<Position> getHistory() {
|
||||||
ArrayList<Position> posList = new ArrayList<Position>();
|
ArrayList<Position> posList = new ArrayList<>();
|
||||||
Position pos = new Position(this.pos);
|
Position pos = new Position(this.pos);
|
||||||
for (int i = currentMove; i > 0; i--) {
|
for (int i = currentMove; i > 0; i--) {
|
||||||
if (pos.halfMoveClock == 0)
|
if (pos.halfMoveClock == 0)
|
||||||
@@ -446,7 +446,7 @@ public class Game {
|
|||||||
boolean valid;
|
boolean valid;
|
||||||
if (rep) {
|
if (rep) {
|
||||||
valid = false;
|
valid = false;
|
||||||
List<Position> oldPositions = new ArrayList<Position>();
|
List<Position> oldPositions = new ArrayList<>();
|
||||||
if (m != null) {
|
if (m != null) {
|
||||||
UndoInfo ui = new UndoInfo();
|
UndoInfo ui = new UndoInfo();
|
||||||
Position tmpPos = new Position(pos);
|
Position tmpPos = new Position(pos);
|
||||||
|
|||||||
@@ -366,7 +366,7 @@ public final class MoveGen {
|
|||||||
{
|
{
|
||||||
ArrayList<Move> allMoves = pseudoLegalMoves(pos);
|
ArrayList<Move> allMoves = pseudoLegalMoves(pos);
|
||||||
allMoves = MoveGen.removeIllegal(pos, allMoves);
|
allMoves = MoveGen.removeIllegal(pos, allMoves);
|
||||||
HashSet<String> evMoves = new HashSet<String>();
|
HashSet<String> evMoves = new HashSet<>();
|
||||||
for (Move m : moveList)
|
for (Move m : moveList)
|
||||||
evMoves.add(TextIO.moveToUCIString(m));
|
evMoves.add(TextIO.moveToUCIString(m));
|
||||||
for (Move m : allMoves)
|
for (Move m : allMoves)
|
||||||
@@ -967,7 +967,7 @@ public final class MoveGen {
|
|||||||
moveList.size = length;
|
moveList.size = length;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static boolean addPawnMovesByMask(MoveList moveList, Position pos, long mask,
|
private static boolean addPawnMovesByMask(MoveList moveList, Position pos, long mask,
|
||||||
int delta, boolean allPromotions) {
|
int delta, boolean allPromotions) {
|
||||||
if (mask == 0)
|
if (mask == 0)
|
||||||
return false;
|
return false;
|
||||||
@@ -1008,7 +1008,7 @@ public final class MoveGen {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static void addPawnDoubleMovesByMask(MoveList moveList, Position pos,
|
private static void addPawnDoubleMovesByMask(MoveList moveList, Position pos,
|
||||||
long mask, int delta) {
|
long mask, int delta) {
|
||||||
while (mask != 0) {
|
while (mask != 0) {
|
||||||
int sq = BitBoard.numberOfTrailingZeros(mask);
|
int sq = BitBoard.numberOfTrailingZeros(mask);
|
||||||
@@ -1017,7 +1017,7 @@ public final class MoveGen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static boolean addMovesByMask(MoveList moveList, Position pos, int sq0, long mask) {
|
private static boolean addMovesByMask(MoveList moveList, Position pos, int sq0, long mask) {
|
||||||
long oKingMask = pos.pieceTypeBB[pos.whiteMove ? Piece.BKING : Piece.WKING];
|
long oKingMask = pos.pieceTypeBB[pos.whiteMove ? Piece.BKING : Piece.WKING];
|
||||||
if ((mask & oKingMask) != 0) {
|
if ((mask & oKingMask) != 0) {
|
||||||
int sq = BitBoard.numberOfTrailingZeros(mask & oKingMask);
|
int sq = BitBoard.numberOfTrailingZeros(mask & oKingMask);
|
||||||
@@ -1033,7 +1033,7 @@ public final class MoveGen {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static void setMove(MoveList moveList, int from, int to, int promoteTo) {
|
private static void setMove(MoveList moveList, int from, int to, int promoteTo) {
|
||||||
Move m = moveList.m[moveList.size++];
|
Move m = moveList.m[moveList.size++];
|
||||||
m.from = from;
|
m.from = from;
|
||||||
m.to = to;
|
m.to = to;
|
||||||
@@ -1047,7 +1047,7 @@ public final class MoveGen {
|
|||||||
|
|
||||||
private static final int MAX_MOVES = 256;
|
private static final int MAX_MOVES = 256;
|
||||||
|
|
||||||
private final MoveList getMoveListObj() {
|
private MoveList getMoveListObj() {
|
||||||
MoveList ml;
|
MoveList ml;
|
||||||
if (moveListsInCache > 0) {
|
if (moveListsInCache > 0) {
|
||||||
ml = (MoveList)moveListCache[--moveListsInCache];
|
ml = (MoveList)moveListCache[--moveListsInCache];
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public class Parameters {
|
|||||||
return inst;
|
return inst;
|
||||||
}
|
}
|
||||||
public final String[] getParamNames() {
|
public final String[] getParamNames() {
|
||||||
ArrayList<String> parNames = new ArrayList<String>();
|
ArrayList<String> parNames = new ArrayList<>();
|
||||||
for (Map.Entry<String, ParamBase> e : params.entrySet())
|
for (Map.Entry<String, ParamBase> e : params.entrySet())
|
||||||
if (e.getValue().visible)
|
if (e.getValue().visible)
|
||||||
parNames.add(e.getKey());
|
parNames.add(e.getKey());
|
||||||
@@ -97,7 +97,7 @@ public class Parameters {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static final Parameters inst = new Parameters();
|
private static final Parameters inst = new Parameters();
|
||||||
private Map<String, ParamBase> params = new TreeMap<String, ParamBase>();
|
private Map<String, ParamBase> params = new TreeMap<>();
|
||||||
|
|
||||||
private Parameters() {
|
private Parameters() {
|
||||||
addPar(new SpinParam("qV", false, -200, 200, 0));
|
addPar(new SpinParam("qV", false, -200, 200, 0));
|
||||||
@@ -107,7 +107,7 @@ public class Parameters {
|
|||||||
addPar(new SpinParam("pV", false, -200, 200, 0));
|
addPar(new SpinParam("pV", false, -200, 200, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void addPar(ParamBase p) {
|
private void addPar(ParamBase p) {
|
||||||
params.put(p.name.toLowerCase(), p);
|
params.put(p.name.toLowerCase(), p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ public class Position {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Move a non-pawn piece to an empty square. */
|
/** Move a non-pawn piece to an empty square. */
|
||||||
private final void movePieceNotPawn(int from, int to) {
|
private void movePieceNotPawn(int from, int to) {
|
||||||
final int piece = squares[from];
|
final int piece = squares[from];
|
||||||
hashKey ^= psHashKeys[piece][from];
|
hashKey ^= psHashKeys[piece][from];
|
||||||
hashKey ^= psHashKeys[piece][to];
|
hashKey ^= psHashKeys[piece][to];
|
||||||
@@ -562,7 +562,7 @@ public class Position {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void removeCastleRights(int square) {
|
private void removeCastleRights(int square) {
|
||||||
if (square == Position.getSquare(0, 0)) {
|
if (square == Position.getSquare(0, 0)) {
|
||||||
setCastleMask(castleMask & ~(1 << Position.A1_CASTLE));
|
setCastleMask(castleMask & ~(1 << Position.A1_CASTLE));
|
||||||
} else if (square == Position.getSquare(7, 0)) {
|
} else if (square == Position.getSquare(7, 0)) {
|
||||||
@@ -620,7 +620,7 @@ public class Position {
|
|||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static long getRandomHashVal(int rndNo) {
|
private static long getRandomHashVal(int rndNo) {
|
||||||
try {
|
try {
|
||||||
MessageDigest md = MessageDigest.getInstance("SHA-1");
|
MessageDigest md = MessageDigest.getInstance("SHA-1");
|
||||||
byte[] input = new byte[4];
|
byte[] input = new byte[4];
|
||||||
|
|||||||
@@ -418,7 +418,7 @@ public class Search {
|
|||||||
return bestMove;
|
return bestMove;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void notifyPV(int depth, int score, boolean uBound, boolean lBound, Move m) {
|
private void notifyPV(int depth, int score, boolean uBound, boolean lBound, Move m) {
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
boolean isMate = false;
|
boolean isMate = false;
|
||||||
if (score > MATE0 / 2) {
|
if (score > MATE0 / 2) {
|
||||||
@@ -436,7 +436,7 @@ public class Search {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void notifyStats() {
|
private void notifyStats() {
|
||||||
long tNow = System.currentTimeMillis();
|
long tNow = System.currentTimeMillis();
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
int time = (int) (tNow - tStart);
|
int time = (int) (tNow - tStart);
|
||||||
@@ -876,7 +876,7 @@ public class Search {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Return true if move m2 was made possible by move m1. */
|
/** Return true if move m2 was made possible by move m1. */
|
||||||
private final boolean relatedMoves(Move m1, Move m2) {
|
private boolean relatedMoves(Move m1, Move m2) {
|
||||||
if ((m1.from == m1.to) || (m2.from == m2.to))
|
if ((m1.from == m1.to) || (m2.from == m2.to))
|
||||||
return false;
|
return false;
|
||||||
if ((m1.to == m2.from) || (m1.from == m2.to) ||
|
if ((m1.to == m2.from) || (m1.from == m2.to) ||
|
||||||
@@ -886,7 +886,7 @@ public class Search {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Return true if move should be skipped in order to make engine play weaker. */
|
/** Return true if move should be skipped in order to make engine play weaker. */
|
||||||
private final boolean weakPlaySkipMove(Position pos, Move m, int ply) {
|
private boolean weakPlaySkipMove(Position pos, Move m, int ply) {
|
||||||
long rndL = pos.zobristHash() ^ Position.psHashKeys[0][m.from] ^
|
long rndL = pos.zobristHash() ^ Position.psHashKeys[0][m.from] ^
|
||||||
Position.psHashKeys[0][m.to] ^ randomSeed;
|
Position.psHashKeys[0][m.to] ^ randomSeed;
|
||||||
double rnd = ((rndL & 0x7fffffffffffffffL) % 1000000000) / 1e9;
|
double rnd = ((rndL & 0x7fffffffffffffffL) % 1000000000) / 1e9;
|
||||||
@@ -1207,7 +1207,7 @@ public class Search {
|
|||||||
m.score = score;
|
m.score = score;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private final void scoreMoveListMvvLva(MoveGen.MoveList moves) {
|
private void scoreMoveListMvvLva(MoveGen.MoveList moves) {
|
||||||
for (int i = 0; i < moves.size; i++) {
|
for (int i = 0; i < moves.size; i++) {
|
||||||
Move m = moves.m[i];
|
Move m = moves.m[i];
|
||||||
int v = pos.getPiece(m.to);
|
int v = pos.getPiece(m.to);
|
||||||
@@ -1271,7 +1271,7 @@ public class Search {
|
|||||||
return (reps >= 2);
|
return (reps >= 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void initNodeStats() {
|
private void initNodeStats() {
|
||||||
nodes = qNodes = 0;
|
nodes = qNodes = 0;
|
||||||
nodesPlyVec = new int[20];
|
nodesPlyVec = new int[20];
|
||||||
nodesDepthVec = new int[20];
|
nodesDepthVec = new int[20];
|
||||||
|
|||||||
@@ -218,9 +218,9 @@ public class TranspositionTable {
|
|||||||
public final ArrayList<Move> extractPVMoves(Position rootPos, Move m) {
|
public final ArrayList<Move> extractPVMoves(Position rootPos, Move m) {
|
||||||
Position pos = new Position(rootPos);
|
Position pos = new Position(rootPos);
|
||||||
m = new Move(m);
|
m = new Move(m);
|
||||||
ArrayList<Move> ret = new ArrayList<Move>();
|
ArrayList<Move> ret = new ArrayList<>();
|
||||||
UndoInfo ui = new UndoInfo();
|
UndoInfo ui = new UndoInfo();
|
||||||
List<Long> hashHistory = new ArrayList<Long>();
|
List<Long> hashHistory = new ArrayList<>();
|
||||||
MoveGen moveGen = new MoveGen();
|
MoveGen moveGen = new MoveGen();
|
||||||
while (true) {
|
while (true) {
|
||||||
ret.add(m);
|
ret.add(m);
|
||||||
@@ -256,7 +256,7 @@ public class TranspositionTable {
|
|||||||
boolean first = true;
|
boolean first = true;
|
||||||
TTEntry ent = probe(pos.historyHash());
|
TTEntry ent = probe(pos.historyHash());
|
||||||
UndoInfo ui = new UndoInfo();
|
UndoInfo ui = new UndoInfo();
|
||||||
ArrayList<Long> hashHistory = new ArrayList<Long>();
|
ArrayList<Long> hashHistory = new ArrayList<>();
|
||||||
boolean repetition = false;
|
boolean repetition = false;
|
||||||
MoveGen moveGen = MoveGen.instance;
|
MoveGen moveGen = MoveGen.instance;
|
||||||
while (ent.type != TTEntry.T_EMPTY) {
|
while (ent.type != TTEntry.T_EMPTY) {
|
||||||
@@ -301,7 +301,7 @@ public class TranspositionTable {
|
|||||||
public final void printStats() {
|
public final void printStats() {
|
||||||
int unused = 0;
|
int unused = 0;
|
||||||
int thisGen = 0;
|
int thisGen = 0;
|
||||||
List<Integer> depHist = new ArrayList<Integer>();
|
List<Integer> depHist = new ArrayList<>();
|
||||||
final int maxDepth = 20*8;
|
final int maxDepth = 20*8;
|
||||||
for (int i = 0; i < maxDepth; i++) {
|
for (int i = 0; i < maxDepth; i++) {
|
||||||
depHist.add(0);
|
depHist.add(0);
|
||||||
@@ -328,11 +328,11 @@ public class TranspositionTable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int h0(long key) {
|
private int h0(long key) {
|
||||||
return (int)(key & (table.length - 1));
|
return (int)(key & (table.length - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int h1(long key) {
|
private int h1(long key) {
|
||||||
return (int)((key >> 32) & (table.length - 1));
|
return (int)((key >> 32) & (table.length - 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public final class TreeLogger {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void writeHeader(Position pos) {
|
private void writeHeader(Position pos) {
|
||||||
try {
|
try {
|
||||||
byte[] fen = TextIO.toFEN(pos).getBytes();
|
byte[] fen = TextIO.toFEN(pos).getBytes();
|
||||||
bos.write((byte)(fen.length));
|
bos.write((byte)(fen.length));
|
||||||
@@ -196,7 +196,7 @@ public final class TreeLogger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Compute endIndex for all StartNode entries. */
|
/** Compute endIndex for all StartNode entries. */
|
||||||
private final void computeForwardPointers() {
|
private void computeForwardPointers() {
|
||||||
if ((mapBuf.get(127) & (1<<7)) != 0)
|
if ((mapBuf.get(127) & (1<<7)) != 0)
|
||||||
return;
|
return;
|
||||||
System.out.printf("Computing forward pointers...\n");
|
System.out.printf("Computing forward pointers...\n");
|
||||||
@@ -215,7 +215,7 @@ public final class TreeLogger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Get FEN string for root node position. */
|
/** Get FEN string for root node position. */
|
||||||
private final String getRootNodeFEN() {
|
private String getRootNodeFEN() {
|
||||||
int len = mapBuf.get(0);
|
int len = mapBuf.get(0);
|
||||||
byte[] fenB = new byte[len];
|
byte[] fenB = new byte[len];
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
@@ -243,7 +243,7 @@ public final class TreeLogger {
|
|||||||
|
|
||||||
/** Read a start/end entry.
|
/** Read a start/end entry.
|
||||||
* @return True if entry was a start entry, false if it was an end entry. */
|
* @return True if entry was a start entry, false if it was an end entry. */
|
||||||
private final boolean readEntry(int index, StartEntry se, EndEntry ee) {
|
private boolean readEntry(int index, StartEntry se, EndEntry ee) {
|
||||||
int offs = indexToFileOffs(index);
|
int offs = indexToFileOffs(index);
|
||||||
for (int i = 0; i < 16; i++)
|
for (int i = 0; i < 16; i++)
|
||||||
bb.put(i, mapBuf.get(offs + i));
|
bb.put(i, mapBuf.get(offs + i));
|
||||||
@@ -286,7 +286,7 @@ public final class TreeLogger {
|
|||||||
an.close();
|
an.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void mainLoop(Position rootPos) throws IOException {
|
private void mainLoop(Position rootPos) throws IOException {
|
||||||
int currIndex = -1;
|
int currIndex = -1;
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
|
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
|
||||||
String prevStr = "";
|
String prevStr = "";
|
||||||
@@ -326,7 +326,7 @@ public final class TreeLogger {
|
|||||||
String m = cmdStr;
|
String m = cmdStr;
|
||||||
StartEntry se = new StartEntry();
|
StartEntry se = new StartEntry();
|
||||||
EndEntry ee = new EndEntry();
|
EndEntry ee = new EndEntry();
|
||||||
ArrayList<Integer> found = new ArrayList<Integer>();
|
ArrayList<Integer> found = new ArrayList<>();
|
||||||
for (Integer c : children) {
|
for (Integer c : children) {
|
||||||
readEntries(c, se, ee);
|
readEntries(c, se, ee);
|
||||||
if (TextIO.moveToUCIString(se.move).equals(m))
|
if (TextIO.moveToUCIString(se.move).equals(m))
|
||||||
@@ -392,7 +392,7 @@ public final class TreeLogger {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final boolean isMove(String cmdStr) {
|
private boolean isMove(String cmdStr) {
|
||||||
if (cmdStr.length() != 4)
|
if (cmdStr.length() != 4)
|
||||||
return false;
|
return false;
|
||||||
cmdStr = cmdStr.toLowerCase();
|
cmdStr = cmdStr.toLowerCase();
|
||||||
@@ -410,9 +410,9 @@ public final class TreeLogger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Return all nodes with a given hash key. */
|
/** Return all nodes with a given hash key. */
|
||||||
private final ArrayList<Integer> getNodeForHashKey(long hashKey) {
|
private ArrayList<Integer> getNodeForHashKey(long hashKey) {
|
||||||
hashKey &= 0x0000ffffffffffffL;
|
hashKey &= 0x0000ffffffffffffL;
|
||||||
ArrayList<Integer> ret = new ArrayList<Integer>();
|
ArrayList<Integer> ret = new ArrayList<>();
|
||||||
StartEntry se = new StartEntry();
|
StartEntry se = new StartEntry();
|
||||||
EndEntry ee = new EndEntry();
|
EndEntry ee = new EndEntry();
|
||||||
for (int index = 0; index < numEntries; index++) {
|
for (int index = 0; index < numEntries; index++) {
|
||||||
@@ -429,7 +429,7 @@ public final class TreeLogger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Get hash key from an input string. */
|
/** Get hash key from an input string. */
|
||||||
private final long getHashKey(String s, long defKey) {
|
private long getHashKey(String s, long defKey) {
|
||||||
long key = defKey;
|
long key = defKey;
|
||||||
int idx = s.indexOf(' ');
|
int idx = s.indexOf(' ');
|
||||||
if (idx > 0) {
|
if (idx > 0) {
|
||||||
@@ -458,7 +458,7 @@ public final class TreeLogger {
|
|||||||
|
|
||||||
/** Get a list of integer parameters from an input string. */
|
/** Get a list of integer parameters from an input string. */
|
||||||
final ArrayList<Integer> getArgs(String s, int defVal) {
|
final ArrayList<Integer> getArgs(String s, int defVal) {
|
||||||
ArrayList<Integer> ret = new ArrayList<Integer>();
|
ArrayList<Integer> ret = new ArrayList<>();
|
||||||
String[] split = s.split(" ");
|
String[] split = s.split(" ");
|
||||||
try {
|
try {
|
||||||
for (int i = 1; i < split.length; i++)
|
for (int i = 1; i < split.length; i++)
|
||||||
@@ -479,7 +479,7 @@ public final class TreeLogger {
|
|||||||
return defVal;
|
return defVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void printHelp() {
|
private void printHelp() {
|
||||||
System.out.printf(" p - Print move sequence\n");
|
System.out.printf(" p - Print move sequence\n");
|
||||||
System.out.printf(" n - Print node info corresponding to move sequence\n");
|
System.out.printf(" n - Print node info corresponding to move sequence\n");
|
||||||
System.out.printf(" l [move] - List child nodes, optionally only for one move\n");
|
System.out.printf(" l [move] - List child nodes, optionally only for one move\n");
|
||||||
@@ -493,7 +493,7 @@ public final class TreeLogger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Read start/end entries for a tree node. Return true if the end entry exists. */
|
/** Read start/end entries for a tree node. Return true if the end entry exists. */
|
||||||
private final boolean readEntries(int index, StartEntry se, EndEntry ee) {
|
private boolean readEntries(int index, StartEntry se, EndEntry ee) {
|
||||||
boolean isStart = readEntry(index, se, ee);
|
boolean isStart = readEntry(index, se, ee);
|
||||||
if (isStart) {
|
if (isStart) {
|
||||||
int eIdx = se.endIndex;
|
int eIdx = se.endIndex;
|
||||||
@@ -510,7 +510,7 @@ public final class TreeLogger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Find the parent node to a node. */
|
/** Find the parent node to a node. */
|
||||||
private final int findParent(int index) {
|
private int findParent(int index) {
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
StartEntry se = new StartEntry();
|
StartEntry se = new StartEntry();
|
||||||
EndEntry ee = new EndEntry();
|
EndEntry ee = new EndEntry();
|
||||||
@@ -521,8 +521,8 @@ public final class TreeLogger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Find all children of a node. */
|
/** Find all children of a node. */
|
||||||
private final ArrayList<Integer> findChildren(int index) {
|
private ArrayList<Integer> findChildren(int index) {
|
||||||
ArrayList<Integer> ret = new ArrayList<Integer>();
|
ArrayList<Integer> ret = new ArrayList<>();
|
||||||
StartEntry se = new StartEntry();
|
StartEntry se = new StartEntry();
|
||||||
EndEntry ee = new EndEntry();
|
EndEntry ee = new EndEntry();
|
||||||
int child = index + 1;
|
int child = index + 1;
|
||||||
@@ -542,7 +542,7 @@ public final class TreeLogger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Get node position in parents children list. */
|
/** Get node position in parents children list. */
|
||||||
private final int getChildNo(int index) {
|
private int getChildNo(int index) {
|
||||||
ArrayList<Integer> childs = findChildren(findParent(index));
|
ArrayList<Integer> childs = findChildren(findParent(index));
|
||||||
for (int i = 0; i < childs.size(); i++)
|
for (int i = 0; i < childs.size(); i++)
|
||||||
if (childs.get(i) == index)
|
if (childs.get(i) == index)
|
||||||
@@ -551,8 +551,8 @@ public final class TreeLogger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Get list of nodes from root position to a node. */
|
/** Get list of nodes from root position to a node. */
|
||||||
private final ArrayList<Integer> getNodeSequence(int index) {
|
private ArrayList<Integer> getNodeSequence(int index) {
|
||||||
ArrayList<Integer> nodes = new ArrayList<Integer>();
|
ArrayList<Integer> nodes = new ArrayList<>();
|
||||||
nodes.add(index);
|
nodes.add(index);
|
||||||
while (index >= 0) {
|
while (index >= 0) {
|
||||||
index = findParent(index);
|
index = findParent(index);
|
||||||
@@ -563,8 +563,8 @@ public final class TreeLogger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Find list of moves from root node to a node. */
|
/** Find list of moves from root node to a node. */
|
||||||
private final ArrayList<Move> getMoveSequence(int index) {
|
private ArrayList<Move> getMoveSequence(int index) {
|
||||||
ArrayList<Move> moves = new ArrayList<Move>();
|
ArrayList<Move> moves = new ArrayList<>();
|
||||||
StartEntry se = new StartEntry();
|
StartEntry se = new StartEntry();
|
||||||
EndEntry ee = new EndEntry();
|
EndEntry ee = new EndEntry();
|
||||||
while (index >= 0) {
|
while (index >= 0) {
|
||||||
@@ -577,7 +577,7 @@ public final class TreeLogger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Find the position corresponding to a node. */
|
/** Find the position corresponding to a node. */
|
||||||
private final Position getPosition(Position rootPos, int index) {
|
private Position getPosition(Position rootPos, int index) {
|
||||||
ArrayList<Move> moves = getMoveSequence(index);
|
ArrayList<Move> moves = getMoveSequence(index);
|
||||||
Position ret = new Position(rootPos);
|
Position ret = new Position(rootPos);
|
||||||
UndoInfo ui = new UndoInfo();
|
UndoInfo ui = new UndoInfo();
|
||||||
@@ -586,10 +586,10 @@ public final class TreeLogger {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void printNodeInfo(Position rootPos, int index) {
|
private void printNodeInfo(Position rootPos, int index) {
|
||||||
printNodeInfo(rootPos, index, "");
|
printNodeInfo(rootPos, index, "");
|
||||||
}
|
}
|
||||||
private final void printNodeInfo(Position rootPos, int index, String filterMove) {
|
private void printNodeInfo(Position rootPos, int index, String filterMove) {
|
||||||
if (index < 0) { // Root node
|
if (index < 0) { // Root node
|
||||||
System.out.printf("%8d entries:%d\n", index, numEntries);
|
System.out.printf("%8d entries:%d\n", index, numEntries);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public class ComputerPlayerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testGetCommand() throws ChessParseError {
|
public void testGetCommand() throws ChessParseError {
|
||||||
System.out.println("getCommand");
|
System.out.println("getCommand");
|
||||||
ArrayList<Position> nullHist = new ArrayList<Position>();
|
ArrayList<Position> nullHist = new ArrayList<>();
|
||||||
|
|
||||||
Position pos = TextIO.readFEN("7k/5Q2/p5K1/8/8/8/8/8 b - - 99 80");
|
Position pos = TextIO.readFEN("7k/5Q2/p5K1/8/8/8/8/8 b - - 99 80");
|
||||||
ComputerPlayer cp = new ComputerPlayer();
|
ComputerPlayer cp = new ComputerPlayer();
|
||||||
|
|||||||
@@ -514,7 +514,7 @@ public class EvaluateTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Compute change in eval score for white after making "moveStr" in position "pos". */
|
/** Compute change in eval score for white after making "moveStr" in position "pos". */
|
||||||
private final int moveScore(Position pos, String moveStr) {
|
private int moveScore(Position pos, String moveStr) {
|
||||||
int score1 = evalWhite(pos);
|
int score1 = evalWhite(pos);
|
||||||
Position tmpPos = new Position(pos);
|
Position tmpPos = new Position(pos);
|
||||||
UndoInfo ui = new UndoInfo();
|
UndoInfo ui = new UndoInfo();
|
||||||
|
|||||||
@@ -434,7 +434,7 @@ public class MoveGenTest {
|
|||||||
MoveGen.MoveList moves = moveGen.pseudoLegalMoves(pos);
|
MoveGen.MoveList moves = moveGen.pseudoLegalMoves(pos);
|
||||||
if (onlyLegal)
|
if (onlyLegal)
|
||||||
MoveGen.removeIllegal(pos, moves);
|
MoveGen.removeIllegal(pos, moves);
|
||||||
ArrayList<String> strMoves = new ArrayList<String>();
|
ArrayList<String> strMoves = new ArrayList<>();
|
||||||
for (int mi = 0; mi < moves.size; mi++) {
|
for (int mi = 0; mi < moves.size; mi++) {
|
||||||
Move m = moves.m[mi];
|
Move m = moves.m[mi];
|
||||||
String mStr = TextIO.moveToUCIString(m);
|
String mStr = TextIO.moveToUCIString(m);
|
||||||
@@ -512,7 +512,7 @@ public class MoveGenTest {
|
|||||||
}
|
}
|
||||||
if (onlyLegal)
|
if (onlyLegal)
|
||||||
MoveGen.removeIllegal(pos, moves);
|
MoveGen.removeIllegal(pos, moves);
|
||||||
ArrayList<String> strMoves = new ArrayList<String>();
|
ArrayList<String> strMoves = new ArrayList<>();
|
||||||
for (int mi = 0; mi < moves.size; mi++) {
|
for (int mi = 0; mi < moves.size; mi++) {
|
||||||
Move m = moves.m[mi];
|
Move m = moves.m[mi];
|
||||||
String mStr = TextIO.moveToUCIString(m);
|
String mStr = TextIO.moveToUCIString(m);
|
||||||
@@ -527,7 +527,7 @@ public class MoveGenTest {
|
|||||||
MoveGen.MoveList moves = new MoveGen().checkEvasions(pos);
|
MoveGen.MoveList moves = new MoveGen().checkEvasions(pos);
|
||||||
if (onlyLegal)
|
if (onlyLegal)
|
||||||
MoveGen.removeIllegal(pos, moves);
|
MoveGen.removeIllegal(pos, moves);
|
||||||
ArrayList<String> strMoves = new ArrayList<String>();
|
ArrayList<String> strMoves = new ArrayList<>();
|
||||||
for (int mi = 0; mi < moves.size; mi++) {
|
for (int mi = 0; mi < moves.size; mi++) {
|
||||||
Move m = moves.m[mi];
|
Move m = moves.m[mi];
|
||||||
String mStr = TextIO.moveToUCIString(m);
|
String mStr = TextIO.moveToUCIString(m);
|
||||||
|
|||||||
@@ -395,9 +395,9 @@ public class PositionTest {
|
|||||||
"b5", "Nc3", "Nf6", "Nb1", "Ng8", "Nc3", "Nf6", "Nb1", "Ng8", "Nc3", "d5",
|
"b5", "Nc3", "Nf6", "Nb1", "Ng8", "Nc3", "Nf6", "Nb1", "Ng8", "Nc3", "d5",
|
||||||
"cxd6", "Qxd6", "h4", "Be6", "h5", "Nc6", "h6", "o-o-o", "hxg7", "Nf6", "gxh8Q", "Be7"
|
"cxd6", "Qxd6", "h4", "Be6", "h5", "Nc6", "h6", "o-o-o", "hxg7", "Nf6", "gxh8Q", "Be7"
|
||||||
};
|
};
|
||||||
List<UndoInfo> uiList = new ArrayList<UndoInfo>();
|
List<UndoInfo> uiList = new ArrayList<>();
|
||||||
List<Long> hashList = new ArrayList<Long>();
|
List<Long> hashList = new ArrayList<>();
|
||||||
List<Move> moveList = new ArrayList<Move>();
|
List<Move> moveList = new ArrayList<>();
|
||||||
for (int i = 0; i < moves.length; i++) {
|
for (int i = 0; i < moves.length; i++) {
|
||||||
uiList.add(new UndoInfo());
|
uiList.add(new UndoInfo());
|
||||||
Move m = TextIO.stringToMove(pos, moves[i]);
|
Move m = TextIO.stringToMove(pos, moves[i]);
|
||||||
@@ -413,7 +413,7 @@ public class PositionTest {
|
|||||||
pos.unMakeMove(moveList.get(i), uiList.get(i));
|
pos.unMakeMove(moveList.get(i), uiList.get(i));
|
||||||
long h = pos.zobristHash();
|
long h = pos.zobristHash();
|
||||||
assertEquals(h, pos.computeZobristHash());
|
assertEquals(h, pos.computeZobristHash());
|
||||||
assertEquals(h, i > 0 ? hashList.get(i - 1) : h1);
|
assertEquals(h, i > 0 ? (long)hashList.get(i - 1) : h1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ import org.petero.droidfish.gamelogic.TimeControlData.TimeControlField;
|
|||||||
public class GameTreeTest extends TestCase {
|
public class GameTreeTest extends TestCase {
|
||||||
|
|
||||||
/** Add a move to the game tree, with no comments or annotations. */
|
/** Add a move to the game tree, with no comments or annotations. */
|
||||||
private final int addStdMove(GameTree gt, String moveStr) {
|
private int addStdMove(GameTree gt, String moveStr) {
|
||||||
return gt.addMove(moveStr, "", 0, "", "");
|
return gt.addMove(moveStr, "", 0, "", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,7 +129,7 @@ public class GameTreeTest extends TestCase {
|
|||||||
assertEquals(2, varList.size());
|
assertEquals(2, varList.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String getMoveListAsString(GameTree gt) {
|
private String getMoveListAsString(GameTree gt) {
|
||||||
StringBuilder ret = new StringBuilder();
|
StringBuilder ret = new StringBuilder();
|
||||||
Pair<List<Node>, Integer> ml = gt.getMoveList();
|
Pair<List<Node>, Integer> ml = gt.getMoveList();
|
||||||
List<Node> lst = ml.first;
|
List<Node> lst = ml.first;
|
||||||
@@ -318,9 +318,9 @@ public class GameTreeTest extends TestCase {
|
|||||||
assertEquals(initialTime, gt.getRemainingTime(false, initialTime));
|
assertEquals(initialTime, gt.getRemainingTime(false, initialTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
private final List<PgnToken> getAllTokens(String s) {
|
private List<PgnToken> getAllTokens(String s) {
|
||||||
PgnScanner sc = new PgnScanner(s);
|
PgnScanner sc = new PgnScanner(s);
|
||||||
List<PgnToken> ret = new ArrayList<PgnToken>();
|
List<PgnToken> ret = new ArrayList<>();
|
||||||
while (true) {
|
while (true) {
|
||||||
PgnToken tok = sc.nextToken();
|
PgnToken tok = sc.nextToken();
|
||||||
if (tok.type == PgnToken.EOF)
|
if (tok.type == PgnToken.EOF)
|
||||||
@@ -729,7 +729,7 @@ public class GameTreeTest extends TestCase {
|
|||||||
assertTrue(tcData2.isSymmetric());
|
assertTrue(tcData2.isSymmetric());
|
||||||
assertTrue(tcData.equals(tcData2));
|
assertTrue(tcData.equals(tcData2));
|
||||||
|
|
||||||
Map<String,String> headers = new TreeMap<String,String>();
|
Map<String,String> headers = new TreeMap<>();
|
||||||
gt.getHeaders(headers);
|
gt.getHeaders(headers);
|
||||||
assertEquals("35/180", headers.get("TimeControl"));
|
assertEquals("35/180", headers.get("TimeControl"));
|
||||||
assertEquals(null, headers.get("WhiteTimeControl"));
|
assertEquals(null, headers.get("WhiteTimeControl"));
|
||||||
@@ -741,7 +741,7 @@ public class GameTreeTest extends TestCase {
|
|||||||
tcData2 = gt.getTimeControlData();
|
tcData2 = gt.getTimeControlData();
|
||||||
assertTrue(tcData2.isSymmetric());
|
assertTrue(tcData2.isSymmetric());
|
||||||
assertEquals(tcData, tcData2);
|
assertEquals(tcData, tcData2);
|
||||||
headers = new TreeMap<String,String>();
|
headers = new TreeMap<>();
|
||||||
gt.getHeaders(headers);
|
gt.getHeaders(headers);
|
||||||
assertEquals("35/180", headers.get("TimeControl"));
|
assertEquals("35/180", headers.get("TimeControl"));
|
||||||
assertEquals(null, headers.get("WhiteTimeControl"));
|
assertEquals(null, headers.get("WhiteTimeControl"));
|
||||||
@@ -757,7 +757,7 @@ public class GameTreeTest extends TestCase {
|
|||||||
tcData.tcB.add(new TimeControlField(60*1000,20,3004));
|
tcData.tcB.add(new TimeControlField(60*1000,20,3004));
|
||||||
tcData.tcB.add(new TimeControlField(30*1000,0,0));
|
tcData.tcB.add(new TimeControlField(30*1000,0,0));
|
||||||
gt.setTimeControlData(tcData);
|
gt.setTimeControlData(tcData);
|
||||||
headers = new TreeMap<String,String>();
|
headers = new TreeMap<>();
|
||||||
gt.getHeaders(headers);
|
gt.getHeaders(headers);
|
||||||
assertEquals(null, headers.get("TimeControl"));
|
assertEquals(null, headers.get("TimeControl"));
|
||||||
assertEquals("40/900:20/300.345:10/0+1:0+5", headers.get("WhiteTimeControl"));
|
assertEquals("40/900:20/300.345:10/0+1:0+5", headers.get("WhiteTimeControl"));
|
||||||
@@ -773,7 +773,7 @@ public class GameTreeTest extends TestCase {
|
|||||||
tcData2 = gt.getTimeControlData();
|
tcData2 = gt.getTimeControlData();
|
||||||
assertTrue(!tcData2.isSymmetric());
|
assertTrue(!tcData2.isSymmetric());
|
||||||
assertEquals(tcData, tcData2);
|
assertEquals(tcData, tcData2);
|
||||||
headers = new TreeMap<String,String>();
|
headers = new TreeMap<>();
|
||||||
gt.getHeaders(headers);
|
gt.getHeaders(headers);
|
||||||
assertEquals(null, headers.get("TimeControl"));
|
assertEquals(null, headers.get("TimeControl"));
|
||||||
assertEquals("40/900:20/300.345:10/0+1:0+5", headers.get("WhiteTimeControl"));
|
assertEquals("40/900:20/300.345:10/0+1:0+5", headers.get("WhiteTimeControl"));
|
||||||
@@ -782,7 +782,7 @@ public class GameTreeTest extends TestCase {
|
|||||||
tcData = new TimeControlData();
|
tcData = new TimeControlData();
|
||||||
tcData.setTimeControl(2*60*1000, 0, 12000);
|
tcData.setTimeControl(2*60*1000, 0, 12000);
|
||||||
gt.setTimeControlData(tcData);
|
gt.setTimeControlData(tcData);
|
||||||
headers = new TreeMap<String,String>();
|
headers = new TreeMap<>();
|
||||||
gt.getHeaders(headers);
|
gt.getHeaders(headers);
|
||||||
assertEquals("120+12", headers.get("TimeControl"));
|
assertEquals("120+12", headers.get("TimeControl"));
|
||||||
assertEquals(null, headers.get("WhiteTimeControl"));
|
assertEquals(null, headers.get("WhiteTimeControl"));
|
||||||
@@ -815,10 +815,10 @@ public class GameTreeTest extends TestCase {
|
|||||||
boolean res = gt.readPGN("[White \"a\"][Black \"b\"] f4 *", options);
|
boolean res = gt.readPGN("[White \"a\"][Black \"b\"] f4 *", options);
|
||||||
assertEquals(true, res);
|
assertEquals(true, res);
|
||||||
|
|
||||||
TreeMap<String,String> headers = new TreeMap<String,String>();
|
TreeMap<String,String> headers = new TreeMap<>();
|
||||||
headers.put("Event", "test");
|
headers.put("Event", "test");
|
||||||
gt.setHeaders(headers);
|
gt.setHeaders(headers);
|
||||||
TreeMap<String,String> newHeaders = new TreeMap<String,String>();
|
TreeMap<String,String> newHeaders = new TreeMap<>();
|
||||||
gt.getHeaders(newHeaders);
|
gt.getHeaders(newHeaders);
|
||||||
assertEquals("test", newHeaders.get("Event"));
|
assertEquals("test", newHeaders.get("Event"));
|
||||||
|
|
||||||
@@ -836,7 +836,7 @@ public class GameTreeTest extends TestCase {
|
|||||||
{
|
{
|
||||||
GameTree gt = new GameTree(null);
|
GameTree gt = new GameTree(null);
|
||||||
gt.readPGN("f3 e5 g4 Qh4", options);
|
gt.readPGN("f3 e5 g4 Qh4", options);
|
||||||
TreeMap<String,String> headers = new TreeMap<String,String>();
|
TreeMap<String,String> headers = new TreeMap<>();
|
||||||
gt.getHeaders(headers);
|
gt.getHeaders(headers);
|
||||||
assertEquals("0-1", headers.get("Result"));
|
assertEquals("0-1", headers.get("Result"));
|
||||||
|
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ public class MoveGenTest extends TestCase {
|
|||||||
if (onlyLegal) {
|
if (onlyLegal) {
|
||||||
moves = MoveGen.removeIllegal(pos, moves);
|
moves = MoveGen.removeIllegal(pos, moves);
|
||||||
}
|
}
|
||||||
ArrayList<String> strMoves = new ArrayList<String>();
|
ArrayList<String> strMoves = new ArrayList<>();
|
||||||
for (Move m : moves) {
|
for (Move m : moves) {
|
||||||
String mStr = TextIO.moveToString(pos, m, true, false);
|
String mStr = TextIO.moveToString(pos, m, true, false);
|
||||||
strMoves.add(mStr);
|
strMoves.add(mStr);
|
||||||
|
|||||||
@@ -347,9 +347,9 @@ public class PositionTest extends TestCase {
|
|||||||
"b5", "Nc3", "Nf6", "Nb1", "Ng8", "Nc3", "Nf6", "Nb1", "Ng8", "Nc3", "d5",
|
"b5", "Nc3", "Nf6", "Nb1", "Ng8", "Nc3", "Nf6", "Nb1", "Ng8", "Nc3", "d5",
|
||||||
"cxd6", "Qxd6", "h4", "Be6", "h5", "Nc6", "h6", "o-o-o", "hxg7", "Nf6", "gxh8Q", "Be7"
|
"cxd6", "Qxd6", "h4", "Be6", "h5", "Nc6", "h6", "o-o-o", "hxg7", "Nf6", "gxh8Q", "Be7"
|
||||||
};
|
};
|
||||||
List<UndoInfo> uiList = new ArrayList<UndoInfo>();
|
List<UndoInfo> uiList = new ArrayList<>();
|
||||||
List<Long> hashList = new ArrayList<Long>();
|
List<Long> hashList = new ArrayList<>();
|
||||||
List<Move> moveList = new ArrayList<Move>();
|
List<Move> moveList = new ArrayList<>();
|
||||||
for (int i = 0; i < moves.length; i++) {
|
for (int i = 0; i < moves.length; i++) {
|
||||||
uiList.add(new UndoInfo());
|
uiList.add(new UndoInfo());
|
||||||
Move m = TextIO.stringToMove(pos, moves[i]);
|
Move m = TextIO.stringToMove(pos, moves[i]);
|
||||||
@@ -365,7 +365,7 @@ public class PositionTest extends TestCase {
|
|||||||
pos.unMakeMove(moveList.get(i), uiList.get(i));
|
pos.unMakeMove(moveList.get(i), uiList.get(i));
|
||||||
long h = pos.zobristHash();
|
long h = pos.zobristHash();
|
||||||
assertEquals(h, pos.computeZobristHash());
|
assertEquals(h, pos.computeZobristHash());
|
||||||
assertEquals(h, i > 0 ? hashList.get(i - 1) : h1);
|
assertEquals(h, i > 0 ? (long)hashList.get(i - 1) : h1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ public class TextIOTest extends TestCase {
|
|||||||
return wasError;
|
return wasError;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static String moveToString(Position pos, Move move, boolean longForm) {
|
private static String moveToString(Position pos, Move move, boolean longForm) {
|
||||||
return TextIO.moveToString(pos, move, longForm, false);
|
return TextIO.moveToString(pos, move, longForm, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -126,11 +126,11 @@ public class TimeControlTest extends TestCase {
|
|||||||
public void testMultiTimeControl() {
|
public void testMultiTimeControl() {
|
||||||
TimeControl tc = new TimeControl();
|
TimeControl tc = new TimeControl();
|
||||||
TimeControlData tcData = new TimeControlData();
|
TimeControlData tcData = new TimeControlData();
|
||||||
tcData.tcW = new ArrayList<TimeControlField>();
|
tcData.tcW = new ArrayList<>();
|
||||||
tcData.tcW.add(tcf(120*60*1000, 40, 0));
|
tcData.tcW.add(tcf(120*60*1000, 40, 0));
|
||||||
tcData.tcW.add(tcf(60*60*1000, 20, 0));
|
tcData.tcW.add(tcf(60*60*1000, 20, 0));
|
||||||
tcData.tcW.add(tcf(30*60*1000, 0, 15*1000));
|
tcData.tcW.add(tcf(30*60*1000, 0, 15*1000));
|
||||||
tcData.tcB = new ArrayList<TimeControlField>();
|
tcData.tcB = new ArrayList<>();
|
||||||
tcData.tcB.add(tcf(5*60*1000, 60, 1000));
|
tcData.tcB.add(tcf(5*60*1000, 60, 1000));
|
||||||
tc.setTimeControl(tcData);
|
tc.setTimeControl(tcData);
|
||||||
|
|
||||||
@@ -236,11 +236,11 @@ public class TimeControlTest extends TestCase {
|
|||||||
public void testSerialize() throws IOException {
|
public void testSerialize() throws IOException {
|
||||||
TimeControl tc = new TimeControl();
|
TimeControl tc = new TimeControl();
|
||||||
TimeControlData tcData = new TimeControlData();
|
TimeControlData tcData = new TimeControlData();
|
||||||
tcData.tcW = new ArrayList<TimeControlField>();
|
tcData.tcW = new ArrayList<>();
|
||||||
tcData.tcW.add(tcf(120*60*1000, 40, 0));
|
tcData.tcW.add(tcf(120*60*1000, 40, 0));
|
||||||
tcData.tcW.add(tcf(60*60*1000, 20, 0));
|
tcData.tcW.add(tcf(60*60*1000, 20, 0));
|
||||||
tcData.tcW.add(tcf(30*60*1000, 0, 15*1000));
|
tcData.tcW.add(tcf(30*60*1000, 0, 15*1000));
|
||||||
tcData.tcB = new ArrayList<TimeControlField>();
|
tcData.tcB = new ArrayList<>();
|
||||||
tcData.tcB.add(tcf(5*60*1000, 60, 1000));
|
tcData.tcB.add(tcf(5*60*1000, 60, 1000));
|
||||||
tc.setTimeControl(tcData);
|
tc.setTimeControl(tcData);
|
||||||
|
|
||||||
|
|||||||
@@ -13,25 +13,25 @@ public class ProbeResultTest extends TestCase {
|
|||||||
assertEquals(0, ProbeResult.compareScore(0, 0, 0, 0));
|
assertEquals(0, ProbeResult.compareScore(0, 0, 0, 0));
|
||||||
assertEquals(0, ProbeResult.compareScore(1, 3, 1, 3));
|
assertEquals(0, ProbeResult.compareScore(1, 3, 1, 3));
|
||||||
assertEquals(0, ProbeResult.compareScore(-1, 4, -1, 4));
|
assertEquals(0, ProbeResult.compareScore(-1, 4, -1, 4));
|
||||||
assertEquals(true, ProbeResult.compareScore(0, 0, 1, 1) < 0);
|
assertTrue(ProbeResult.compareScore(0, 0, 1, 1) < 0);
|
||||||
assertEquals(true, ProbeResult.compareScore(1, 1, 1, 2) > 0);
|
assertTrue(ProbeResult.compareScore(1, 1, 1, 2) > 0);
|
||||||
assertEquals(true, ProbeResult.compareScore(-1, 1, 0, 0) < 0);
|
assertTrue(ProbeResult.compareScore(-1, 1, 0, 0) < 0);
|
||||||
assertEquals(true, ProbeResult.compareScore(-1, 20, -1, 10) > 0);
|
assertTrue(ProbeResult.compareScore(-1, 20, -1, 10) > 0);
|
||||||
assertEquals(true, ProbeResult.compareScore(-1, 20, 1, 21) < 0);
|
assertTrue(ProbeResult.compareScore(-1, 20, 1, 21) < 0);
|
||||||
assertEquals(true, ProbeResult.compareScore(-1, 20, 1, 19) < 0);
|
assertTrue(ProbeResult.compareScore(-1, 20, 1, 19) < 0);
|
||||||
|
|
||||||
assertEquals(true, ProbeResult.compareScore(1, 0, 0, 0) > 0);
|
assertTrue(ProbeResult.compareScore(1, 0, 0, 0) > 0);
|
||||||
assertEquals(true, ProbeResult.compareScore(1, 0, 1, 1) > 0);
|
assertTrue(ProbeResult.compareScore(1, 0, 1, 1) > 0);
|
||||||
assertEquals(true, ProbeResult.compareScore(0, 0, 1, 0) < 0);
|
assertTrue(ProbeResult.compareScore(0, 0, 1, 0) < 0);
|
||||||
assertEquals(true, ProbeResult.compareScore(1, 1, 1, 0) < 0);
|
assertTrue(ProbeResult.compareScore(1, 1, 1, 0) < 0);
|
||||||
|
|
||||||
assertEquals(true, ProbeResult.compareScore(-1, 0, 0, 0) < 0);
|
assertTrue(ProbeResult.compareScore(-1, 0, 0, 0) < 0);
|
||||||
assertEquals(true, ProbeResult.compareScore(-1, 0, -1, 1) < 0);
|
assertTrue(ProbeResult.compareScore(-1, 0, -1, 1) < 0);
|
||||||
assertEquals(true, ProbeResult.compareScore(0, 0, -1, 0) > 0);
|
assertTrue(ProbeResult.compareScore(0, 0, -1, 0) > 0);
|
||||||
assertEquals(true, ProbeResult.compareScore(-1, 1, -1, 0) > 0);
|
assertTrue(ProbeResult.compareScore(-1, 1, -1, 0) > 0);
|
||||||
|
|
||||||
assertEquals(true, ProbeResult.compareScore(-1, 0, 1, 0) < 0);
|
assertTrue(ProbeResult.compareScore(-1, 0, 1, 0) < 0);
|
||||||
assertEquals(true, ProbeResult.compareScore(1, 0, -1, 0) > 0);
|
assertTrue(ProbeResult.compareScore(1, 0, -1, 0) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCompareProbeResult() {
|
public void testCompareProbeResult() {
|
||||||
@@ -43,173 +43,173 @@ public class ProbeResultTest extends TestCase {
|
|||||||
assertEquals(0, new ProbeResult(Type.NONE, 0, 0).compareTo(new ProbeResult(Type.NONE, 1, 2)));
|
assertEquals(0, new ProbeResult(Type.NONE, 0, 0).compareTo(new ProbeResult(Type.NONE, 1, 2)));
|
||||||
|
|
||||||
// NONE vs DTM,DTZ,WDL
|
// NONE vs DTM,DTZ,WDL
|
||||||
assertEquals(true, new ProbeResult(Type.NONE, 0, 0).compareTo(new ProbeResult(Type.DTM, 0, 0)) > 0);
|
assertTrue(new ProbeResult(Type.NONE, 0, 0).compareTo(new ProbeResult(Type.DTM, 0, 0)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.NONE, 0, 0).compareTo(new ProbeResult(Type.DTZ, 0, 0)) > 0);
|
assertTrue(new ProbeResult(Type.NONE, 0, 0).compareTo(new ProbeResult(Type.DTZ, 0, 0)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.NONE, 0, 0).compareTo(new ProbeResult(Type.WDL, 0, 0)) > 0);
|
assertTrue(new ProbeResult(Type.NONE, 0, 0).compareTo(new ProbeResult(Type.WDL, 0, 0)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.NONE, 0, 0).compareTo(new ProbeResult(Type.DTM, 1, 1)) > 0);
|
assertTrue(new ProbeResult(Type.NONE, 0, 0).compareTo(new ProbeResult(Type.DTM, 1, 1)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.NONE, 0, 0).compareTo(new ProbeResult(Type.DTZ, 1, 1)) > 0);
|
assertTrue(new ProbeResult(Type.NONE, 0, 0).compareTo(new ProbeResult(Type.DTZ, 1, 1)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.NONE, 0, 0).compareTo(new ProbeResult(Type.WDL, 1, 1)) > 0);
|
assertTrue(new ProbeResult(Type.NONE, 0, 0).compareTo(new ProbeResult(Type.WDL, 1, 1)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.NONE, 0, 0).compareTo(new ProbeResult(Type.DTM, -1, 1)) > 0);
|
assertTrue(new ProbeResult(Type.NONE, 0, 0).compareTo(new ProbeResult(Type.DTM, -1, 1)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.NONE, 0, 0).compareTo(new ProbeResult(Type.DTZ, -1, 1)) > 0);
|
assertTrue(new ProbeResult(Type.NONE, 0, 0).compareTo(new ProbeResult(Type.DTZ, -1, 1)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.NONE, 0, 0).compareTo(new ProbeResult(Type.WDL, -1, 1)) > 0);
|
assertTrue(new ProbeResult(Type.NONE, 0, 0).compareTo(new ProbeResult(Type.WDL, -1, 1)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 0, 0).compareTo(new ProbeResult(Type.NONE, 0, 0)) < 0);
|
assertTrue(new ProbeResult(Type.DTM, 0, 0).compareTo(new ProbeResult(Type.NONE, 0, 0)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, 0, 0).compareTo(new ProbeResult(Type.NONE, 0, 0)) < 0);
|
assertTrue(new ProbeResult(Type.DTZ, 0, 0).compareTo(new ProbeResult(Type.NONE, 0, 0)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, 0, 0).compareTo(new ProbeResult(Type.NONE, 0, 0)) < 0);
|
assertTrue(new ProbeResult(Type.WDL, 0, 0).compareTo(new ProbeResult(Type.NONE, 0, 0)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 1, 1).compareTo(new ProbeResult(Type.NONE, 0, 0)) < 0);
|
assertTrue(new ProbeResult(Type.DTM, 1, 1).compareTo(new ProbeResult(Type.NONE, 0, 0)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, 1, 1).compareTo(new ProbeResult(Type.NONE, 0, 0)) < 0);
|
assertTrue(new ProbeResult(Type.DTZ, 1, 1).compareTo(new ProbeResult(Type.NONE, 0, 0)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, 1, 1).compareTo(new ProbeResult(Type.NONE, 0, 0)) < 0);
|
assertTrue(new ProbeResult(Type.WDL, 1, 1).compareTo(new ProbeResult(Type.NONE, 0, 0)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, -1, 1).compareTo(new ProbeResult(Type.NONE, 0, 0)) < 0);
|
assertTrue(new ProbeResult(Type.DTM, -1, 1).compareTo(new ProbeResult(Type.NONE, 0, 0)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, -1, 1).compareTo(new ProbeResult(Type.NONE, 0, 0)) < 0);
|
assertTrue(new ProbeResult(Type.DTZ, -1, 1).compareTo(new ProbeResult(Type.NONE, 0, 0)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, -1, 1).compareTo(new ProbeResult(Type.NONE, 0, 0)) < 0);
|
assertTrue(new ProbeResult(Type.WDL, -1, 1).compareTo(new ProbeResult(Type.NONE, 0, 0)) < 0);
|
||||||
|
|
||||||
assertEquals(true, new ProbeResult(Type.NONE, 1, 1).compareTo(new ProbeResult(Type.DTM, 0, 0)) > 0);
|
assertTrue(new ProbeResult(Type.NONE, 1, 1).compareTo(new ProbeResult(Type.DTM, 0, 0)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.NONE, 1, 1).compareTo(new ProbeResult(Type.DTZ, 0, 0)) > 0);
|
assertTrue(new ProbeResult(Type.NONE, 1, 1).compareTo(new ProbeResult(Type.DTZ, 0, 0)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.NONE, 1, 1).compareTo(new ProbeResult(Type.WDL, 0, 0)) > 0);
|
assertTrue(new ProbeResult(Type.NONE, 1, 1).compareTo(new ProbeResult(Type.WDL, 0, 0)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.NONE, 1, 1).compareTo(new ProbeResult(Type.DTM, 1, 1)) > 0);
|
assertTrue(new ProbeResult(Type.NONE, 1, 1).compareTo(new ProbeResult(Type.DTM, 1, 1)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.NONE, 1, 1).compareTo(new ProbeResult(Type.DTZ, 1, 1)) > 0);
|
assertTrue(new ProbeResult(Type.NONE, 1, 1).compareTo(new ProbeResult(Type.DTZ, 1, 1)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.NONE, 1, 1).compareTo(new ProbeResult(Type.WDL, 1, 1)) > 0);
|
assertTrue(new ProbeResult(Type.NONE, 1, 1).compareTo(new ProbeResult(Type.WDL, 1, 1)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.NONE, 1, 1).compareTo(new ProbeResult(Type.DTM, -1, 1)) > 0);
|
assertTrue(new ProbeResult(Type.NONE, 1, 1).compareTo(new ProbeResult(Type.DTM, -1, 1)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.NONE, 1, 1).compareTo(new ProbeResult(Type.DTZ, -1, 1)) > 0);
|
assertTrue(new ProbeResult(Type.NONE, 1, 1).compareTo(new ProbeResult(Type.DTZ, -1, 1)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.NONE, 1, 1).compareTo(new ProbeResult(Type.WDL, -1, 1)) > 0);
|
assertTrue(new ProbeResult(Type.NONE, 1, 1).compareTo(new ProbeResult(Type.WDL, -1, 1)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 0, 0).compareTo(new ProbeResult(Type.NONE, 1, 1)) < 0);
|
assertTrue(new ProbeResult(Type.DTM, 0, 0).compareTo(new ProbeResult(Type.NONE, 1, 1)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, 0, 0).compareTo(new ProbeResult(Type.NONE, 1, 1)) < 0);
|
assertTrue(new ProbeResult(Type.DTZ, 0, 0).compareTo(new ProbeResult(Type.NONE, 1, 1)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, 0, 0).compareTo(new ProbeResult(Type.NONE, 1, 1)) < 0);
|
assertTrue(new ProbeResult(Type.WDL, 0, 0).compareTo(new ProbeResult(Type.NONE, 1, 1)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 1, 1).compareTo(new ProbeResult(Type.NONE, 1, 1)) < 0);
|
assertTrue(new ProbeResult(Type.DTM, 1, 1).compareTo(new ProbeResult(Type.NONE, 1, 1)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, 1, 1).compareTo(new ProbeResult(Type.NONE, 1, 1)) < 0);
|
assertTrue(new ProbeResult(Type.DTZ, 1, 1).compareTo(new ProbeResult(Type.NONE, 1, 1)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, 1, 1).compareTo(new ProbeResult(Type.NONE, 1, 1)) < 0);
|
assertTrue(new ProbeResult(Type.WDL, 1, 1).compareTo(new ProbeResult(Type.NONE, 1, 1)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, -1, 1).compareTo(new ProbeResult(Type.NONE, 1, 1)) < 0);
|
assertTrue(new ProbeResult(Type.DTM, -1, 1).compareTo(new ProbeResult(Type.NONE, 1, 1)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, -1, 1).compareTo(new ProbeResult(Type.NONE, 1, 1)) < 0);
|
assertTrue(new ProbeResult(Type.DTZ, -1, 1).compareTo(new ProbeResult(Type.NONE, 1, 1)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, -1, 1).compareTo(new ProbeResult(Type.NONE, 1, 1)) < 0);
|
assertTrue(new ProbeResult(Type.WDL, -1, 1).compareTo(new ProbeResult(Type.NONE, 1, 1)) < 0);
|
||||||
|
|
||||||
assertEquals(true, new ProbeResult(Type.NONE, -1, 1).compareTo(new ProbeResult(Type.DTM, 0, 0)) > 0);
|
assertTrue(new ProbeResult(Type.NONE, -1, 1).compareTo(new ProbeResult(Type.DTM, 0, 0)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.NONE, -1, 1).compareTo(new ProbeResult(Type.DTZ, 0, 0)) > 0);
|
assertTrue(new ProbeResult(Type.NONE, -1, 1).compareTo(new ProbeResult(Type.DTZ, 0, 0)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.NONE, -1, 1).compareTo(new ProbeResult(Type.WDL, 0, 0)) > 0);
|
assertTrue(new ProbeResult(Type.NONE, -1, 1).compareTo(new ProbeResult(Type.WDL, 0, 0)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.NONE, -1, 1).compareTo(new ProbeResult(Type.DTM, 1, 1)) > 0);
|
assertTrue(new ProbeResult(Type.NONE, -1, 1).compareTo(new ProbeResult(Type.DTM, 1, 1)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.NONE, -1, 1).compareTo(new ProbeResult(Type.DTZ, 1, 1)) > 0);
|
assertTrue(new ProbeResult(Type.NONE, -1, 1).compareTo(new ProbeResult(Type.DTZ, 1, 1)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.NONE, -1, 1).compareTo(new ProbeResult(Type.WDL, 1, 1)) > 0);
|
assertTrue(new ProbeResult(Type.NONE, -1, 1).compareTo(new ProbeResult(Type.WDL, 1, 1)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.NONE, -1, 1).compareTo(new ProbeResult(Type.DTM, -1, 1)) > 0);
|
assertTrue(new ProbeResult(Type.NONE, -1, 1).compareTo(new ProbeResult(Type.DTM, -1, 1)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.NONE, -1, 1).compareTo(new ProbeResult(Type.DTZ, -1, 1)) > 0);
|
assertTrue(new ProbeResult(Type.NONE, -1, 1).compareTo(new ProbeResult(Type.DTZ, -1, 1)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.NONE, -1, 1).compareTo(new ProbeResult(Type.WDL, -1, 1)) > 0);
|
assertTrue(new ProbeResult(Type.NONE, -1, 1).compareTo(new ProbeResult(Type.WDL, -1, 1)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 0, 0).compareTo(new ProbeResult(Type.NONE, -1, 1)) < 0);
|
assertTrue(new ProbeResult(Type.DTM, 0, 0).compareTo(new ProbeResult(Type.NONE, -1, 1)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, 0, 0).compareTo(new ProbeResult(Type.NONE, -1, 1)) < 0);
|
assertTrue(new ProbeResult(Type.DTZ, 0, 0).compareTo(new ProbeResult(Type.NONE, -1, 1)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, 0, 0).compareTo(new ProbeResult(Type.NONE, -1, 1)) < 0);
|
assertTrue(new ProbeResult(Type.WDL, 0, 0).compareTo(new ProbeResult(Type.NONE, -1, 1)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 1, 1).compareTo(new ProbeResult(Type.NONE, -1, 1)) < 0);
|
assertTrue(new ProbeResult(Type.DTM, 1, 1).compareTo(new ProbeResult(Type.NONE, -1, 1)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, 1, 1).compareTo(new ProbeResult(Type.NONE, -1, 1)) < 0);
|
assertTrue(new ProbeResult(Type.DTZ, 1, 1).compareTo(new ProbeResult(Type.NONE, -1, 1)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, 1, 1).compareTo(new ProbeResult(Type.NONE, -1, 1)) < 0);
|
assertTrue(new ProbeResult(Type.WDL, 1, 1).compareTo(new ProbeResult(Type.NONE, -1, 1)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, -1, 1).compareTo(new ProbeResult(Type.NONE, -1, 1)) < 0);
|
assertTrue(new ProbeResult(Type.DTM, -1, 1).compareTo(new ProbeResult(Type.NONE, -1, 1)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, -1, 1).compareTo(new ProbeResult(Type.NONE, -1, 1)) < 0);
|
assertTrue(new ProbeResult(Type.DTZ, -1, 1).compareTo(new ProbeResult(Type.NONE, -1, 1)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, -1, 1).compareTo(new ProbeResult(Type.NONE, -1, 1)) < 0);
|
assertTrue(new ProbeResult(Type.WDL, -1, 1).compareTo(new ProbeResult(Type.NONE, -1, 1)) < 0);
|
||||||
|
|
||||||
// DTM vs DTM
|
// DTM vs DTM
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 1, 10).compareTo(new ProbeResult(Type.DTM, 1, 10)) == 0);
|
assertTrue(new ProbeResult(Type.DTM, 1, 10).compareTo(new ProbeResult(Type.DTM, 1, 10)) == 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 1, 10).compareTo(new ProbeResult(Type.DTM, 1, 11)) < 0);
|
assertTrue(new ProbeResult(Type.DTM, 1, 10).compareTo(new ProbeResult(Type.DTM, 1, 11)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 1, 11).compareTo(new ProbeResult(Type.DTM, 1, 10)) > 0);
|
assertTrue(new ProbeResult(Type.DTM, 1, 11).compareTo(new ProbeResult(Type.DTM, 1, 10)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 0, 0).compareTo(new ProbeResult(Type.DTM, 0, 0)) == 0);
|
assertTrue(new ProbeResult(Type.DTM, 0, 0).compareTo(new ProbeResult(Type.DTM, 0, 0)) == 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 0, 0).compareTo(new ProbeResult(Type.DTM, 1, 1)) > 0);
|
assertTrue(new ProbeResult(Type.DTM, 0, 0).compareTo(new ProbeResult(Type.DTM, 1, 1)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 1, 1).compareTo(new ProbeResult(Type.DTM, 0, 0)) < 0);
|
assertTrue(new ProbeResult(Type.DTM, 1, 1).compareTo(new ProbeResult(Type.DTM, 0, 0)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, -1, 1).compareTo(new ProbeResult(Type.DTM, -1, 1)) == 0);
|
assertTrue(new ProbeResult(Type.DTM, -1, 1).compareTo(new ProbeResult(Type.DTM, -1, 1)) == 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, -1, 1).compareTo(new ProbeResult(Type.DTM, 0, 0)) > 0);
|
assertTrue(new ProbeResult(Type.DTM, -1, 1).compareTo(new ProbeResult(Type.DTM, 0, 0)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 0, 0).compareTo(new ProbeResult(Type.DTM, -1, 1)) < 0);
|
assertTrue(new ProbeResult(Type.DTM, 0, 0).compareTo(new ProbeResult(Type.DTM, -1, 1)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, -1, 3).compareTo(new ProbeResult(Type.DTM, -1, 3)) == 0);
|
assertTrue(new ProbeResult(Type.DTM, -1, 3).compareTo(new ProbeResult(Type.DTM, -1, 3)) == 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, -1, 3).compareTo(new ProbeResult(Type.DTM, -1, 5)) > 0);
|
assertTrue(new ProbeResult(Type.DTM, -1, 3).compareTo(new ProbeResult(Type.DTM, -1, 5)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, -1, 5).compareTo(new ProbeResult(Type.DTM, -1, 3)) < 0);
|
assertTrue(new ProbeResult(Type.DTM, -1, 5).compareTo(new ProbeResult(Type.DTM, -1, 3)) < 0);
|
||||||
|
|
||||||
// DTZ vs DTZ
|
// DTZ vs DTZ
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, 1, 10).compareTo(new ProbeResult(Type.DTZ, 1, 10)) == 0);
|
assertTrue(new ProbeResult(Type.DTZ, 1, 10).compareTo(new ProbeResult(Type.DTZ, 1, 10)) == 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, 1, 10).compareTo(new ProbeResult(Type.DTZ, 1, 11)) < 0);
|
assertTrue(new ProbeResult(Type.DTZ, 1, 10).compareTo(new ProbeResult(Type.DTZ, 1, 11)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, 1, 11).compareTo(new ProbeResult(Type.DTZ, 1, 10)) > 0);
|
assertTrue(new ProbeResult(Type.DTZ, 1, 11).compareTo(new ProbeResult(Type.DTZ, 1, 10)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, 0, 0).compareTo(new ProbeResult(Type.DTZ, 0, 0)) == 0);
|
assertTrue(new ProbeResult(Type.DTZ, 0, 0).compareTo(new ProbeResult(Type.DTZ, 0, 0)) == 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, 0, 0).compareTo(new ProbeResult(Type.DTZ, 1, 1)) > 0);
|
assertTrue(new ProbeResult(Type.DTZ, 0, 0).compareTo(new ProbeResult(Type.DTZ, 1, 1)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, 1, 1).compareTo(new ProbeResult(Type.DTZ, 0, 0)) < 0);
|
assertTrue(new ProbeResult(Type.DTZ, 1, 1).compareTo(new ProbeResult(Type.DTZ, 0, 0)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, -1, 1).compareTo(new ProbeResult(Type.DTZ, -1, 1)) == 0);
|
assertTrue(new ProbeResult(Type.DTZ, -1, 1).compareTo(new ProbeResult(Type.DTZ, -1, 1)) == 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, -1, 1).compareTo(new ProbeResult(Type.DTZ, 0, 0)) > 0);
|
assertTrue(new ProbeResult(Type.DTZ, -1, 1).compareTo(new ProbeResult(Type.DTZ, 0, 0)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, 0, 0).compareTo(new ProbeResult(Type.DTZ, -1, 1)) < 0);
|
assertTrue(new ProbeResult(Type.DTZ, 0, 0).compareTo(new ProbeResult(Type.DTZ, -1, 1)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, -1, 3).compareTo(new ProbeResult(Type.DTZ, -1, 3)) == 0);
|
assertTrue(new ProbeResult(Type.DTZ, -1, 3).compareTo(new ProbeResult(Type.DTZ, -1, 3)) == 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, -1, 3).compareTo(new ProbeResult(Type.DTZ, -1, 5)) > 0);
|
assertTrue(new ProbeResult(Type.DTZ, -1, 3).compareTo(new ProbeResult(Type.DTZ, -1, 5)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, -1, 5).compareTo(new ProbeResult(Type.DTZ, -1, 3)) < 0);
|
assertTrue(new ProbeResult(Type.DTZ, -1, 5).compareTo(new ProbeResult(Type.DTZ, -1, 3)) < 0);
|
||||||
|
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, -1, 1).compareTo(new ProbeResult(Type.WDL, -1, 1)) == 0);
|
assertTrue(new ProbeResult(Type.WDL, -1, 1).compareTo(new ProbeResult(Type.WDL, -1, 1)) == 0);
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, -1, 1).compareTo(new ProbeResult(Type.WDL, 0, 0)) > 0);
|
assertTrue(new ProbeResult(Type.WDL, -1, 1).compareTo(new ProbeResult(Type.WDL, 0, 0)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, -1, 1).compareTo(new ProbeResult(Type.WDL, 1, 1)) > 0);
|
assertTrue(new ProbeResult(Type.WDL, -1, 1).compareTo(new ProbeResult(Type.WDL, 1, 1)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, 0, 0).compareTo(new ProbeResult(Type.WDL, -1, 1)) < 0);
|
assertTrue(new ProbeResult(Type.WDL, 0, 0).compareTo(new ProbeResult(Type.WDL, -1, 1)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, 0, 0).compareTo(new ProbeResult(Type.WDL, 0, 0)) == 0);
|
assertTrue(new ProbeResult(Type.WDL, 0, 0).compareTo(new ProbeResult(Type.WDL, 0, 0)) == 0);
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, 0, 0).compareTo(new ProbeResult(Type.WDL, 1, 1)) > 0);
|
assertTrue(new ProbeResult(Type.WDL, 0, 0).compareTo(new ProbeResult(Type.WDL, 1, 1)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, 1, 1).compareTo(new ProbeResult(Type.WDL, -1, 1)) < 0);
|
assertTrue(new ProbeResult(Type.WDL, 1, 1).compareTo(new ProbeResult(Type.WDL, -1, 1)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, 1, 1).compareTo(new ProbeResult(Type.WDL, 0, 0)) < 0);
|
assertTrue(new ProbeResult(Type.WDL, 1, 1).compareTo(new ProbeResult(Type.WDL, 0, 0)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, 1, 1).compareTo(new ProbeResult(Type.WDL, 1, 1)) == 0);
|
assertTrue(new ProbeResult(Type.WDL, 1, 1).compareTo(new ProbeResult(Type.WDL, 1, 1)) == 0);
|
||||||
|
|
||||||
// DTM vs DTZ
|
// DTM vs DTZ
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 1, 10).compareTo(new ProbeResult(Type.DTZ, 1, 11)) < 0);
|
assertTrue(new ProbeResult(Type.DTM, 1, 10).compareTo(new ProbeResult(Type.DTZ, 1, 11)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 1, 10).compareTo(new ProbeResult(Type.DTZ, 1, 9)) < 0);
|
assertTrue(new ProbeResult(Type.DTM, 1, 10).compareTo(new ProbeResult(Type.DTZ, 1, 9)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 1, 10).compareTo(new ProbeResult(Type.DTZ, 0, 0)) < 0);
|
assertTrue(new ProbeResult(Type.DTM, 1, 10).compareTo(new ProbeResult(Type.DTZ, 0, 0)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 1, 10).compareTo(new ProbeResult(Type.DTZ, -1, 11)) < 0);
|
assertTrue(new ProbeResult(Type.DTM, 1, 10).compareTo(new ProbeResult(Type.DTZ, -1, 11)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 1, 10).compareTo(new ProbeResult(Type.DTZ, -1, 9)) < 0);
|
assertTrue(new ProbeResult(Type.DTM, 1, 10).compareTo(new ProbeResult(Type.DTZ, -1, 9)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, 1, 11).compareTo(new ProbeResult(Type.DTM, 1, 10)) > 0);
|
assertTrue(new ProbeResult(Type.DTZ, 1, 11).compareTo(new ProbeResult(Type.DTM, 1, 10)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, 1, 9).compareTo(new ProbeResult(Type.DTM, 1, 10)) > 0);
|
assertTrue(new ProbeResult(Type.DTZ, 1, 9).compareTo(new ProbeResult(Type.DTM, 1, 10)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, 0, 0).compareTo(new ProbeResult(Type.DTM, 1, 10)) > 0);
|
assertTrue(new ProbeResult(Type.DTZ, 0, 0).compareTo(new ProbeResult(Type.DTM, 1, 10)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, -1, 11).compareTo(new ProbeResult(Type.DTM, 1, 10)) > 0);
|
assertTrue(new ProbeResult(Type.DTZ, -1, 11).compareTo(new ProbeResult(Type.DTM, 1, 10)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, -1, 9).compareTo(new ProbeResult(Type.DTM, 1, 10)) > 0);
|
assertTrue(new ProbeResult(Type.DTZ, -1, 9).compareTo(new ProbeResult(Type.DTM, 1, 10)) > 0);
|
||||||
|
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 0, 0).compareTo(new ProbeResult(Type.DTZ, 0, 0)) == 0);
|
assertTrue(new ProbeResult(Type.DTM, 0, 0).compareTo(new ProbeResult(Type.DTZ, 0, 0)) == 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 0, 0).compareTo(new ProbeResult(Type.DTZ, 1, 3)) > 0);
|
assertTrue(new ProbeResult(Type.DTM, 0, 0).compareTo(new ProbeResult(Type.DTZ, 1, 3)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 0, 0).compareTo(new ProbeResult(Type.DTZ, -1, 4)) < 0);
|
assertTrue(new ProbeResult(Type.DTM, 0, 0).compareTo(new ProbeResult(Type.DTZ, -1, 4)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, 0, 0).compareTo(new ProbeResult(Type.DTM, 0, 0)) == 0);
|
assertTrue(new ProbeResult(Type.DTZ, 0, 0).compareTo(new ProbeResult(Type.DTM, 0, 0)) == 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, 1, 3).compareTo(new ProbeResult(Type.DTM, 0, 0)) < 0);
|
assertTrue(new ProbeResult(Type.DTZ, 1, 3).compareTo(new ProbeResult(Type.DTM, 0, 0)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, -1, 4).compareTo(new ProbeResult(Type.DTM, 0, 0)) > 0);
|
assertTrue(new ProbeResult(Type.DTZ, -1, 4).compareTo(new ProbeResult(Type.DTM, 0, 0)) > 0);
|
||||||
|
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, -1, 8).compareTo(new ProbeResult(Type.DTZ, -1, 7)) > 0);
|
assertTrue(new ProbeResult(Type.DTM, -1, 8).compareTo(new ProbeResult(Type.DTZ, -1, 7)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, -1, 8).compareTo(new ProbeResult(Type.DTZ, -1, 9)) > 0);
|
assertTrue(new ProbeResult(Type.DTM, -1, 8).compareTo(new ProbeResult(Type.DTZ, -1, 9)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, -1, 8).compareTo(new ProbeResult(Type.DTZ, 0, 0)) > 0);
|
assertTrue(new ProbeResult(Type.DTM, -1, 8).compareTo(new ProbeResult(Type.DTZ, 0, 0)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, -1, 8).compareTo(new ProbeResult(Type.DTZ, 1, 7)) > 0);
|
assertTrue(new ProbeResult(Type.DTM, -1, 8).compareTo(new ProbeResult(Type.DTZ, 1, 7)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, -1, 8).compareTo(new ProbeResult(Type.DTZ, 1, 9)) > 0);
|
assertTrue(new ProbeResult(Type.DTM, -1, 8).compareTo(new ProbeResult(Type.DTZ, 1, 9)) > 0);
|
||||||
|
|
||||||
// DTM vs WDL
|
// DTM vs WDL
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 1, 10).compareTo(new ProbeResult(Type.WDL, 1, 1)) < 0);
|
assertTrue(new ProbeResult(Type.DTM, 1, 10).compareTo(new ProbeResult(Type.WDL, 1, 1)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 1, 10).compareTo(new ProbeResult(Type.WDL, 0, 0)) < 0);
|
assertTrue(new ProbeResult(Type.DTM, 1, 10).compareTo(new ProbeResult(Type.WDL, 0, 0)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 1, 10).compareTo(new ProbeResult(Type.WDL, -1, 1)) < 0);
|
assertTrue(new ProbeResult(Type.DTM, 1, 10).compareTo(new ProbeResult(Type.WDL, -1, 1)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, 1, 1).compareTo(new ProbeResult(Type.DTM, 1, 10)) > 0);
|
assertTrue(new ProbeResult(Type.WDL, 1, 1).compareTo(new ProbeResult(Type.DTM, 1, 10)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, 0, 0).compareTo(new ProbeResult(Type.DTM, 1, 10)) > 0);
|
assertTrue(new ProbeResult(Type.WDL, 0, 0).compareTo(new ProbeResult(Type.DTM, 1, 10)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, -1, 1).compareTo(new ProbeResult(Type.DTM, 1, 10)) > 0);
|
assertTrue(new ProbeResult(Type.WDL, -1, 1).compareTo(new ProbeResult(Type.DTM, 1, 10)) > 0);
|
||||||
|
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 0, 0).compareTo(new ProbeResult(Type.WDL, 0, 0)) == 0);
|
assertTrue(new ProbeResult(Type.DTM, 0, 0).compareTo(new ProbeResult(Type.WDL, 0, 0)) == 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 0, 0).compareTo(new ProbeResult(Type.WDL, 1, 1)) > 0);
|
assertTrue(new ProbeResult(Type.DTM, 0, 0).compareTo(new ProbeResult(Type.WDL, 1, 1)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 0, 0).compareTo(new ProbeResult(Type.WDL, -1, 1)) < 0);
|
assertTrue(new ProbeResult(Type.DTM, 0, 0).compareTo(new ProbeResult(Type.WDL, -1, 1)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, 0, 0).compareTo(new ProbeResult(Type.DTM, 0, 0)) == 0);
|
assertTrue(new ProbeResult(Type.WDL, 0, 0).compareTo(new ProbeResult(Type.DTM, 0, 0)) == 0);
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, 1, 1).compareTo(new ProbeResult(Type.DTM, 0, 0)) < 0);
|
assertTrue(new ProbeResult(Type.WDL, 1, 1).compareTo(new ProbeResult(Type.DTM, 0, 0)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, -1, 1).compareTo(new ProbeResult(Type.DTM, 0, 0)) > 0);
|
assertTrue(new ProbeResult(Type.WDL, -1, 1).compareTo(new ProbeResult(Type.DTM, 0, 0)) > 0);
|
||||||
|
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, -1, 8).compareTo(new ProbeResult(Type.WDL, -1, 1)) > 0);
|
assertTrue(new ProbeResult(Type.DTM, -1, 8).compareTo(new ProbeResult(Type.WDL, -1, 1)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, -1, 8).compareTo(new ProbeResult(Type.WDL, 0, 0)) > 0);
|
assertTrue(new ProbeResult(Type.DTM, -1, 8).compareTo(new ProbeResult(Type.WDL, 0, 0)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, -1, 8).compareTo(new ProbeResult(Type.WDL, 1, 1)) > 0);
|
assertTrue(new ProbeResult(Type.DTM, -1, 8).compareTo(new ProbeResult(Type.WDL, 1, 1)) > 0);
|
||||||
|
|
||||||
// DTZ vs WDL
|
// DTZ vs WDL
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, 1, 10).compareTo(new ProbeResult(Type.WDL, 1, 1)) < 0);
|
assertTrue(new ProbeResult(Type.DTZ, 1, 10).compareTo(new ProbeResult(Type.WDL, 1, 1)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, 1, 10).compareTo(new ProbeResult(Type.WDL, 0, 0)) < 0);
|
assertTrue(new ProbeResult(Type.DTZ, 1, 10).compareTo(new ProbeResult(Type.WDL, 0, 0)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, 1, 10).compareTo(new ProbeResult(Type.WDL, -1, 1)) < 0);
|
assertTrue(new ProbeResult(Type.DTZ, 1, 10).compareTo(new ProbeResult(Type.WDL, -1, 1)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, 1, 1).compareTo(new ProbeResult(Type.DTZ, 1, 10)) > 0);
|
assertTrue(new ProbeResult(Type.WDL, 1, 1).compareTo(new ProbeResult(Type.DTZ, 1, 10)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, 0, 0).compareTo(new ProbeResult(Type.DTZ, 1, 10)) > 0);
|
assertTrue(new ProbeResult(Type.WDL, 0, 0).compareTo(new ProbeResult(Type.DTZ, 1, 10)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, -1, 1).compareTo(new ProbeResult(Type.DTZ, 1, 10)) > 0);
|
assertTrue(new ProbeResult(Type.WDL, -1, 1).compareTo(new ProbeResult(Type.DTZ, 1, 10)) > 0);
|
||||||
|
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, 0, 0).compareTo(new ProbeResult(Type.WDL, 0, 0)) == 0);
|
assertTrue(new ProbeResult(Type.DTZ, 0, 0).compareTo(new ProbeResult(Type.WDL, 0, 0)) == 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, 0, 0).compareTo(new ProbeResult(Type.WDL, 1, 1)) > 0);
|
assertTrue(new ProbeResult(Type.DTZ, 0, 0).compareTo(new ProbeResult(Type.WDL, 1, 1)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, 0, 0).compareTo(new ProbeResult(Type.WDL, -1, 1)) < 0);
|
assertTrue(new ProbeResult(Type.DTZ, 0, 0).compareTo(new ProbeResult(Type.WDL, -1, 1)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, 0, 0).compareTo(new ProbeResult(Type.DTZ, 0, 0)) == 0);
|
assertTrue(new ProbeResult(Type.WDL, 0, 0).compareTo(new ProbeResult(Type.DTZ, 0, 0)) == 0);
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, 1, 1).compareTo(new ProbeResult(Type.DTZ, 0, 0)) < 0);
|
assertTrue(new ProbeResult(Type.WDL, 1, 1).compareTo(new ProbeResult(Type.DTZ, 0, 0)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.WDL, -1, 1).compareTo(new ProbeResult(Type.DTZ, 0, 0)) > 0);
|
assertTrue(new ProbeResult(Type.WDL, -1, 1).compareTo(new ProbeResult(Type.DTZ, 0, 0)) > 0);
|
||||||
|
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, -1, 8).compareTo(new ProbeResult(Type.WDL, -1, 1)) > 0);
|
assertTrue(new ProbeResult(Type.DTZ, -1, 8).compareTo(new ProbeResult(Type.WDL, -1, 1)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, -1, 8).compareTo(new ProbeResult(Type.WDL, 0, 0)) > 0);
|
assertTrue(new ProbeResult(Type.DTZ, -1, 8).compareTo(new ProbeResult(Type.WDL, 0, 0)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, -1, 8).compareTo(new ProbeResult(Type.WDL, 1, 1)) > 0);
|
assertTrue(new ProbeResult(Type.DTZ, -1, 8).compareTo(new ProbeResult(Type.WDL, 1, 1)) > 0);
|
||||||
|
|
||||||
// Win-in-zero and loss-in-zero
|
// Win-in-zero and loss-in-zero
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 1, 0).compareTo(new ProbeResult(Type.DTM, 0, 0)) < 0);
|
assertTrue(new ProbeResult(Type.DTM, 1, 0).compareTo(new ProbeResult(Type.DTM, 0, 0)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 0, 0).compareTo(new ProbeResult(Type.DTM, 1, 0)) > 0);
|
assertTrue(new ProbeResult(Type.DTM, 0, 0).compareTo(new ProbeResult(Type.DTM, 1, 0)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, -1, 0).compareTo(new ProbeResult(Type.DTM, 0, 0)) > 0);
|
assertTrue(new ProbeResult(Type.DTM, -1, 0).compareTo(new ProbeResult(Type.DTM, 0, 0)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTM, 0, 0).compareTo(new ProbeResult(Type.DTM, -1, 0)) < 0);
|
assertTrue(new ProbeResult(Type.DTM, 0, 0).compareTo(new ProbeResult(Type.DTM, -1, 0)) < 0);
|
||||||
|
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, 1, 0).compareTo(new ProbeResult(Type.DTZ, 0, 0)) < 0);
|
assertTrue(new ProbeResult(Type.DTZ, 1, 0).compareTo(new ProbeResult(Type.DTZ, 0, 0)) < 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, 0, 0).compareTo(new ProbeResult(Type.DTZ, 1, 0)) > 0);
|
assertTrue(new ProbeResult(Type.DTZ, 0, 0).compareTo(new ProbeResult(Type.DTZ, 1, 0)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, -1, 0).compareTo(new ProbeResult(Type.DTZ, 0, 0)) > 0);
|
assertTrue(new ProbeResult(Type.DTZ, -1, 0).compareTo(new ProbeResult(Type.DTZ, 0, 0)) > 0);
|
||||||
assertEquals(true, new ProbeResult(Type.DTZ, 0, 0).compareTo(new ProbeResult(Type.DTZ, -1, 0)) < 0);
|
assertTrue(new ProbeResult(Type.DTZ, 0, 0).compareTo(new ProbeResult(Type.DTZ, -1, 0)) < 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class ChessEngineResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<ChessEngine> resolveEngines() {
|
public List<ChessEngine> resolveEngines() {
|
||||||
List<ChessEngine> result = new ArrayList<ChessEngine>();
|
List<ChessEngine> result = new ArrayList<>();
|
||||||
final Intent intent = new Intent(ENGINE_PROVIDER_MARKER);
|
final Intent intent = new Intent(ENGINE_PROVIDER_MARKER);
|
||||||
List<ResolveInfo> list = context.getPackageManager()
|
List<ResolveInfo> list = context.getPackageManager()
|
||||||
.queryIntentActivities(intent, PackageManager.GET_META_DATA);
|
.queryIntentActivities(intent, PackageManager.GET_META_DATA);
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ public class SVGParser {
|
|||||||
//Util.debug("Parsing numbers from: '" + s + "'");
|
//Util.debug("Parsing numbers from: '" + s + "'");
|
||||||
int n = s.length();
|
int n = s.length();
|
||||||
int p = 0;
|
int p = 0;
|
||||||
ArrayList<Float> numbers = new ArrayList<Float>();
|
ArrayList<Float> numbers = new ArrayList<>();
|
||||||
boolean skipChar = false;
|
boolean skipChar = false;
|
||||||
for (int i = 1; i < n; i++) {
|
for (int i = 1; i < n; i++) {
|
||||||
if (skipChar) {
|
if (skipChar) {
|
||||||
@@ -649,8 +649,8 @@ public class SVGParser {
|
|||||||
boolean isLinear;
|
boolean isLinear;
|
||||||
float x1, y1, x2, y2;
|
float x1, y1, x2, y2;
|
||||||
float x, y, radius;
|
float x, y, radius;
|
||||||
ArrayList<Float> positions = new ArrayList<Float>();
|
ArrayList<Float> positions = new ArrayList<>();
|
||||||
ArrayList<Integer> colors = new ArrayList<Integer>();
|
ArrayList<Integer> colors = new ArrayList<>();
|
||||||
Matrix matrix = null;
|
Matrix matrix = null;
|
||||||
|
|
||||||
public Gradient createChild(Gradient g) {
|
public Gradient createChild(Gradient g) {
|
||||||
@@ -682,7 +682,7 @@ public class SVGParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static class StyleSet {
|
private static class StyleSet {
|
||||||
HashMap<String, String> styleMap = new HashMap<String, String>();
|
HashMap<String, String> styleMap = new HashMap<>();
|
||||||
|
|
||||||
private StyleSet(String string) {
|
private StyleSet(String string) {
|
||||||
String[] styles = string.split(";");
|
String[] styles = string.split(";");
|
||||||
@@ -783,8 +783,8 @@ public class SVGParser {
|
|||||||
|
|
||||||
boolean whiteMode = false;
|
boolean whiteMode = false;
|
||||||
|
|
||||||
HashMap<String, Shader> gradientMap = new HashMap<String, Shader>();
|
HashMap<String, Shader> gradientMap = new HashMap<>();
|
||||||
HashMap<String, Gradient> gradientRefMap = new HashMap<String, Gradient>();
|
HashMap<String, Gradient> gradientRefMap = new HashMap<>();
|
||||||
Gradient gradient = null;
|
Gradient gradient = null;
|
||||||
|
|
||||||
private SVGHandler(Picture picture) {
|
private SVGHandler(Picture picture) {
|
||||||
|
|||||||
@@ -316,8 +316,7 @@ public class ColorPickerPreference
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public static final Creator<SavedState> CREATOR =
|
public static final Creator<SavedState> CREATOR = new Creator<SavedState>() {
|
||||||
new Creator<SavedState>() {
|
|
||||||
public SavedState createFromParcel(Parcel in) {
|
public SavedState createFromParcel(Parcel in) {
|
||||||
return new SavedState(in);
|
return new SavedState(in);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class ButtonActions {
|
|||||||
private int menuTitle;
|
private int menuTitle;
|
||||||
|
|
||||||
private UIAction mainAction = null;
|
private UIAction mainAction = null;
|
||||||
private ArrayList<UIAction> menuActions = new ArrayList<UIAction>();
|
private ArrayList<UIAction> menuActions = new ArrayList<>();
|
||||||
|
|
||||||
private static final int maxMenuActions = 6;
|
private static final int maxMenuActions = 6;
|
||||||
|
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ public class ChessBoardPlay extends ChessBoard {
|
|||||||
protected void drawExtraSquares(Canvas canvas) {
|
protected void drawExtraSquares(Canvas canvas) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private final boolean myColor(int piece) {
|
private boolean myColor(int piece) {
|
||||||
return (piece != Piece.EMPTY) && (Piece.isWhite(piece) == pos.whiteMove);
|
return (piece != Piece.EMPTY) && (Piece.isWhite(piece) == pos.whiteMove);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@ public class ChessBoardPlay extends ChessBoard {
|
|||||||
* @return Matching move if unique.
|
* @return Matching move if unique.
|
||||||
* Boolean indicating if there was at least one match.
|
* Boolean indicating if there was at least one match.
|
||||||
*/
|
*/
|
||||||
private final Pair<Move, Boolean> matchingMove(int sq1, int sq2, ArrayList<Move> moves) {
|
private Pair<Move, Boolean> matchingMove(int sq1, int sq2, ArrayList<Move> moves) {
|
||||||
Move matchingMove = null;
|
Move matchingMove = null;
|
||||||
boolean anyMatch = false;
|
boolean anyMatch = false;
|
||||||
for (Move m : moves) {
|
for (Move m : moves) {
|
||||||
@@ -198,6 +198,6 @@ public class ChessBoardPlay extends ChessBoard {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new Pair<Move, Boolean>(matchingMove, anyMatch);
|
return new Pair<>(matchingMove, anyMatch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -297,7 +297,7 @@ public class DroidFish extends Activity
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
actions = new HashMap<String, UIAction>();
|
actions = new HashMap<>();
|
||||||
addAction(new UIAction() {
|
addAction(new UIAction() {
|
||||||
public String getId() { return "flipboard"; }
|
public String getId() { return "flipboard"; }
|
||||||
public int getName() { return R.string.flip_board; }
|
public int getName() { return R.string.flip_board; }
|
||||||
@@ -613,7 +613,7 @@ public class DroidFish extends Activity
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
tourGuide = TourGuide.init(this);
|
tourGuide = TourGuide.init(this);
|
||||||
ArrayList<TourGuide> guides = new ArrayList<TourGuide>();
|
ArrayList<TourGuide> guides = new ArrayList<>();
|
||||||
|
|
||||||
TourGuide tg = TourGuide.init(this);
|
TourGuide tg = TourGuide.init(this);
|
||||||
tg.setToolTip(new ToolTip()
|
tg.setToolTip(new ToolTip()
|
||||||
@@ -821,7 +821,7 @@ public class DroidFish extends Activity
|
|||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
DroidFishApp.toast(e.getMessage(), Toast.LENGTH_LONG);
|
DroidFishApp.toast(e.getMessage(), Toast.LENGTH_LONG);
|
||||||
}
|
}
|
||||||
return new Pair<String,String>(pgnOrFen,filename);
|
return new Pair<>(pgnOrFen,filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] strToByteArr(String str) {
|
private byte[] strToByteArr(String str) {
|
||||||
@@ -1617,7 +1617,7 @@ public class DroidFish extends Activity
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<SquareDecoration> sd = new ArrayList<SquareDecoration>();
|
ArrayList<SquareDecoration> sd = new ArrayList<>();
|
||||||
for (Pair<Integer,ProbeResult> p : x)
|
for (Pair<Integer,ProbeResult> p : x)
|
||||||
sd.add(new SquareDecoration(p.first, p.second));
|
sd.add(new SquareDecoration(p.first, p.second));
|
||||||
cb.setSquareDecorations(sd);
|
cb.setSquareDecorations(sd);
|
||||||
@@ -1665,7 +1665,7 @@ public class DroidFish extends Activity
|
|||||||
new DrawerItem(ITEM_SETTINGS, R.string.option_settings),
|
new DrawerItem(ITEM_SETTINGS, R.string.option_settings),
|
||||||
new DrawerItem(ITEM_ABOUT, R.string.option_about)
|
new DrawerItem(ITEM_ABOUT, R.string.option_about)
|
||||||
};
|
};
|
||||||
leftDrawer.setAdapter(new ArrayAdapter<DrawerItem>(this,
|
leftDrawer.setAdapter(new ArrayAdapter<>(this,
|
||||||
R.layout.drawer_list_item,
|
R.layout.drawer_list_item,
|
||||||
leftItems));
|
leftItems));
|
||||||
leftDrawer.setOnItemClickListener(new OnItemClickListener() {
|
leftDrawer.setOnItemClickListener(new OnItemClickListener() {
|
||||||
@@ -1683,7 +1683,7 @@ public class DroidFish extends Activity
|
|||||||
new DrawerItem(ITEM_FORCE_MOVE, R.string.option_force_computer_move),
|
new DrawerItem(ITEM_FORCE_MOVE, R.string.option_force_computer_move),
|
||||||
new DrawerItem(ITEM_DRAW, R.string.option_draw)
|
new DrawerItem(ITEM_DRAW, R.string.option_draw)
|
||||||
};
|
};
|
||||||
rightDrawer.setAdapter(new ArrayAdapter<DrawerItem>(this,
|
rightDrawer.setAdapter(new ArrayAdapter<>(this,
|
||||||
R.layout.drawer_list_item,
|
R.layout.drawer_list_item,
|
||||||
rightItems));
|
rightItems));
|
||||||
rightDrawer.setOnItemClickListener(new OnItemClickListener() {
|
rightDrawer.setOnItemClickListener(new OnItemClickListener() {
|
||||||
@@ -1940,7 +1940,7 @@ public class DroidFish extends Activity
|
|||||||
private void setBoardFlip(boolean matchPlayerNames) {
|
private void setBoardFlip(boolean matchPlayerNames) {
|
||||||
boolean flipped = boardFlipped;
|
boolean flipped = boardFlipped;
|
||||||
if (playerNameFlip && matchPlayerNames && (ctrl != null)) {
|
if (playerNameFlip && matchPlayerNames && (ctrl != null)) {
|
||||||
final TreeMap<String,String> headers = new TreeMap<String,String>();
|
final TreeMap<String,String> headers = new TreeMap<>();
|
||||||
ctrl.getHeaders(headers);
|
ctrl.getHeaders(headers);
|
||||||
int whiteMatch = nameMatchScore(headers.get("White"), playerName);
|
int whiteMatch = nameMatchScore(headers.get("White"), playerName);
|
||||||
int blackMatch = nameMatchScore(headers.get("Black"), playerName);
|
int blackMatch = nameMatchScore(headers.get("Black"), playerName);
|
||||||
@@ -2085,7 +2085,7 @@ public class DroidFish extends Activity
|
|||||||
private String ecoInfoStr = "";
|
private String ecoInfoStr = "";
|
||||||
private int distToEcoTree = 0;
|
private int distToEcoTree = 0;
|
||||||
private String variantStr = "";
|
private String variantStr = "";
|
||||||
private ArrayList<ArrayList<Move>> pvMoves = new ArrayList<ArrayList<Move>>();
|
private ArrayList<ArrayList<Move>> pvMoves = new ArrayList<>();
|
||||||
private ArrayList<Move> bookMoves = null;
|
private ArrayList<Move> bookMoves = null;
|
||||||
private ArrayList<Move> variantMoves = null;
|
private ArrayList<Move> variantMoves = null;
|
||||||
|
|
||||||
@@ -2178,7 +2178,7 @@ public class DroidFish extends Activity
|
|||||||
if (pvMovesTmp.size() == 1) {
|
if (pvMovesTmp.size() == 1) {
|
||||||
hints = pvMovesTmp.get(0);
|
hints = pvMovesTmp.get(0);
|
||||||
} else if (pvMovesTmp.size() > 1) {
|
} else if (pvMovesTmp.size() > 1) {
|
||||||
hints = new ArrayList<Move>();
|
hints = new ArrayList<>();
|
||||||
for (ArrayList<Move> pv : pvMovesTmp)
|
for (ArrayList<Move> pv : pvMovesTmp)
|
||||||
if (!pv.isEmpty())
|
if (!pv.isEmpty())
|
||||||
hints.add(pv.get(0));
|
hints.add(pv.get(0));
|
||||||
@@ -2330,8 +2330,8 @@ public class DroidFish extends Activity
|
|||||||
final int PASTE = 2;
|
final int PASTE = 2;
|
||||||
|
|
||||||
setAutoMode(AutoMode.OFF);
|
setAutoMode(AutoMode.OFF);
|
||||||
List<CharSequence> lst = new ArrayList<CharSequence>();
|
List<CharSequence> lst = new ArrayList<>();
|
||||||
final List<Integer> actions = new ArrayList<Integer>();
|
final List<Integer> actions = new ArrayList<>();
|
||||||
lst.add(getString(R.string.copy_game)); actions.add(COPY_GAME);
|
lst.add(getString(R.string.copy_game)); actions.add(COPY_GAME);
|
||||||
lst.add(getString(R.string.copy_position)); actions.add(COPY_POSITION);
|
lst.add(getString(R.string.copy_position)); actions.add(COPY_POSITION);
|
||||||
lst.add(getString(R.string.paste)); actions.add(PASTE);
|
lst.add(getString(R.string.paste)); actions.add(PASTE);
|
||||||
@@ -2389,8 +2389,8 @@ public class DroidFish extends Activity
|
|||||||
final int REPEAT_LAST_MOVE = 6;
|
final int REPEAT_LAST_MOVE = 6;
|
||||||
|
|
||||||
setAutoMode(AutoMode.OFF);
|
setAutoMode(AutoMode.OFF);
|
||||||
List<CharSequence> lst = new ArrayList<CharSequence>();
|
List<CharSequence> lst = new ArrayList<>();
|
||||||
final List<Integer> actions = new ArrayList<Integer>();
|
final List<Integer> actions = new ArrayList<>();
|
||||||
lst.add(getString(R.string.clipboard)); actions.add(CLIPBOARD);
|
lst.add(getString(R.string.clipboard)); actions.add(CLIPBOARD);
|
||||||
if (storageAvailable()) {
|
if (storageAvailable()) {
|
||||||
lst.add(getString(R.string.option_file)); actions.add(FILEMENU);
|
lst.add(getString(R.string.option_file)); actions.add(FILEMENU);
|
||||||
@@ -2434,8 +2434,7 @@ public class DroidFish extends Activity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
AlertDialog alert = builder.create();
|
return builder.create();
|
||||||
return alert;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void shareGameOrText(boolean game) {
|
private void shareGameOrText(boolean game) {
|
||||||
@@ -2515,8 +2514,8 @@ public class DroidFish extends Activity
|
|||||||
final int SAVE_GAME = 4;
|
final int SAVE_GAME = 4;
|
||||||
|
|
||||||
setAutoMode(AutoMode.OFF);
|
setAutoMode(AutoMode.OFF);
|
||||||
List<CharSequence> lst = new ArrayList<CharSequence>();
|
List<CharSequence> lst = new ArrayList<>();
|
||||||
final List<Integer> actions = new ArrayList<Integer>();
|
final List<Integer> actions = new ArrayList<>();
|
||||||
if (currFileType() != FT_NONE) {
|
if (currFileType() != FT_NONE) {
|
||||||
lst.add(getString(R.string.load_last_file)); actions.add(LOAD_LAST_FILE);
|
lst.add(getString(R.string.load_last_file)); actions.add(LOAD_LAST_FILE);
|
||||||
}
|
}
|
||||||
@@ -2659,8 +2658,8 @@ public class DroidFish extends Activity
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Dialog selectEngineDialog(final boolean abortOnCancel) {
|
private Dialog selectEngineDialog(final boolean abortOnCancel) {
|
||||||
final ArrayList<String> items = new ArrayList<String>();
|
final ArrayList<String> items = new ArrayList<>();
|
||||||
final ArrayList<String> ids = new ArrayList<String>();
|
final ArrayList<String> ids = new ArrayList<>();
|
||||||
ids.add("stockfish"); items.add(getString(R.string.stockfish_engine));
|
ids.add("stockfish"); items.add(getString(R.string.stockfish_engine));
|
||||||
ids.add("cuckoochess"); items.add(getString(R.string.cuckoochess_engine));
|
ids.add("cuckoochess"); items.add(getString(R.string.cuckoochess_engine));
|
||||||
|
|
||||||
@@ -2670,11 +2669,11 @@ public class DroidFish extends Activity
|
|||||||
{
|
{
|
||||||
ChessEngineResolver resolver = new ChessEngineResolver(this);
|
ChessEngineResolver resolver = new ChessEngineResolver(this);
|
||||||
List<ChessEngine> engines = resolver.resolveEngines();
|
List<ChessEngine> engines = resolver.resolveEngines();
|
||||||
ArrayList<Pair<String,String>> oexEngines = new ArrayList<Pair<String,String>>();
|
ArrayList<Pair<String,String>> oexEngines = new ArrayList<>();
|
||||||
for (ChessEngine engine : engines) {
|
for (ChessEngine engine : engines) {
|
||||||
if ((engine.getName() != null) && (engine.getFileName() != null) &&
|
if ((engine.getName() != null) && (engine.getFileName() != null) &&
|
||||||
(engine.getPackageName() != null)) {
|
(engine.getPackageName() != null)) {
|
||||||
oexEngines.add(new Pair<String,String>(EngineUtil.openExchangeFileName(engine),
|
oexEngines.add(new Pair<>(EngineUtil.openExchangeFileName(engine),
|
||||||
engine.getName()));
|
engine.getName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2938,8 +2937,8 @@ public class DroidFish extends Activity
|
|||||||
final int ADD_NULL_MOVE = 6;
|
final int ADD_NULL_MOVE = 6;
|
||||||
|
|
||||||
setAutoMode(AutoMode.OFF);
|
setAutoMode(AutoMode.OFF);
|
||||||
List<CharSequence> lst = new ArrayList<CharSequence>();
|
List<CharSequence> lst = new ArrayList<>();
|
||||||
final List<Integer> actions = new ArrayList<Integer>();
|
final List<Integer> actions = new ArrayList<>();
|
||||||
lst.add(getString(R.string.edit_headers)); actions.add(EDIT_HEADERS);
|
lst.add(getString(R.string.edit_headers)); actions.add(EDIT_HEADERS);
|
||||||
if (ctrl.humansTurn()) {
|
if (ctrl.humansTurn()) {
|
||||||
lst.add(getString(R.string.edit_comments)); actions.add(EDIT_COMMENTS);
|
lst.add(getString(R.string.edit_comments)); actions.add(EDIT_COMMENTS);
|
||||||
@@ -2997,7 +2996,7 @@ public class DroidFish extends Activity
|
|||||||
|
|
||||||
/** Let the user edit the PGN headers. */
|
/** Let the user edit the PGN headers. */
|
||||||
private void editHeaders() {
|
private void editHeaders() {
|
||||||
final TreeMap<String,String> headers = new TreeMap<String,String>();
|
final TreeMap<String,String> headers = new TreeMap<>();
|
||||||
ctrl.getHeaders(headers);
|
ctrl.getHeaders(headers);
|
||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(DroidFish.this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(DroidFish.this);
|
||||||
@@ -3098,8 +3097,8 @@ public class DroidFish extends Activity
|
|||||||
final int TRUNCATE_VARS = 3;
|
final int TRUNCATE_VARS = 3;
|
||||||
final int HIDE_STATISTICS = 4;
|
final int HIDE_STATISTICS = 4;
|
||||||
final int SHOW_STATISTICS = 5;
|
final int SHOW_STATISTICS = 5;
|
||||||
List<CharSequence> lst = new ArrayList<CharSequence>();
|
List<CharSequence> lst = new ArrayList<>();
|
||||||
final List<Integer> actions = new ArrayList<Integer>();
|
final List<Integer> actions = new ArrayList<>();
|
||||||
lst.add(getString(R.string.add_analysis)); actions.add(ADD_ANALYSIS);
|
lst.add(getString(R.string.add_analysis)); actions.add(ADD_ANALYSIS);
|
||||||
int numPV = this.numPV;
|
int numPV = this.numPV;
|
||||||
final int maxPV = ctrl.maxPV();
|
final int maxPV = ctrl.maxPV();
|
||||||
@@ -3289,8 +3288,8 @@ public class DroidFish extends Activity
|
|||||||
final int AUTO_BACKWARD = 4;
|
final int AUTO_BACKWARD = 4;
|
||||||
|
|
||||||
setAutoMode(AutoMode.OFF);
|
setAutoMode(AutoMode.OFF);
|
||||||
List<CharSequence> lst = new ArrayList<CharSequence>();
|
List<CharSequence> lst = new ArrayList<>();
|
||||||
final List<Integer> actions = new ArrayList<Integer>();
|
final List<Integer> actions = new ArrayList<>();
|
||||||
lst.add(getString(R.string.goto_start_game)); actions.add(GOTO_START_GAME);
|
lst.add(getString(R.string.goto_start_game)); actions.add(GOTO_START_GAME);
|
||||||
lst.add(getString(R.string.goto_start_variation)); actions.add(GOTO_START_VAR);
|
lst.add(getString(R.string.goto_start_variation)); actions.add(GOTO_START_VAR);
|
||||||
if (ctrl.currVariation() > 0) {
|
if (ctrl.currVariation() > 0) {
|
||||||
@@ -3331,8 +3330,8 @@ public class DroidFish extends Activity
|
|||||||
final int AUTO_FORWARD = 3;
|
final int AUTO_FORWARD = 3;
|
||||||
|
|
||||||
setAutoMode(AutoMode.OFF);
|
setAutoMode(AutoMode.OFF);
|
||||||
List<CharSequence> lst = new ArrayList<CharSequence>();
|
List<CharSequence> lst = new ArrayList<>();
|
||||||
final List<Integer> actions = new ArrayList<Integer>();
|
final List<Integer> actions = new ArrayList<>();
|
||||||
lst.add(getString(R.string.goto_end_variation)); actions.add(GOTO_END_VAR);
|
lst.add(getString(R.string.goto_end_variation)); actions.add(GOTO_END_VAR);
|
||||||
if (ctrl.currVariation() < ctrl.numVariations() - 1) {
|
if (ctrl.currVariation() < ctrl.numVariations() - 1) {
|
||||||
lst.add(getString(R.string.goto_next_variation)); actions.add(GOTO_NEXT_VAR);
|
lst.add(getString(R.string.goto_next_variation)); actions.add(GOTO_NEXT_VAR);
|
||||||
@@ -3365,10 +3364,10 @@ public class DroidFish extends Activity
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Dialog makeButtonDialog(ButtonActions buttonActions) {
|
private Dialog makeButtonDialog(ButtonActions buttonActions) {
|
||||||
List<CharSequence> names = new ArrayList<CharSequence>();
|
List<CharSequence> names = new ArrayList<>();
|
||||||
final List<UIAction> actions = new ArrayList<UIAction>();
|
final List<UIAction> actions = new ArrayList<>();
|
||||||
|
|
||||||
HashSet<String> used = new HashSet<String>();
|
HashSet<String> used = new HashSet<>();
|
||||||
for (UIAction a : buttonActions.getMenuActions()) {
|
for (UIAction a : buttonActions.getMenuActions()) {
|
||||||
if ((a != null) && a.enabled() && !used.contains(a.getId())) {
|
if ((a != null) && a.enabled() && !used.contains(a.getId())) {
|
||||||
names.add(getString(a.getName()));
|
names.add(getString(a.getName()));
|
||||||
@@ -3391,8 +3390,8 @@ public class DroidFish extends Activity
|
|||||||
final int SELECT_ENGINE = 0;
|
final int SELECT_ENGINE = 0;
|
||||||
final int SET_ENGINE_OPTIONS = 1;
|
final int SET_ENGINE_OPTIONS = 1;
|
||||||
final int CONFIG_NET_ENGINE = 2;
|
final int CONFIG_NET_ENGINE = 2;
|
||||||
List<CharSequence> lst = new ArrayList<CharSequence>();
|
List<CharSequence> lst = new ArrayList<>();
|
||||||
final List<Integer> actions = new ArrayList<Integer>();
|
final List<Integer> actions = new ArrayList<>();
|
||||||
lst.add(getString(R.string.select_engine)); actions.add(SELECT_ENGINE);
|
lst.add(getString(R.string.select_engine)); actions.add(SELECT_ENGINE);
|
||||||
if (canSetEngineOptions()) {
|
if (canSetEngineOptions()) {
|
||||||
lst.add(getString(R.string.set_engine_options));
|
lst.add(getString(R.string.set_engine_options));
|
||||||
@@ -3998,7 +3997,7 @@ public class DroidFish extends Activity
|
|||||||
whiteTitleText.setText(getString(R.string.white_square_character) + " " + timeToString(wTime));
|
whiteTitleText.setText(getString(R.string.white_square_character) + " " + timeToString(wTime));
|
||||||
blackTitleText.setText(getString(R.string.black_square_character) + " " + timeToString(bTime));
|
blackTitleText.setText(getString(R.string.black_square_character) + " " + timeToString(bTime));
|
||||||
} else {
|
} else {
|
||||||
TreeMap<String,String> headers = new TreeMap<String,String>();
|
TreeMap<String,String> headers = new TreeMap<>();
|
||||||
ctrl.getHeaders(headers);
|
ctrl.getHeaders(headers);
|
||||||
whiteTitleText.setText(headers.get("White"));
|
whiteTitleText.setText(headers.get("White"));
|
||||||
blackTitleText.setText(headers.get("Black"));
|
blackTitleText.setText(headers.get("Black"));
|
||||||
@@ -4052,7 +4051,7 @@ public class DroidFish extends Activity
|
|||||||
static class PgnScreenText implements PgnToken.PgnTokenReceiver,
|
static class PgnScreenText implements PgnToken.PgnTokenReceiver,
|
||||||
MoveListView.OnLinkClickListener {
|
MoveListView.OnLinkClickListener {
|
||||||
private SpannableStringBuilder sb = new SpannableStringBuilder();
|
private SpannableStringBuilder sb = new SpannableStringBuilder();
|
||||||
private TreeMap<Integer,Node> offs2Node = new TreeMap<Integer,Node>();
|
private TreeMap<Integer,Node> offs2Node = new TreeMap<>();
|
||||||
private int prevType = PgnToken.EOF;
|
private int prevType = PgnToken.EOF;
|
||||||
int nestLevel = 0;
|
int nestLevel = 0;
|
||||||
boolean col0 = true;
|
boolean col0 = true;
|
||||||
@@ -4074,7 +4073,7 @@ public class DroidFish extends Activity
|
|||||||
|
|
||||||
PgnScreenText(DroidFish df, PGNOptions options) {
|
PgnScreenText(DroidFish df, PGNOptions options) {
|
||||||
this.df = df;
|
this.df = df;
|
||||||
nodeToCharPos = new HashMap<Node, NodeInfo>();
|
nodeToCharPos = new HashMap<>();
|
||||||
this.options = options;
|
this.options = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import java.util.ArrayList;
|
|||||||
public class FileUtil {
|
public class FileUtil {
|
||||||
/** Read a text file. Return string array with one string per line. */
|
/** Read a text file. Return string array with one string per line. */
|
||||||
public static String[] readFile(String filename) throws IOException {
|
public static String[] readFile(String filename) throws IOException {
|
||||||
ArrayList<String> ret = new ArrayList<String>();
|
ArrayList<String> ret = new ArrayList<>();
|
||||||
InputStream inStream = new FileInputStream(filename);
|
InputStream inStream = new FileInputStream(filename);
|
||||||
InputStreamReader inFile = new InputStreamReader(inStream, "UTF-8");
|
InputStreamReader inFile = new InputStreamReader(inStream, "UTF-8");
|
||||||
BufferedReader inBuf = new BufferedReader(inFile);
|
BufferedReader inBuf = new BufferedReader(inFile);
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ final class BufferedRandomAccessFileReader {
|
|||||||
return new String(lineBuf, 0, lineLen);
|
return new String(lineBuf, 0, lineLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int getByte() throws IOException {
|
private int getByte() throws IOException {
|
||||||
if (bufPos >= bufLen) {
|
if (bufPos >= bufLen) {
|
||||||
bufStartFilePos = f.getFilePointer();
|
bufStartFilePos = f.getFilePointer();
|
||||||
bufLen = f.read(buffer);
|
bufLen = f.read(buffer);
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public class ChessBoardEdit extends ChessBoard {
|
|||||||
landScape = (config.orientation == Configuration.ORIENTATION_LANDSCAPE);
|
landScape = (config.orientation == Configuration.ORIENTATION_LANDSCAPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static int getGap(int sqSize) {
|
private static int getGap(int sqSize) {
|
||||||
return sqSize / 4;
|
return sqSize / 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ public class ChessBoardEdit extends ChessBoard {
|
|||||||
y0 = landScape ? 0 : (height - getHeight(sqSize)) / 2;
|
y0 = landScape ? 0 : (height - getHeight(sqSize)) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int extraPieces(int x, int y) {
|
private int extraPieces(int x, int y) {
|
||||||
if (landScape) {
|
if (landScape) {
|
||||||
if (x == 8) {
|
if (x == 8) {
|
||||||
switch (y) {
|
switch (y) {
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ public class EditBoard extends Activity {
|
|||||||
checkValidAndUpdateMaterialDiff();
|
checkValidAndUpdateMaterialDiff();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void initUI() {
|
private void initUI() {
|
||||||
setContentView(R.layout.editboard);
|
setContentView(R.layout.editboard);
|
||||||
Util.overrideViewAttribs(findViewById(R.id.main));
|
Util.overrideViewAttribs(findViewById(R.id.main));
|
||||||
|
|
||||||
@@ -281,7 +281,7 @@ public class EditBoard extends Activity {
|
|||||||
final int PASTE_POSITION = 7;
|
final int PASTE_POSITION = 7;
|
||||||
final int GET_FEN = 8;
|
final int GET_FEN = 8;
|
||||||
|
|
||||||
final ArrayList<DrawerItem> leftItems = new ArrayList<DrawerItem>();
|
final ArrayList<DrawerItem> leftItems = new ArrayList<>();
|
||||||
leftItems.add(new DrawerItem(SIDE_TO_MOVE, R.string.side_to_move));
|
leftItems.add(new DrawerItem(SIDE_TO_MOVE, R.string.side_to_move));
|
||||||
leftItems.add(new DrawerItem(CLEAR_BOARD, R.string.clear_board));
|
leftItems.add(new DrawerItem(CLEAR_BOARD, R.string.clear_board));
|
||||||
leftItems.add(new DrawerItem(INITIAL_POS, R.string.initial_position));
|
leftItems.add(new DrawerItem(INITIAL_POS, R.string.initial_position));
|
||||||
@@ -293,7 +293,7 @@ public class EditBoard extends Activity {
|
|||||||
if (DroidFish.hasFenProvider(getPackageManager()))
|
if (DroidFish.hasFenProvider(getPackageManager()))
|
||||||
leftItems.add(new DrawerItem(GET_FEN, R.string.get_fen));
|
leftItems.add(new DrawerItem(GET_FEN, R.string.get_fen));
|
||||||
|
|
||||||
leftDrawer.setAdapter(new ArrayAdapter<DrawerItem>(this,
|
leftDrawer.setAdapter(new ArrayAdapter<>(this,
|
||||||
R.layout.drawer_list_item,
|
R.layout.drawer_list_item,
|
||||||
leftItems.toArray(new DrawerItem[0])));
|
leftItems.toArray(new DrawerItem[0])));
|
||||||
leftDrawer.setOnItemClickListener(new OnItemClickListener() {
|
leftDrawer.setOnItemClickListener(new OnItemClickListener() {
|
||||||
@@ -381,12 +381,12 @@ public class EditBoard extends Activity {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void setSelection(int sq) {
|
private void setSelection(int sq) {
|
||||||
cb.setSelection(sq);
|
cb.setSelection(sq);
|
||||||
setEgtbHints(sq);
|
setEgtbHints(sq);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void setEgtbHints(int sq) {
|
private void setEgtbHints(int sq) {
|
||||||
if (!egtbHints || (sq < 0)) {
|
if (!egtbHints || (sq < 0)) {
|
||||||
cb.setSquareDecorations(null);
|
cb.setSquareDecorations(null);
|
||||||
return;
|
return;
|
||||||
@@ -399,7 +399,7 @@ public class EditBoard extends Activity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<SquareDecoration> sd = new ArrayList<SquareDecoration>();
|
ArrayList<SquareDecoration> sd = new ArrayList<>();
|
||||||
for (Pair<Integer,ProbeResult> p : x)
|
for (Pair<Integer,ProbeResult> p : x)
|
||||||
sd.add(new SquareDecoration(p.first, p.second));
|
sd.add(new SquareDecoration(p.first, p.second));
|
||||||
cb.setSquareDecorations(sd);
|
cb.setSquareDecorations(sd);
|
||||||
@@ -447,7 +447,7 @@ public class EditBoard extends Activity {
|
|||||||
return super.onKeyDown(keyCode, event);
|
return super.onKeyDown(keyCode, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void sendBackResult() {
|
private void sendBackResult() {
|
||||||
if (checkValidAndUpdateMaterialDiff()) {
|
if (checkValidAndUpdateMaterialDiff()) {
|
||||||
setPosFields();
|
setPosFields();
|
||||||
String fen = TextIO.toFEN(cb.pos);
|
String fen = TextIO.toFEN(cb.pos);
|
||||||
@@ -458,19 +458,19 @@ public class EditBoard extends Activity {
|
|||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void setPosFields() {
|
private void setPosFields() {
|
||||||
setEPFile(getEPFile()); // To handle sideToMove change
|
setEPFile(getEPFile()); // To handle sideToMove change
|
||||||
TextIO.fixupEPSquare(cb.pos);
|
TextIO.fixupEPSquare(cb.pos);
|
||||||
TextIO.removeBogusCastleFlags(cb.pos);
|
TextIO.removeBogusCastleFlags(cb.pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int getEPFile() {
|
private int getEPFile() {
|
||||||
int epSquare = cb.pos.getEpSquare();
|
int epSquare = cb.pos.getEpSquare();
|
||||||
if (epSquare < 0) return 8;
|
if (epSquare < 0) return 8;
|
||||||
return Position.getX(epSquare);
|
return Position.getX(epSquare);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void setEPFile(int epFile) {
|
private void setEPFile(int epFile) {
|
||||||
int epSquare = -1;
|
int epSquare = -1;
|
||||||
if ((epFile >= 0) && (epFile < 8)) {
|
if ((epFile >= 0) && (epFile < 8)) {
|
||||||
int epRank = cb.pos.whiteMove ? 5 : 2;
|
int epRank = cb.pos.whiteMove ? 5 : 2;
|
||||||
@@ -480,7 +480,7 @@ public class EditBoard extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Test if a position is valid and update material diff display. */
|
/** Test if a position is valid and update material diff display. */
|
||||||
private final boolean checkValidAndUpdateMaterialDiff() {
|
private boolean checkValidAndUpdateMaterialDiff() {
|
||||||
try {
|
try {
|
||||||
MaterialDiff md = Util.getMaterialDiff(cb.pos);
|
MaterialDiff md = Util.getMaterialDiff(cb.pos);
|
||||||
whiteFigText.setText(md.white);
|
whiteFigText.setText(md.white);
|
||||||
@@ -496,7 +496,7 @@ public class EditBoard extends Activity {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String getParseErrString(ChessParseError e) {
|
private String getParseErrString(ChessParseError e) {
|
||||||
if (e.resourceId == -1)
|
if (e.resourceId == -1)
|
||||||
return e.getMessage();
|
return e.getMessage();
|
||||||
else
|
else
|
||||||
@@ -637,7 +637,7 @@ public class EditBoard extends Activity {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void setFEN(String fen) {
|
private void setFEN(String fen) {
|
||||||
if (fen == null)
|
if (fen == null)
|
||||||
return;
|
return;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ public class EditOptions extends Activity {
|
|||||||
return super.onKeyDown(keyCode, event);
|
return super.onKeyDown(keyCode, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void initUI() {
|
private void initUI() {
|
||||||
String title = getString(R.string.edit_options_title);
|
String title = getString(R.string.edit_options_title);
|
||||||
if (engineName != null)
|
if (engineName != null)
|
||||||
title = title + ": " + engineName;
|
title = title + ": " + engineName;
|
||||||
@@ -272,9 +272,9 @@ public class EditOptions extends Activity {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void sendBackResult() {
|
private void sendBackResult() {
|
||||||
if (uciOpts != null) {
|
if (uciOpts != null) {
|
||||||
TreeMap<String, String> uciMap = new TreeMap<String,String>();
|
TreeMap<String, String> uciMap = new TreeMap<>();
|
||||||
for (String name : uciOpts.getOptionNames()) {
|
for (String name : uciOpts.getOptionNames()) {
|
||||||
UCIOptions.OptionBase o = uciOpts.getOption(name);
|
UCIOptions.OptionBase o = uciOpts.getOption(name);
|
||||||
if (o != null) {
|
if (o != null) {
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ import android.widget.AdapterView.OnItemClickListener;
|
|||||||
import android.widget.AdapterView.OnItemLongClickListener;
|
import android.widget.AdapterView.OnItemLongClickListener;
|
||||||
|
|
||||||
public class EditPGN extends ListActivity {
|
public class EditPGN extends ListActivity {
|
||||||
static ArrayList<GameInfo> gamesInFile = new ArrayList<GameInfo>();
|
static ArrayList<GameInfo> gamesInFile = new ArrayList<>();
|
||||||
static boolean cacheValid = false;
|
static boolean cacheValid = false;
|
||||||
PGNFile pgnFile;
|
PGNFile pgnFile;
|
||||||
ProgressDialog progress;
|
ProgressDialog progress;
|
||||||
@@ -246,7 +246,7 @@ public class EditPGN extends ListActivity {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void showList() {
|
private void showList() {
|
||||||
progress = null;
|
progress = null;
|
||||||
removeDialog(PROGRESS_DIALOG);
|
removeDialog(PROGRESS_DIALOG);
|
||||||
setContentView(R.layout.select_game);
|
setContentView(R.layout.select_game);
|
||||||
@@ -422,7 +422,7 @@ public class EditPGN extends ListActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final boolean readFile() {
|
private boolean readFile() {
|
||||||
String fileName = pgnFile.getName();
|
String fileName = pgnFile.getName();
|
||||||
if (!fileName.equals(lastFileName))
|
if (!fileName.equals(lastFileName))
|
||||||
defaultItem = 0;
|
defaultItem = 0;
|
||||||
@@ -431,7 +431,7 @@ public class EditPGN extends ListActivity {
|
|||||||
return true;
|
return true;
|
||||||
Pair<GameInfoResult, ArrayList<GameInfo>> p = pgnFile.getGameInfo(this, progress);
|
Pair<GameInfoResult, ArrayList<GameInfo>> p = pgnFile.getGameInfo(this, progress);
|
||||||
if (p.first != GameInfoResult.OK) {
|
if (p.first != GameInfoResult.OK) {
|
||||||
gamesInFile = new ArrayList<GameInfo>();
|
gamesInFile = new ArrayList<>();
|
||||||
switch (p.first) {
|
switch (p.first) {
|
||||||
case OUT_OF_MEMORY:
|
case OUT_OF_MEMORY:
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@@ -462,7 +462,7 @@ public class EditPGN extends ListActivity {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void sendBackResult(GameInfo gi) {
|
private void sendBackResult(GameInfo gi) {
|
||||||
String pgn = pgnFile.readOneGame(gi);
|
String pgn = pgnFile.readOneGame(gi);
|
||||||
if (pgn != null) {
|
if (pgn != null) {
|
||||||
String pgnToken = (new ObjectCache()).storeString(pgn);
|
String pgnToken = (new ObjectCache()).storeString(pgn);
|
||||||
@@ -474,19 +474,18 @@ public class EditPGN extends ListActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void deleteGame(GameInfo gi) {
|
private void deleteGame(GameInfo gi) {
|
||||||
if (pgnFile.deleteGame(gi, gamesInFile)) {
|
if (pgnFile.deleteGame(gi, gamesInFile)) {
|
||||||
ListView lv = getListView();
|
ListView lv = getListView();
|
||||||
int pos = lv.pointToPosition(0,0);
|
int pos = lv.pointToPosition(0,0);
|
||||||
aa = new ArrayAdapter<GameInfo>(this, R.layout.select_game_list_item, gamesInFile);
|
aa = new ArrayAdapter<>(this, R.layout.select_game_list_item, gamesInFile);
|
||||||
setListAdapter(aa);
|
setListAdapter(aa);
|
||||||
String s = filterText.getText().toString();
|
String s = filterText.getText().toString();
|
||||||
aa.getFilter().filter(s);
|
aa.getFilter().filter(s);
|
||||||
lv.setSelection(pos);
|
lv.setSelection(pos);
|
||||||
// Update lastModTime, since current change has already been handled
|
// Update lastModTime, since current change has already been handled
|
||||||
String fileName = pgnFile.getName();
|
String fileName = pgnFile.getName();
|
||||||
long modTime = new File(fileName).lastModified();
|
lastModTime = new File(fileName).lastModified();
|
||||||
lastModTime = modTime;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public class FENFile {
|
|||||||
/** Read all FEN strings (one per line) in a file. */
|
/** Read all FEN strings (one per line) in a file. */
|
||||||
public final Pair<FenInfoResult,ArrayList<FenInfo>> getFenInfo(Activity activity,
|
public final Pair<FenInfoResult,ArrayList<FenInfo>> getFenInfo(Activity activity,
|
||||||
final ProgressDialog progress) {
|
final ProgressDialog progress) {
|
||||||
ArrayList<FenInfo> fensInFile = new ArrayList<FenInfo>();
|
ArrayList<FenInfo> fensInFile = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
int percent = -1;
|
int percent = -1;
|
||||||
fensInFile.clear();
|
fensInFile.clear();
|
||||||
@@ -94,15 +94,15 @@ public class FENFile {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Thread.currentThread().isInterrupted())
|
if (Thread.currentThread().isInterrupted())
|
||||||
return new Pair<FenInfoResult,ArrayList<FenInfo>>(FenInfoResult.CANCEL, null);
|
return new Pair<>(FenInfoResult.CANCEL, null);
|
||||||
}
|
}
|
||||||
f.close();
|
f.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
} catch (OutOfMemoryError e) {
|
} catch (OutOfMemoryError e) {
|
||||||
fensInFile.clear();
|
fensInFile.clear();
|
||||||
fensInFile = null;
|
fensInFile = null;
|
||||||
return new Pair<FenInfoResult,ArrayList<FenInfo>>(FenInfoResult.OUT_OF_MEMORY, null);
|
return new Pair<>(FenInfoResult.OUT_OF_MEMORY, null);
|
||||||
}
|
}
|
||||||
return new Pair<FenInfoResult,ArrayList<FenInfo>>(FenInfoResult.OK, fensInFile);
|
return new Pair<>(FenInfoResult.OK, fensInFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ import android.widget.AdapterView.OnItemClickListener;
|
|||||||
import android.widget.AdapterView.OnItemLongClickListener;
|
import android.widget.AdapterView.OnItemLongClickListener;
|
||||||
|
|
||||||
public class LoadFEN extends ListActivity {
|
public class LoadFEN extends ListActivity {
|
||||||
private static ArrayList<FenInfo> fensInFile = new ArrayList<FenInfo>();
|
private static ArrayList<FenInfo> fensInFile = new ArrayList<>();
|
||||||
private static boolean cacheValid = false;
|
private static boolean cacheValid = false;
|
||||||
private FENFile fenFile;
|
private FENFile fenFile;
|
||||||
private ProgressDialog progress;
|
private ProgressDialog progress;
|
||||||
@@ -197,7 +197,7 @@ public class LoadFEN extends ListActivity {
|
|||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void showList() {
|
private void showList() {
|
||||||
progress = null;
|
progress = null;
|
||||||
removeProgressDialog();
|
removeProgressDialog();
|
||||||
setContentView(R.layout.load_fen);
|
setContentView(R.layout.load_fen);
|
||||||
@@ -323,7 +323,7 @@ public class LoadFEN extends ListActivity {
|
|||||||
((DialogFragment)f).dismiss();
|
((DialogFragment)f).dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final boolean readFile() {
|
private boolean readFile() {
|
||||||
String fileName = fenFile.getName();
|
String fileName = fenFile.getName();
|
||||||
if (!fileName.equals(lastFileName))
|
if (!fileName.equals(lastFileName))
|
||||||
defaultItem = 0;
|
defaultItem = 0;
|
||||||
@@ -333,7 +333,7 @@ public class LoadFEN extends ListActivity {
|
|||||||
fenFile = new FENFile(fileName);
|
fenFile = new FENFile(fileName);
|
||||||
Pair<FenInfoResult, ArrayList<FenInfo>> p = fenFile.getFenInfo(this, progress);
|
Pair<FenInfoResult, ArrayList<FenInfo>> p = fenFile.getFenInfo(this, progress);
|
||||||
if (p.first != FenInfoResult.OK) {
|
if (p.first != FenInfoResult.OK) {
|
||||||
fensInFile = new ArrayList<FenInfo>();
|
fensInFile = new ArrayList<>();
|
||||||
if (p.first == FenInfoResult.OUT_OF_MEMORY) {
|
if (p.first == FenInfoResult.OUT_OF_MEMORY) {
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -352,7 +352,7 @@ public class LoadFEN extends ListActivity {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void sendBackResult(FenInfo fi, boolean toast) {
|
private void sendBackResult(FenInfo fi, boolean toast) {
|
||||||
String fen = fi.fen;
|
String fen = fi.fen;
|
||||||
if (fen != null) {
|
if (fen != null) {
|
||||||
if (toast)
|
if (toast)
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ public class LoadScid extends ListActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Vector<GameInfo> gamesInFile = new Vector<GameInfo>();
|
private static Vector<GameInfo> gamesInFile = new Vector<>();
|
||||||
private static boolean cacheValid = false;
|
private static boolean cacheValid = false;
|
||||||
private String fileName;
|
private String fileName;
|
||||||
private ProgressDialog progress;
|
private ProgressDialog progress;
|
||||||
@@ -229,7 +229,7 @@ public class LoadScid extends ListActivity {
|
|||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void showList() {
|
private void showList() {
|
||||||
progress = null;
|
progress = null;
|
||||||
removeProgressDialog();
|
removeProgressDialog();
|
||||||
final ArrayAdapter<GameInfo> aa =
|
final ArrayAdapter<GameInfo> aa =
|
||||||
@@ -294,7 +294,7 @@ public class LoadScid extends ListActivity {
|
|||||||
((DialogFragment)f).dismiss();
|
((DialogFragment)f).dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final boolean readFile(Cursor cursor) {
|
private boolean readFile(Cursor cursor) {
|
||||||
if (!fileName.equals(lastFileName))
|
if (!fileName.equals(lastFileName))
|
||||||
defaultItem = 0;
|
defaultItem = 0;
|
||||||
long modTime = new File(fileName).lastModified();
|
long modTime = new File(fileName).lastModified();
|
||||||
@@ -346,7 +346,7 @@ public class LoadScid extends ListActivity {
|
|||||||
gamesInFile.add(gi);
|
gamesInFile.add(gi);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void sendBackResult(final GameInfo gi) {
|
private void sendBackResult(final GameInfo gi) {
|
||||||
if (resultSentBack)
|
if (resultSentBack)
|
||||||
return;
|
return;
|
||||||
resultSentBack = true;
|
resultSentBack = true;
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ public class PGNFile {
|
|||||||
public final Pair<GameInfoResult,ArrayList<GameInfo>> getGameInfo(Activity activity,
|
public final Pair<GameInfoResult,ArrayList<GameInfo>> getGameInfo(Activity activity,
|
||||||
final ProgressDialog progress,
|
final ProgressDialog progress,
|
||||||
int maxGames) {
|
int maxGames) {
|
||||||
ArrayList<GameInfo> gamesInFile = new ArrayList<GameInfo>();
|
ArrayList<GameInfo> gamesInFile = new ArrayList<>();
|
||||||
gamesInFile.clear();
|
gamesInFile.clear();
|
||||||
long fileLen = 0;
|
long fileLen = 0;
|
||||||
BufferedInput f = null;
|
BufferedInput f = null;
|
||||||
@@ -350,7 +350,7 @@ public class PGNFile {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Thread.currentThread().isInterrupted())
|
if (Thread.currentThread().isInterrupted())
|
||||||
return new Pair<GameInfoResult,ArrayList<GameInfo>>(GameInfoResult.CANCEL, null);
|
return new Pair<>(GameInfoResult.CANCEL, null);
|
||||||
}
|
}
|
||||||
gi = new GameInfo();
|
gi = new GameInfo();
|
||||||
gi.startPos = filePos;
|
gi.startPos = filePos;
|
||||||
@@ -368,18 +368,18 @@ public class PGNFile {
|
|||||||
} catch (OutOfMemoryError e) {
|
} catch (OutOfMemoryError e) {
|
||||||
gamesInFile.clear();
|
gamesInFile.clear();
|
||||||
gamesInFile = null;
|
gamesInFile = null;
|
||||||
return new Pair<GameInfoResult,ArrayList<GameInfo>>(GameInfoResult.OUT_OF_MEMORY, null);
|
return new Pair<>(GameInfoResult.OUT_OF_MEMORY, null);
|
||||||
} finally {
|
} finally {
|
||||||
if (f != null)
|
if (f != null)
|
||||||
f.close();
|
f.close();
|
||||||
}
|
}
|
||||||
if ((gamesInFile.size() == 0) && (fileLen > 0))
|
if ((gamesInFile.size() == 0) && (fileLen > 0))
|
||||||
return new Pair<GameInfoResult,ArrayList<GameInfo>>(GameInfoResult.NOT_PGN, null);
|
return new Pair<>(GameInfoResult.NOT_PGN, null);
|
||||||
|
|
||||||
return new Pair<GameInfoResult,ArrayList<GameInfo>>(GameInfoResult.OK, gamesInFile);
|
return new Pair<>(GameInfoResult.OK, gamesInFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void mkDirs() {
|
private void mkDirs() {
|
||||||
File dirFile = fileName.getParentFile();
|
File dirFile = fileName.getParentFile();
|
||||||
dirFile.mkdirs();
|
dirFile.mkdirs();
|
||||||
}
|
}
|
||||||
@@ -465,7 +465,7 @@ public class PGNFile {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static void copyData(RandomAccessFile fileReader,
|
private static void copyData(RandomAccessFile fileReader,
|
||||||
RandomAccessFile fileWriter,
|
RandomAccessFile fileWriter,
|
||||||
long nBytes) throws IOException {
|
long nBytes) throws IOException {
|
||||||
byte[] buffer = new byte[8192];
|
byte[] buffer = new byte[8192];
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ public class SeekBarPreference extends Preference
|
|||||||
return layout;
|
return layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String valToString() {
|
private String valToString() {
|
||||||
return String.format(Locale.US, "%.1f%%", currVal*0.1);
|
return String.format(Locale.US, "%.1f%%", currVal*0.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ class CtgBook implements IOpeningBook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Read len bytes from offs in file f. */
|
/** Read len bytes from offs in file f. */
|
||||||
private final static byte[] readBytes(RandomAccessFile f, long offs, int len) throws IOException {
|
private static byte[] readBytes(RandomAccessFile f, long offs, int len) throws IOException {
|
||||||
byte[] ret = new byte[len];
|
byte[] ret = new byte[len];
|
||||||
f.seek(offs);
|
f.seek(offs);
|
||||||
f.readFully(ret);
|
f.readFully(ret);
|
||||||
@@ -135,7 +135,7 @@ class CtgBook implements IOpeningBook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Convert len bytes starting at offs in buf to an integer. */
|
/** Convert len bytes starting at offs in buf to an integer. */
|
||||||
private final static int extractInt(byte[] buf, int offs, int len) {
|
private static int extractInt(byte[] buf, int offs, int len) {
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
int b = buf[offs + i];
|
int b = buf[offs + i];
|
||||||
@@ -156,7 +156,7 @@ class CtgBook implements IOpeningBook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final static class BitVector {
|
private final static class BitVector {
|
||||||
private List<Byte> buf = new ArrayList<Byte>();
|
private List<Byte> buf = new ArrayList<>();
|
||||||
private int length = 0;
|
private int length = 0;
|
||||||
|
|
||||||
void addBit(boolean value) {
|
void addBit(boolean value) {
|
||||||
@@ -191,7 +191,7 @@ class CtgBook implements IOpeningBook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Converts a position to a byte array. */
|
/** Converts a position to a byte array. */
|
||||||
private final static byte[] positionToByteArray(Position pos) {
|
private static byte[] positionToByteArray(Position pos) {
|
||||||
BitVector bits = new BitVector();
|
BitVector bits = new BitVector();
|
||||||
bits.addBits(0, 8); // Header byte
|
bits.addBits(0, 8); // Header byte
|
||||||
for (int x = 0; x < 8; x++) {
|
for (int x = 0; x < 8; x++) {
|
||||||
@@ -251,7 +251,7 @@ class CtgBook implements IOpeningBook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final static ArrayList<Integer> getHashIndices(byte[] encodedPos, CtbFile ctb) throws IOException {
|
final static ArrayList<Integer> getHashIndices(byte[] encodedPos, CtbFile ctb) throws IOException {
|
||||||
ArrayList<Integer> ret = new ArrayList<Integer>();
|
ArrayList<Integer> ret = new ArrayList<>();
|
||||||
int hash = getHashValue(encodedPos);
|
int hash = getHashValue(encodedPos);
|
||||||
for (int n = 0; n < 0x7fffffff; n = 2*n + 1) {
|
for (int n = 0; n < 0x7fffffff; n = 2*n + 1) {
|
||||||
int c = (hash & n) + n;
|
int c = (hash & n) + n;
|
||||||
@@ -289,7 +289,7 @@ class CtgBook implements IOpeningBook {
|
|||||||
0x274c7e7c, 0x1e8be65c, 0x2fa0b0bb, 0x1eb6c371
|
0x274c7e7c, 0x1e8be65c, 0x2fa0b0bb, 0x1eb6c371
|
||||||
};
|
};
|
||||||
|
|
||||||
private final static int getHashValue(byte[] encodedPos) {
|
private static int getHashValue(byte[] encodedPos) {
|
||||||
int hash = 0;
|
int hash = 0;
|
||||||
int tmp = 0;
|
int tmp = 0;
|
||||||
for (int i = 0; i < encodedPos.length; i++) {
|
for (int i = 0; i < encodedPos.length; i++) {
|
||||||
@@ -349,7 +349,7 @@ class CtgBook implements IOpeningBook {
|
|||||||
return pd;
|
return pd;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final PositionData findInPage(int page, byte[] encodedPos) throws IOException {
|
private PositionData findInPage(int page, byte[] encodedPos) throws IOException {
|
||||||
byte[] pageBuf = readBytes(f, (page+1)*4096L, 4096);
|
byte[] pageBuf = readBytes(f, (page+1)*4096L, 4096);
|
||||||
try {
|
try {
|
||||||
int nPos = extractInt(pageBuf, 0, 2);
|
int nPos = extractInt(pageBuf, 0, 2);
|
||||||
@@ -400,7 +400,7 @@ class CtgBook implements IOpeningBook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final ArrayList<BookEntry> getBookMoves() {
|
final ArrayList<BookEntry> getBookMoves() {
|
||||||
ArrayList<BookEntry> entries = new ArrayList<BookEntry>();
|
ArrayList<BookEntry> entries = new ArrayList<>();
|
||||||
int nMoves = (moveBytes - 1) / 2;
|
int nMoves = (moveBytes - 1) / 2;
|
||||||
for (int mi = 0; mi < nMoves; mi++) {
|
for (int mi = 0; mi < nMoves; mi++) {
|
||||||
int move = extractInt(buf, posLen + 1 + mi * 2, 1);
|
int move = extractInt(buf, posLen + 1 + mi * 2, 1);
|
||||||
@@ -448,7 +448,7 @@ class CtgBook implements IOpeningBook {
|
|||||||
int dy;
|
int dy;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static MoveInfo MI(int piece, int pieceNo, int dx, int dy) {
|
private static MoveInfo MI(int piece, int pieceNo, int dx, int dy) {
|
||||||
MoveInfo mi = new MoveInfo();
|
MoveInfo mi = new MoveInfo();
|
||||||
mi.piece = piece;
|
mi.piece = piece;
|
||||||
mi.pieceNo = pieceNo;
|
mi.pieceNo = pieceNo;
|
||||||
@@ -627,7 +627,7 @@ class CtgBook implements IOpeningBook {
|
|||||||
moveInfo[0xfe] = MI(Piece.WQUEEN , 1, -3, +3);
|
moveInfo[0xfe] = MI(Piece.WQUEEN , 1, -3, +3);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static int findPiece(Position pos, int piece, int pieceNo) {
|
private static int findPiece(Position pos, int piece, int pieceNo) {
|
||||||
for (int x = 0; x < 8; x++)
|
for (int x = 0; x < 8; x++)
|
||||||
for (int y = 0; y < 8; y++) {
|
for (int y = 0; y < 8; y++) {
|
||||||
int sq = Position.getSquare(x, y);
|
int sq = Position.getSquare(x, y);
|
||||||
@@ -638,7 +638,7 @@ class CtgBook implements IOpeningBook {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Move decodeMove(Position pos, int moveCode) {
|
private Move decodeMove(Position pos, int moveCode) {
|
||||||
MoveInfo mi = moveInfo[moveCode];
|
MoveInfo mi = moveInfo[moveCode];
|
||||||
if (mi == null)
|
if (mi == null)
|
||||||
return null;
|
return null;
|
||||||
@@ -656,13 +656,13 @@ class CtgBook implements IOpeningBook {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static int mirrorSquareColor(int sq) {
|
private static int mirrorSquareColor(int sq) {
|
||||||
int x = Position.getX(sq);
|
int x = Position.getX(sq);
|
||||||
int y = 7 - Position.getY(sq);
|
int y = 7 - Position.getY(sq);
|
||||||
return Position.getSquare(x, y);
|
return Position.getSquare(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static int mirrorPieceColor(int piece) {
|
private static int mirrorPieceColor(int piece) {
|
||||||
if (Piece.isWhite(piece)) {
|
if (Piece.isWhite(piece)) {
|
||||||
piece = Piece.makeBlack(piece);
|
piece = Piece.makeBlack(piece);
|
||||||
} else {
|
} else {
|
||||||
@@ -671,7 +671,7 @@ class CtgBook implements IOpeningBook {
|
|||||||
return piece;
|
return piece;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static Position mirrorPosColor(Position pos) {
|
private static Position mirrorPosColor(Position pos) {
|
||||||
Position ret = new Position(pos);
|
Position ret = new Position(pos);
|
||||||
for (int sq = 0; sq < 64; sq++) {
|
for (int sq = 0; sq < 64; sq++) {
|
||||||
int mSq = mirrorSquareColor(sq);
|
int mSq = mirrorSquareColor(sq);
|
||||||
@@ -696,7 +696,7 @@ class CtgBook implements IOpeningBook {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static Move mirrorMoveColor(Move m) {
|
private static Move mirrorMoveColor(Move m) {
|
||||||
if (m == null) return null;
|
if (m == null) return null;
|
||||||
Move ret = new Move(m);
|
Move ret = new Move(m);
|
||||||
ret.from = mirrorSquareColor(m.from);
|
ret.from = mirrorSquareColor(m.from);
|
||||||
@@ -705,13 +705,13 @@ class CtgBook implements IOpeningBook {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static int mirrorSquareLeftRight(int sq) {
|
private static int mirrorSquareLeftRight(int sq) {
|
||||||
int x = 7 - Position.getX(sq);
|
int x = 7 - Position.getX(sq);
|
||||||
int y = Position.getY(sq);
|
int y = Position.getY(sq);
|
||||||
return Position.getSquare(x, y);
|
return Position.getSquare(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static Position mirrorPosLeftRight(Position pos) {
|
private static Position mirrorPosLeftRight(Position pos) {
|
||||||
Position ret = new Position(pos);
|
Position ret = new Position(pos);
|
||||||
for (int sq = 0; sq < 64; sq++) {
|
for (int sq = 0; sq < 64; sq++) {
|
||||||
int mSq = mirrorSquareLeftRight(sq);
|
int mSq = mirrorSquareLeftRight(sq);
|
||||||
@@ -728,7 +728,7 @@ class CtgBook implements IOpeningBook {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static Move mirrorMoveLeftRight(Move m) {
|
private static Move mirrorMoveLeftRight(Move m) {
|
||||||
if (m == null) return null;
|
if (m == null) return null;
|
||||||
Move ret = new Move(m);
|
Move ret = new Move(m);
|
||||||
ret.from = mirrorSquareLeftRight(m.from);
|
ret.from = mirrorSquareLeftRight(m.from);
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ public final class DroidBook {
|
|||||||
public final synchronized Pair<String,ArrayList<Move>> getAllBookMoves(Position pos,
|
public final synchronized Pair<String,ArrayList<Move>> getAllBookMoves(Position pos,
|
||||||
boolean localized) {
|
boolean localized) {
|
||||||
StringBuilder ret = new StringBuilder();
|
StringBuilder ret = new StringBuilder();
|
||||||
ArrayList<Move> bookMoveList = new ArrayList<Move>();
|
ArrayList<Move> bookMoveList = new ArrayList<>();
|
||||||
ArrayList<BookEntry> bookMoves = getBook().getBookEntries(pos);
|
ArrayList<BookEntry> bookMoves = getBook().getBookEntries(pos);
|
||||||
|
|
||||||
// Check legality
|
// Check legality
|
||||||
@@ -165,10 +165,10 @@ public final class DroidBook {
|
|||||||
ret.append(percent);
|
ret.append(percent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new Pair<String, ArrayList<Move>>(ret.toString(), bookMoveList);
|
return new Pair<>(ret.toString(), bookMoveList);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final double scaleWeight(double w) {
|
private double scaleWeight(double w) {
|
||||||
if (w <= 0)
|
if (w <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
if (options == null)
|
if (options == null)
|
||||||
@@ -176,7 +176,7 @@ public final class DroidBook {
|
|||||||
return Math.pow(w, Math.exp(-options.random));
|
return Math.pow(w, Math.exp(-options.random));
|
||||||
}
|
}
|
||||||
|
|
||||||
private final IOpeningBook getBook() {
|
private IOpeningBook getBook() {
|
||||||
if (externalBook.enabled()) {
|
if (externalBook.enabled()) {
|
||||||
return externalBook;
|
return externalBook;
|
||||||
} else if (ecoBook.enabled()) {
|
} else if (ecoBook.enabled()) {
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public class EcoBook implements IOpeningBook {
|
|||||||
@Override
|
@Override
|
||||||
public ArrayList<BookEntry> getBookEntries(Position pos) {
|
public ArrayList<BookEntry> getBookEntries(Position pos) {
|
||||||
ArrayList<Move> moves = EcoDb.getInstance().getMoves(pos);
|
ArrayList<Move> moves = EcoDb.getInstance().getMoves(pos);
|
||||||
ArrayList<BookEntry> entries = new ArrayList<BookEntry>();
|
ArrayList<BookEntry> entries = new ArrayList<>();
|
||||||
for (int i = 0; i < moves.size(); i++) {
|
for (int i = 0; i < moves.size(); i++) {
|
||||||
BookEntry be = new BookEntry(moves.get(i));
|
BookEntry be = new BookEntry(moves.get(i));
|
||||||
be.weight = 10000 - i;
|
be.weight = 10000 - i;
|
||||||
|
|||||||
@@ -74,8 +74,8 @@ public class EcoDb {
|
|||||||
|
|
||||||
/** Get ECO classification for a given tree node. Also returns distance in plies to "ECO tree". */
|
/** Get ECO classification for a given tree node. Also returns distance in plies to "ECO tree". */
|
||||||
public Result getEco(GameTree gt) {
|
public Result getEco(GameTree gt) {
|
||||||
ArrayList<Integer> treePath = new ArrayList<Integer>(); // Path to restore gt to original node
|
ArrayList<Integer> treePath = new ArrayList<>(); // Path to restore gt to original node
|
||||||
ArrayList<Pair<GameTree.Node,Boolean>> toCache = new ArrayList<Pair<GameTree.Node,Boolean>>();
|
ArrayList<Pair<GameTree.Node,Boolean>> toCache = new ArrayList<>();
|
||||||
|
|
||||||
int nodeIdx = -1;
|
int nodeIdx = -1;
|
||||||
int distToEcoTree = 0;
|
int distToEcoTree = 0;
|
||||||
@@ -93,7 +93,7 @@ public class EcoDb {
|
|||||||
}
|
}
|
||||||
Short idx = posHashToNodeIdx.get(gt.currentPos.zobristHash());
|
Short idx = posHashToNodeIdx.get(gt.currentPos.zobristHash());
|
||||||
boolean inEcoTree = idx != null;
|
boolean inEcoTree = idx != null;
|
||||||
toCache.add(new Pair<GameTree.Node,Boolean>(node, inEcoTree));
|
toCache.add(new Pair<>(node, inEcoTree));
|
||||||
|
|
||||||
if (idx != null) {
|
if (idx != null) {
|
||||||
Node ecoNode = readNode(idx);
|
Node ecoNode = readNode(idx);
|
||||||
@@ -181,7 +181,7 @@ public class EcoDb {
|
|||||||
|
|
||||||
/** Get all moves in the ECO tree from a given position. */
|
/** Get all moves in the ECO tree from a given position. */
|
||||||
public ArrayList<Move> getMoves(Position pos) {
|
public ArrayList<Move> getMoves(Position pos) {
|
||||||
ArrayList<Move> moves = new ArrayList<Move>();
|
ArrayList<Move> moves = new ArrayList<>();
|
||||||
long hash = pos.zobristHash();
|
long hash = pos.zobristHash();
|
||||||
Short idx = posHashToNodeIdx.get(hash);
|
Short idx = posHashToNodeIdx.get(hash);
|
||||||
if (idx != null) {
|
if (idx != null) {
|
||||||
@@ -248,9 +248,9 @@ public class EcoDb {
|
|||||||
|
|
||||||
/** Constructor. */
|
/** Constructor. */
|
||||||
private EcoDb() {
|
private EcoDb() {
|
||||||
posHashToNodeIdx = new HashMap<Long, Short>();
|
posHashToNodeIdx = new HashMap<>();
|
||||||
posHashToNodeIdx2 = new HashMap<Long, ArrayList<Short>>();
|
posHashToNodeIdx2 = new HashMap<>();
|
||||||
gtNodeToIdx = new WeakLRUCache<GameTree.Node, CacheEntry>(50);
|
gtNodeToIdx = new WeakLRUCache<>(50);
|
||||||
try {
|
try {
|
||||||
ByteArrayOutputStream bufStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream bufStream = new ByteArrayOutputStream();
|
||||||
InputStream inStream = DroidFishApp.getContext().getAssets().open("eco.dat");
|
InputStream inStream = DroidFishApp.getContext().getAssets().open("eco.dat");
|
||||||
@@ -275,7 +275,7 @@ public class EcoDb {
|
|||||||
nodesBuffer = new byte[nNodes * 12];
|
nodesBuffer = new byte[nNodes * 12];
|
||||||
System.arraycopy(buf, 0, nodesBuffer, 0, nNodes * 12);
|
System.arraycopy(buf, 0, nodesBuffer, 0, nNodes * 12);
|
||||||
|
|
||||||
ArrayList<String> names = new ArrayList<String>();
|
ArrayList<String> names = new ArrayList<>();
|
||||||
int idx = (nNodes + 1) * 12;
|
int idx = (nNodes + 1) * 12;
|
||||||
int start = idx;
|
int start = idx;
|
||||||
for (int i = idx; i < buf.length; i++) {
|
for (int i = idx; i < buf.length; i++) {
|
||||||
@@ -308,7 +308,7 @@ public class EcoDb {
|
|||||||
} else if (node.ecoIdx != -1) {
|
} else if (node.ecoIdx != -1) {
|
||||||
ArrayList<Short> lst = null;
|
ArrayList<Short> lst = null;
|
||||||
if (posHashToNodeIdx2.get(hash) == null) {
|
if (posHashToNodeIdx2.get(hash) == null) {
|
||||||
lst = new ArrayList<Short>();
|
lst = new ArrayList<>();
|
||||||
posHashToNodeIdx2.put(hash, lst);
|
posHashToNodeIdx2.put(hash, lst);
|
||||||
} else {
|
} else {
|
||||||
lst = posHashToNodeIdx2.get(hash);
|
lst = posHashToNodeIdx2.get(hash);
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ final class InternalBook implements IOpeningBook {
|
|||||||
ArrayList<BookEntry> ents = bookMap.get(pos.zobristHash());
|
ArrayList<BookEntry> ents = bookMap.get(pos.zobristHash());
|
||||||
if (ents == null)
|
if (ents == null)
|
||||||
return null;
|
return null;
|
||||||
ArrayList<BookEntry> ret = new ArrayList<BookEntry>();
|
ArrayList<BookEntry> ret = new ArrayList<>();
|
||||||
for (BookEntry be : ents) {
|
for (BookEntry be : ents) {
|
||||||
BookEntry be2 = new BookEntry(be.move);
|
BookEntry be2 = new BookEntry(be.move);
|
||||||
be2.weight = (float)(Math.sqrt(be.weight) * 100 + 1);
|
be2.weight = (float)(Math.sqrt(be.weight) * 100 + 1);
|
||||||
@@ -82,13 +82,13 @@ final class InternalBook implements IOpeningBook {
|
|||||||
if (numBookMoves >= 0)
|
if (numBookMoves >= 0)
|
||||||
return;
|
return;
|
||||||
// long t0 = System.currentTimeMillis();
|
// long t0 = System.currentTimeMillis();
|
||||||
bookMap = new HashMap<Long, ArrayList<BookEntry>>();
|
bookMap = new HashMap<>();
|
||||||
numBookMoves = 0;
|
numBookMoves = 0;
|
||||||
try {
|
try {
|
||||||
InputStream inStream = getClass().getResourceAsStream("/book.bin");
|
InputStream inStream = getClass().getResourceAsStream("/book.bin");
|
||||||
if (inStream == null)
|
if (inStream == null)
|
||||||
throw new IOException();
|
throw new IOException();
|
||||||
List<Byte> buf = new ArrayList<Byte>(8192);
|
List<Byte> buf = new ArrayList<>(8192);
|
||||||
byte[] tmpBuf = new byte[1024];
|
byte[] tmpBuf = new byte[1024];
|
||||||
while (true) {
|
while (true) {
|
||||||
int len = inStream.read(tmpBuf);
|
int len = inStream.read(tmpBuf);
|
||||||
@@ -131,10 +131,10 @@ final class InternalBook implements IOpeningBook {
|
|||||||
|
|
||||||
|
|
||||||
/** Add a move to a position in the opening book. */
|
/** Add a move to a position in the opening book. */
|
||||||
private final void addToBook(Position pos, Move moveToAdd) {
|
private void addToBook(Position pos, Move moveToAdd) {
|
||||||
ArrayList<BookEntry> ent = bookMap.get(pos.zobristHash());
|
ArrayList<BookEntry> ent = bookMap.get(pos.zobristHash());
|
||||||
if (ent == null) {
|
if (ent == null) {
|
||||||
ent = new ArrayList<BookEntry>();
|
ent = new ArrayList<>();
|
||||||
bookMap.put(pos.zobristHash(), ent);
|
bookMap.put(pos.zobristHash(), ent);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < ent.size(); i++) {
|
for (int i = 0; i < ent.size(); i++) {
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ class PolyglotBook implements IOpeningBook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Castle flags
|
// Castle flags
|
||||||
if (pos.h1Castle()) key ^= hashRandoms[768 + 0];
|
if (pos.h1Castle()) key ^= hashRandoms[768];
|
||||||
if (pos.a1Castle()) key ^= hashRandoms[768 + 1];
|
if (pos.a1Castle()) key ^= hashRandoms[768 + 1];
|
||||||
if (pos.h8Castle()) key ^= hashRandoms[768 + 2];
|
if (pos.h8Castle()) key ^= hashRandoms[768 + 2];
|
||||||
if (pos.a8Castle()) key ^= hashRandoms[768 + 3];
|
if (pos.a8Castle()) key ^= hashRandoms[768 + 3];
|
||||||
@@ -300,7 +300,7 @@ class PolyglotBook implements IOpeningBook {
|
|||||||
data = new byte[16];
|
data = new byte[16];
|
||||||
}
|
}
|
||||||
|
|
||||||
private final long getBytes(int start, int len) {
|
private long getBytes(int start, int len) {
|
||||||
long ret = 0;
|
long ret = 0;
|
||||||
int stop = start + len;
|
int stop = start + len;
|
||||||
for (int i = start; i < stop; i++) {
|
for (int i = start; i < stop; i++) {
|
||||||
@@ -326,7 +326,7 @@ class PolyglotBook implements IOpeningBook {
|
|||||||
|
|
||||||
int from = Position.getSquare(fromFile, fromRow);
|
int from = Position.getSquare(fromFile, fromRow);
|
||||||
int to = Position.getSquare(toFile, toRow);
|
int to = Position.getSquare(toFile, toRow);
|
||||||
int promoteTo = Piece.EMPTY;
|
int promoteTo;
|
||||||
switch (prom) {
|
switch (prom) {
|
||||||
case 1: promoteTo = wtm ? Piece.WKNIGHT : Piece.BKNIGHT; break;
|
case 1: promoteTo = wtm ? Piece.WKNIGHT : Piece.BKNIGHT; break;
|
||||||
case 2: promoteTo = wtm ? Piece.WBISHOP : Piece.BBISHOP; break;
|
case 2: promoteTo = wtm ? Piece.WBISHOP : Piece.BBISHOP; break;
|
||||||
@@ -345,17 +345,16 @@ class PolyglotBook implements IOpeningBook {
|
|||||||
if ((from == 60) && (pos.getPiece(from) == Piece.BKING)) {
|
if ((from == 60) && (pos.getPiece(from) == Piece.BKING)) {
|
||||||
if (to == 56+7)
|
if (to == 56+7)
|
||||||
to = 56+6;
|
to = 56+6;
|
||||||
else if (to == 56+0)
|
else if (to == 56)
|
||||||
to = 56+2;
|
to = 56+2;
|
||||||
}
|
}
|
||||||
|
|
||||||
Move m = new Move(from, to, promoteTo);
|
return new Move(from, to, promoteTo);
|
||||||
return m;
|
|
||||||
}
|
}
|
||||||
final int getWeight() { return (int)getBytes(10, 2); }
|
final int getWeight() { return (int)getBytes(10, 2); }
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void readEntry(RandomAccessFile f, long entNo, PGBookEntry ent) throws IOException {
|
private void readEntry(RandomAccessFile f, long entNo, PGBookEntry ent) throws IOException {
|
||||||
f.seek(entNo * 16);
|
f.seek(entNo * 16);
|
||||||
if (f.read(ent.data) != 16) {
|
if (f.read(ent.data) != 16) {
|
||||||
for (int i = 0; i < 16; i++) ent.data[i] = 0;
|
for (int i = 0; i < 16; i++) ent.data[i] = 0;
|
||||||
@@ -363,7 +362,7 @@ class PolyglotBook implements IOpeningBook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Return true if key1 < key2, when compared as unsigned longs. */
|
/** Return true if key1 < key2, when compared as unsigned longs. */
|
||||||
private final boolean keyLess(long key1, long key2) {
|
private boolean keyLess(long key1, long key2) {
|
||||||
if ((key1 < 0) == (key2 < 0)) { // Same sign, normal compare
|
if ((key1 < 0) == (key2 < 0)) { // Same sign, normal compare
|
||||||
return key1 < key2;
|
return key1 < key2;
|
||||||
} else { // The negative number is largest
|
} else { // The negative number is largest
|
||||||
@@ -395,7 +394,7 @@ class PolyglotBook implements IOpeningBook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read all entries with matching hash key
|
// Read all entries with matching hash key
|
||||||
ArrayList<BookEntry> ret = new ArrayList<BookEntry>();
|
ArrayList<BookEntry> ret = new ArrayList<>();
|
||||||
long entNo = hi;
|
long entNo = hi;
|
||||||
while (entNo < numEntries) {
|
while (entNo < numEntries) {
|
||||||
readEntry(f, entNo, ent);
|
readEntry(f, entNo, ent);
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public class DroidComputerPlayer {
|
|||||||
private final DroidBook book;
|
private final DroidBook book;
|
||||||
private EngineOptions engineOptions = new EngineOptions();
|
private EngineOptions engineOptions = new EngineOptions();
|
||||||
/** Pending UCI options to send when engine becomes idle. */
|
/** Pending UCI options to send when engine becomes idle. */
|
||||||
private Map<String,String> pendingOptions = new TreeMap<String,String>();
|
private Map<String,String> pendingOptions = new TreeMap<>();
|
||||||
|
|
||||||
/** Set when "ucinewgame" needs to be sent. */
|
/** Set when "ucinewgame" needs to be sent. */
|
||||||
private boolean newGame = false;
|
private boolean newGame = false;
|
||||||
@@ -365,7 +365,7 @@ public class DroidComputerPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Decide what moves to search. Filters out non-optimal moves if tablebases are used. */
|
/** Decide what moves to search. Filters out non-optimal moves if tablebases are used. */
|
||||||
private final ArrayList<Move> movesToSearch(SearchRequest sr) {
|
private ArrayList<Move> movesToSearch(SearchRequest sr) {
|
||||||
ArrayList<Move> moves = null;
|
ArrayList<Move> moves = null;
|
||||||
ArrayList<Move> legalMoves = new MoveGen().legalMoves(sr.currPos);
|
ArrayList<Move> legalMoves = new MoveGen().legalMoves(sr.currPos);
|
||||||
if (engineOptions.rootProbe)
|
if (engineOptions.rootProbe)
|
||||||
@@ -450,7 +450,7 @@ public class DroidComputerPlayer {
|
|||||||
handleQueue();
|
handleQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void handleQueue() {
|
private void handleQueue() {
|
||||||
if (engineState.state == MainState.DEAD) {
|
if (engineState.state == MainState.DEAD) {
|
||||||
engineState.engine = "";
|
engineState.engine = "";
|
||||||
engineState.setState(MainState.IDLE);
|
engineState.setState(MainState.IDLE);
|
||||||
@@ -519,7 +519,7 @@ public class DroidComputerPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Determine what to do next when in idle state. */
|
/** Determine what to do next when in idle state. */
|
||||||
private final void handleIdleState() {
|
private void handleIdleState() {
|
||||||
SearchRequest sr = searchRequest;
|
SearchRequest sr = searchRequest;
|
||||||
if (sr == null)
|
if (sr == null)
|
||||||
return;
|
return;
|
||||||
@@ -640,7 +640,7 @@ public class DroidComputerPlayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void startEngine() {
|
private void startEngine() {
|
||||||
myAssert(uciEngine == null);
|
myAssert(uciEngine == null);
|
||||||
myAssert(engineMonitor == null);
|
myAssert(engineMonitor == null);
|
||||||
myAssert(engineState.state == MainState.DEAD);
|
myAssert(engineState.state == MainState.DEAD);
|
||||||
@@ -678,7 +678,7 @@ public class DroidComputerPlayer {
|
|||||||
private final static long guiUpdateInterval = 100;
|
private final static long guiUpdateInterval = 100;
|
||||||
private long lastGUIUpdate = 0;
|
private long lastGUIUpdate = 0;
|
||||||
|
|
||||||
private final void monitorLoop(UCIEngine uci) {
|
private void monitorLoop(UCIEngine uci) {
|
||||||
while (true) {
|
while (true) {
|
||||||
int timeout = getReadTimeout();
|
int timeout = getReadTimeout();
|
||||||
if (Thread.currentThread().isInterrupted())
|
if (Thread.currentThread().isInterrupted())
|
||||||
@@ -706,7 +706,7 @@ public class DroidComputerPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Process one line of data from the engine. */
|
/** Process one line of data from the engine. */
|
||||||
private final synchronized void processEngineOutput(UCIEngine uci, String s) {
|
private synchronized void processEngineOutput(UCIEngine uci, String s) {
|
||||||
if (Thread.currentThread().isInterrupted())
|
if (Thread.currentThread().isInterrupted())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -775,7 +775,7 @@ public class DroidComputerPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Handle reading of UCI options. Return true when finished. */
|
/** Handle reading of UCI options. Return true when finished. */
|
||||||
private final boolean readUCIOption(UCIEngine uci, String s) {
|
private boolean readUCIOption(UCIEngine uci, String s) {
|
||||||
String[] tokens = tokenize(s);
|
String[] tokens = tokenize(s);
|
||||||
if (tokens[0].equals("uciok"))
|
if (tokens[0].equals("uciok"))
|
||||||
return true;
|
return true;
|
||||||
@@ -799,7 +799,7 @@ public class DroidComputerPlayer {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void reportMove(String bestMove, Move nextPonderMove) {
|
private void reportMove(String bestMove, Move nextPonderMove) {
|
||||||
SearchRequest sr = searchRequest;
|
SearchRequest sr = searchRequest;
|
||||||
boolean canPonder = true;
|
boolean canPonder = true;
|
||||||
|
|
||||||
@@ -836,7 +836,7 @@ public class DroidComputerPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Convert a string to tokens by splitting at whitespace characters. */
|
/** Convert a string to tokens by splitting at whitespace characters. */
|
||||||
private final String[] tokenize(String cmdLine) {
|
private String[] tokenize(String cmdLine) {
|
||||||
cmdLine = cmdLine.trim();
|
cmdLine = cmdLine.trim();
|
||||||
return cmdLine.split("\\s+");
|
return cmdLine.split("\\s+");
|
||||||
}
|
}
|
||||||
@@ -845,7 +845,7 @@ public class DroidComputerPlayer {
|
|||||||
* @param move The move that may have to be made before claiming draw.
|
* @param move The move that may have to be made before claiming draw.
|
||||||
* @return The draw string that claims the draw, or empty string if draw claim not valid.
|
* @return The draw string that claims the draw, or empty string if draw claim not valid.
|
||||||
*/
|
*/
|
||||||
private final static String canClaimDraw(Position pos, long[] posHashList, int posHashListSize, Move move) {
|
private static String canClaimDraw(Position pos, long[] posHashList, int posHashListSize, Move move) {
|
||||||
String drawStr = "";
|
String drawStr = "";
|
||||||
if (canClaimDraw50(pos)) {
|
if (canClaimDraw50(pos)) {
|
||||||
drawStr = "draw 50";
|
drawStr = "draw 50";
|
||||||
@@ -866,11 +866,11 @@ public class DroidComputerPlayer {
|
|||||||
return drawStr;
|
return drawStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static boolean canClaimDraw50(Position pos) {
|
private static boolean canClaimDraw50(Position pos) {
|
||||||
return (pos.halfMoveClock >= 100);
|
return (pos.halfMoveClock >= 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static boolean canClaimDrawRep(Position pos, long[] posHashList, int posHashListSize, int posHashFirstNew) {
|
private static boolean canClaimDrawRep(Position pos, long[] posHashList, int posHashListSize, int posHashFirstNew) {
|
||||||
int reps = 0;
|
int reps = 0;
|
||||||
for (int i = posHashListSize - 4; i >= 0; i -= 2) {
|
for (int i = posHashListSize - 4; i >= 0; i -= 2) {
|
||||||
if (pos.zobristHash() == posHashList[i]) {
|
if (pos.zobristHash() == posHashList[i]) {
|
||||||
@@ -897,18 +897,18 @@ public class DroidComputerPlayer {
|
|||||||
private int statHash = 0;
|
private int statHash = 0;
|
||||||
private int statSelDepth = 0;
|
private int statSelDepth = 0;
|
||||||
private int statNps = 0;
|
private int statNps = 0;
|
||||||
private ArrayList<String> statPV = new ArrayList<String>();
|
private ArrayList<String> statPV = new ArrayList<>();
|
||||||
private String statCurrMove = "";
|
private String statCurrMove = "";
|
||||||
private int statCurrMoveNr = 0;
|
private int statCurrMoveNr = 0;
|
||||||
|
|
||||||
private ArrayList<PvInfo> statPvInfo = new ArrayList<PvInfo>();
|
private ArrayList<PvInfo> statPvInfo = new ArrayList<>();
|
||||||
|
|
||||||
private boolean depthModified = false;
|
private boolean depthModified = false;
|
||||||
private boolean currMoveModified = false;
|
private boolean currMoveModified = false;
|
||||||
private boolean pvModified = false;
|
private boolean pvModified = false;
|
||||||
private boolean statsModified = false;
|
private boolean statsModified = false;
|
||||||
|
|
||||||
private final void clearInfo() {
|
private void clearInfo() {
|
||||||
statCurrDepth = statPVDepth = statScore = 0;
|
statCurrDepth = statPVDepth = statScore = 0;
|
||||||
statIsMate = statUpperBound = statLowerBound = false;
|
statIsMate = statUpperBound = statLowerBound = false;
|
||||||
statTime = 0;
|
statTime = 0;
|
||||||
@@ -925,7 +925,7 @@ public class DroidComputerPlayer {
|
|||||||
statCurrMoveNr = 0;
|
statCurrMoveNr = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final synchronized int getReadTimeout() {
|
private synchronized int getReadTimeout() {
|
||||||
boolean needGuiUpdate = depthModified || currMoveModified || pvModified || statsModified;
|
boolean needGuiUpdate = depthModified || currMoveModified || pvModified || statsModified;
|
||||||
int timeout = 2000000000;
|
int timeout = 2000000000;
|
||||||
if (needGuiUpdate) {
|
if (needGuiUpdate) {
|
||||||
@@ -936,7 +936,7 @@ public class DroidComputerPlayer {
|
|||||||
return timeout;
|
return timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void parseInfoCmd(String[] tokens) {
|
private void parseInfoCmd(String[] tokens) {
|
||||||
try {
|
try {
|
||||||
boolean havePvData = false;
|
boolean havePvData = false;
|
||||||
int nTokens = tokens.length;
|
int nTokens = tokens.length;
|
||||||
@@ -1003,7 +1003,7 @@ public class DroidComputerPlayer {
|
|||||||
statPvInfo.add(new PvInfo(0, 0, 0, 0, 0, 0, 0, 0, false, false, false, new ArrayList<Move>()));
|
statPvInfo.add(new PvInfo(0, 0, 0, 0, 0, 0, 0, 0, false, false, false, new ArrayList<Move>()));
|
||||||
while (statPvInfo.size() <= pvNum)
|
while (statPvInfo.size() <= pvNum)
|
||||||
statPvInfo.add(null);
|
statPvInfo.add(null);
|
||||||
ArrayList<Move> moves = new ArrayList<Move>();
|
ArrayList<Move> moves = new ArrayList<>();
|
||||||
int nMoves = statPV.size();
|
int nMoves = statPV.size();
|
||||||
for (i = 0; i < nMoves; i++)
|
for (i = 0; i < nMoves; i++)
|
||||||
moves.add(TextIO.UCIstringToMove(statPV.get(i)));
|
moves.add(TextIO.UCIstringToMove(statPV.get(i)));
|
||||||
@@ -1019,7 +1019,7 @@ public class DroidComputerPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Notify GUI about search statistics. */
|
/** Notify GUI about search statistics. */
|
||||||
private final synchronized void notifyGUI() {
|
private synchronized void notifyGUI() {
|
||||||
if (Thread.currentThread().isInterrupted())
|
if (Thread.currentThread().isInterrupted())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -1058,7 +1058,7 @@ public class DroidComputerPlayer {
|
|||||||
lastGUIUpdate = System.currentTimeMillis();
|
lastGUIUpdate = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static void myAssert(boolean b) {
|
private static void myAssert(boolean b) {
|
||||||
if (!b)
|
if (!b)
|
||||||
throw new RuntimeException();
|
throw new RuntimeException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -221,7 +221,7 @@ public class ExternalEngine extends UCIEngineBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Reduce too large hash sizes. */
|
/** Reduce too large hash sizes. */
|
||||||
private final static int getHashMB(EngineOptions engineOptions) {
|
private static int getHashMB(EngineOptions engineOptions) {
|
||||||
int hashMB = engineOptions.hashMB;
|
int hashMB = engineOptions.hashMB;
|
||||||
if (hashMB > 16 && !engineOptions.unSafeHash) {
|
if (hashMB > 16 && !engineOptions.unSafeHash) {
|
||||||
int maxMem = (int)(Runtime.getRuntime().maxMemory() / (1024*1024));
|
int maxMem = (int)(Runtime.getRuntime().maxMemory() / (1024*1024));
|
||||||
@@ -332,7 +332,7 @@ public class ExternalEngine extends UCIEngineBase {
|
|||||||
return to.getAbsolutePath();
|
return to.getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void chmod(String exePath) throws IOException {
|
private void chmod(String exePath) throws IOException {
|
||||||
if (!EngineUtil.chmod(exePath))
|
if (!EngineUtil.chmod(exePath))
|
||||||
throw new IOException("chmod failed");
|
throw new IOException("chmod failed");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public class InternalStockFish extends ExternalEngine {
|
|||||||
setOption("Skill Level", strength/50);
|
setOption("Skill Level", strength/50);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final long readCheckSum(File f) {
|
private long readCheckSum(File f) {
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
try {
|
try {
|
||||||
is = new FileInputStream(f);
|
is = new FileInputStream(f);
|
||||||
@@ -75,7 +75,7 @@ public class InternalStockFish extends ExternalEngine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void writeCheckSum(File f, long checkSum) {
|
private void writeCheckSum(File f, long checkSum) {
|
||||||
DataOutputStream dos = null;
|
DataOutputStream dos = null;
|
||||||
try {
|
try {
|
||||||
OutputStream os = new FileOutputStream(f);
|
OutputStream os = new FileOutputStream(f);
|
||||||
@@ -87,7 +87,7 @@ public class InternalStockFish extends ExternalEngine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final long computeAssetsCheckSum(String sfExe) {
|
private long computeAssetsCheckSum(String sfExe) {
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
try {
|
try {
|
||||||
is = context.getAssets().open(sfExe);
|
is = context.getAssets().open(sfExe);
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import java.util.Locale;
|
|||||||
|
|
||||||
/** Implements line-based text communication between threads. */
|
/** Implements line-based text communication between threads. */
|
||||||
public class LocalPipe {
|
public class LocalPipe {
|
||||||
private LinkedList<String> lines = new LinkedList<String>();
|
private LinkedList<String> lines = new LinkedList<>();
|
||||||
private boolean closed = false;
|
private boolean closed = false;
|
||||||
|
|
||||||
/** Write a line to the pipe. */
|
/** Write a line to the pipe. */
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public class NetworkEngine extends UCIEngineBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Create socket connection to remote server. */
|
/** Create socket connection to remote server. */
|
||||||
private final synchronized void connect() {
|
private synchronized void connect() {
|
||||||
if (socket == null) {
|
if (socket == null) {
|
||||||
String host = null;
|
String host = null;
|
||||||
String port = null;
|
String port = null;
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ public abstract class UCIEngineBase implements UCIEngine {
|
|||||||
String defVal = null;
|
String defVal = null;
|
||||||
String minVal = null;
|
String minVal = null;
|
||||||
String maxVal = null;
|
String maxVal = null;
|
||||||
ArrayList<String> var = new ArrayList<String>();
|
ArrayList<String> var = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
for (; i < tokens.length; i++) {
|
for (; i < tokens.length; i++) {
|
||||||
if (tokens[i].equals("default")) {
|
if (tokens[i].equals("default")) {
|
||||||
|
|||||||
@@ -223,18 +223,18 @@ public class UCIOptions implements Serializable, Cloneable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UCIOptions() {
|
UCIOptions() {
|
||||||
names = new ArrayList<String>();
|
names = new ArrayList<>();
|
||||||
options = new TreeMap<String, OptionBase>();
|
options = new TreeMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UCIOptions clone() throws CloneNotSupportedException {
|
public UCIOptions clone() throws CloneNotSupportedException {
|
||||||
UCIOptions copy = new UCIOptions();
|
UCIOptions copy = new UCIOptions();
|
||||||
|
|
||||||
copy.names = new ArrayList<String>();
|
copy.names = new ArrayList<>();
|
||||||
copy.names.addAll(names);
|
copy.names.addAll(names);
|
||||||
|
|
||||||
copy.options = new TreeMap<String, OptionBase>();
|
copy.options = new TreeMap<>();
|
||||||
for (Map.Entry<String, OptionBase> e : options.entrySet())
|
for (Map.Entry<String, OptionBase> e : options.entrySet())
|
||||||
copy.options.put(e.getKey(), e.getValue().clone());
|
copy.options.put(e.getKey(), e.getValue().clone());
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class CuckooChessEngine extends UCIEngineBase {
|
|||||||
|
|
||||||
public CuckooChessEngine(Report report) {
|
public CuckooChessEngine(Report report) {
|
||||||
pos = null;
|
pos = null;
|
||||||
moves = new ArrayList<Move>();
|
moves = new ArrayList<>();
|
||||||
quit = false;
|
quit = false;
|
||||||
guiToEngine = new LocalPipe();
|
guiToEngine = new LocalPipe();
|
||||||
engineToGui = new LocalPipe();
|
engineToGui = new LocalPipe();
|
||||||
@@ -100,7 +100,7 @@ public class CuckooChessEngine extends UCIEngineBase {
|
|||||||
setOption("strength", strength);
|
setOption("strength", strength);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void mainLoop(LocalPipe is, LocalPipe os) {
|
private void mainLoop(LocalPipe is, LocalPipe os) {
|
||||||
String line;
|
String line;
|
||||||
while ((line = is.readLine()) != null) {
|
while ((line = is.readLine()) != null) {
|
||||||
handleCommand(line, os);
|
handleCommand(line, os);
|
||||||
@@ -137,7 +137,7 @@ public class CuckooChessEngine extends UCIEngineBase {
|
|||||||
guiToEngine.addLine(data);
|
guiToEngine.addLine(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void handleCommand(String cmdLine, LocalPipe os) {
|
private void handleCommand(String cmdLine, LocalPipe os) {
|
||||||
String[] tokens = tokenize(cmdLine);
|
String[] tokens = tokenize(cmdLine);
|
||||||
try {
|
try {
|
||||||
String cmd = tokens[0];
|
String cmd = tokens[0];
|
||||||
@@ -269,14 +269,14 @@ public class CuckooChessEngine extends UCIEngineBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void initEngine(LocalPipe os) {
|
private void initEngine(LocalPipe os) {
|
||||||
if (engine == null) {
|
if (engine == null) {
|
||||||
engine = new DroidEngineControl(os);
|
engine = new DroidEngineControl(os);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Convert a string to tokens by splitting at whitespace characters. */
|
/** Convert a string to tokens by splitting at whitespace characters. */
|
||||||
private final String[] tokenize(String cmdLine) {
|
private String[] tokenize(String cmdLine) {
|
||||||
cmdLine = cmdLine.trim();
|
cmdLine = cmdLine.trim();
|
||||||
return cmdLine.split("\\s+");
|
return cmdLine.split("\\s+");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -296,7 +296,7 @@ public class DroidEngineControl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private final void setupTT() {
|
private void setupTT() {
|
||||||
int nEntries = hashSizeMB > 0 ? hashSizeMB * (1 << 20) / 24 : 1024;
|
int nEntries = hashSizeMB > 0 ? hashSizeMB * (1 << 20) / 24 : 1024;
|
||||||
int logSize = (int) Math.floor(Math.log(nEntries) / Math.log(2));
|
int logSize = (int) Math.floor(Math.log(nEntries) / Math.log(2));
|
||||||
tt = new TranspositionTable(logSize);
|
tt = new TranspositionTable(logSize);
|
||||||
|
|||||||
@@ -37,6 +37,6 @@ public class SearchParams {
|
|||||||
boolean infinite;
|
boolean infinite;
|
||||||
|
|
||||||
public SearchParams() {
|
public SearchParams() {
|
||||||
searchMoves = new ArrayList<Move>();
|
searchMoves = new ArrayList<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -636,7 +636,7 @@ public class DroidChessController {
|
|||||||
/** Add ECO classification headers. */
|
/** Add ECO classification headers. */
|
||||||
public final synchronized void addECO() {
|
public final synchronized void addECO() {
|
||||||
EcoDb.Result r = game.tree.getGameECO();
|
EcoDb.Result r = game.tree.getGameECO();
|
||||||
Map<String,String> headers = new TreeMap<String,String>();
|
Map<String,String> headers = new TreeMap<>();
|
||||||
headers.put("ECO", r.eco.isEmpty() ? null : r.eco);
|
headers.put("ECO", r.eco.isEmpty() ? null : r.eco);
|
||||||
headers.put("Opening", r.opn.isEmpty() ? null : r.opn);
|
headers.put("Opening", r.opn.isEmpty() ? null : r.opn);
|
||||||
headers.put("Variation", r.var.isEmpty() ? null : r.var);
|
headers.put("Variation", r.var.isEmpty() ? null : r.var);
|
||||||
@@ -674,7 +674,7 @@ public class DroidChessController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Return true if localized piece names should be used. */
|
/** Return true if localized piece names should be used. */
|
||||||
private final boolean localPt() {
|
private boolean localPt() {
|
||||||
switch (pgnOptions.view.pieceType) {
|
switch (pgnOptions.view.pieceType) {
|
||||||
case PGNOptions.PT_ENGLISH:
|
case PGNOptions.PT_ENGLISH:
|
||||||
return false;
|
return false;
|
||||||
@@ -705,7 +705,7 @@ public class DroidChessController {
|
|||||||
private int distToEcoTree = 0; // Number of plies since game was in the "ECO tree".
|
private int distToEcoTree = 0; // Number of plies since game was in the "ECO tree".
|
||||||
|
|
||||||
private Move ponderMove = null;
|
private Move ponderMove = null;
|
||||||
private ArrayList<PvInfo> pvInfoV = new ArrayList<PvInfo>();
|
private ArrayList<PvInfo> pvInfoV = new ArrayList<>();
|
||||||
private int pvInfoSearchId = -1; // Search ID corresponding to pvInfoV
|
private int pvInfoSearchId = -1; // Search ID corresponding to pvInfoV
|
||||||
|
|
||||||
public final void clearSearchInfo(int id) {
|
public final void clearSearchInfo(int id) {
|
||||||
@@ -720,7 +720,7 @@ public class DroidChessController {
|
|||||||
setSearchInfo(id);
|
setSearchInfo(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void setSearchInfo(final int id) {
|
private void setSearchInfo(final int id) {
|
||||||
StringBuilder buf = new StringBuilder();
|
StringBuilder buf = new StringBuilder();
|
||||||
for (int i = 0; i < pvInfoV.size(); i++) {
|
for (int i = 0; i < pvInfoV.size(); i++) {
|
||||||
PvInfo pvi = pvInfoV.get(i);
|
PvInfo pvi = pvInfoV.get(i);
|
||||||
@@ -770,10 +770,10 @@ public class DroidChessController {
|
|||||||
}
|
}
|
||||||
final String statStr = statStrTmp.toString();
|
final String statStr = statStrTmp.toString();
|
||||||
final String newPV = buf.toString();
|
final String newPV = buf.toString();
|
||||||
final ArrayList<ArrayList<Move>> pvMoves = new ArrayList<ArrayList<Move>>();
|
final ArrayList<ArrayList<Move>> pvMoves = new ArrayList<>();
|
||||||
for (int i = 0; i < pvInfoV.size(); i++) {
|
for (int i = 0; i < pvInfoV.size(); i++) {
|
||||||
if (ponderMove != null) {
|
if (ponderMove != null) {
|
||||||
ArrayList<Move> tmp = new ArrayList<Move>();
|
ArrayList<Move> tmp = new ArrayList<>();
|
||||||
tmp.add(ponderMove);
|
tmp.add(ponderMove);
|
||||||
for (Move m : pvInfoV.get(i).pv)
|
for (Move m : pvInfoV.get(i).pv)
|
||||||
tmp.add(m);
|
tmp.add(m);
|
||||||
@@ -934,7 +934,7 @@ public class DroidChessController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Discard current search. Return true if GUI update needed. */
|
/** Discard current search. Return true if GUI update needed. */
|
||||||
private final boolean abortSearch() {
|
private boolean abortSearch() {
|
||||||
ponderMove = null;
|
ponderMove = null;
|
||||||
searchId++;
|
searchId++;
|
||||||
if (computerPlayer == null)
|
if (computerPlayer == null)
|
||||||
@@ -946,7 +946,7 @@ public class DroidChessController {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void updateBookHints() {
|
private void updateBookHints() {
|
||||||
if (game != null) {
|
if (game != null) {
|
||||||
Pair<String, ArrayList<Move>> bi = computerPlayer.getBookHints(game.currPos(), localPt());
|
Pair<String, ArrayList<Move>> bi = computerPlayer.getBookHints(game.currPos(), localPt());
|
||||||
EcoDb.Result ecoData = EcoDb.getInstance().getEco(game.tree);
|
EcoDb.Result ecoData = EcoDb.getInstance().getEco(game.tree);
|
||||||
@@ -955,7 +955,7 @@ public class DroidChessController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void updateGameMode() {
|
private void updateGameMode() {
|
||||||
if (game != null) {
|
if (game != null) {
|
||||||
boolean gamePaused = !gameMode.clocksActive() || (humansTurn() && guiPaused);
|
boolean gamePaused = !gameMode.clocksActive() || (humansTurn() && guiPaused);
|
||||||
game.setGamePaused(gamePaused);
|
game.setGamePaused(gamePaused);
|
||||||
@@ -972,7 +972,7 @@ public class DroidChessController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Start/stop computer thinking/analysis as appropriate. */
|
/** Start/stop computer thinking/analysis as appropriate. */
|
||||||
private final void updateComputeThreads() {
|
private void updateComputeThreads() {
|
||||||
boolean alive = game.tree.getGameState() == GameState.ALIVE;
|
boolean alive = game.tree.getGameState() == GameState.ALIVE;
|
||||||
boolean analysis = gameMode.analysisMode() && alive;
|
boolean analysis = gameMode.analysisMode() && alive;
|
||||||
boolean computersTurn = !humansTurn() && alive;
|
boolean computersTurn = !humansTurn() && alive;
|
||||||
@@ -1021,7 +1021,7 @@ public class DroidChessController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final synchronized void makeComputerMove(int id, final String cmd, final Move ponder) {
|
private synchronized void makeComputerMove(int id, final String cmd, final Move ponder) {
|
||||||
if (searchId != id)
|
if (searchId != id)
|
||||||
return;
|
return;
|
||||||
searchId++;
|
searchId++;
|
||||||
@@ -1043,7 +1043,7 @@ public class DroidChessController {
|
|||||||
gui.movePlayed(game.prevPos(), game.tree.currentNode.move, true);
|
gui.movePlayed(game.prevPos(), game.tree.currentNode.move, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void setPlayerNames(Game game) {
|
private void setPlayerNames(Game game) {
|
||||||
if (game != null) {
|
if (game != null) {
|
||||||
String engine = "Computer";
|
String engine = "Computer";
|
||||||
if (computerPlayer != null) {
|
if (computerPlayer != null) {
|
||||||
@@ -1058,7 +1058,7 @@ public class DroidChessController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final synchronized void updatePlayerNames(String engineName) {
|
private synchronized void updatePlayerNames(String engineName) {
|
||||||
if (game != null) {
|
if (game != null) {
|
||||||
if (strength < 1000)
|
if (strength < 1000)
|
||||||
engineName += String.format(Locale.US, " (%.1f%%)", strength * 0.1);
|
engineName += String.format(Locale.US, " (%.1f%%)", strength * 0.1);
|
||||||
@@ -1069,7 +1069,7 @@ public class DroidChessController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final boolean undoMoveNoUpdate() {
|
private boolean undoMoveNoUpdate() {
|
||||||
if (game.getLastMove() == null)
|
if (game.getLastMove() == null)
|
||||||
return false;
|
return false;
|
||||||
searchId++;
|
searchId++;
|
||||||
@@ -1093,7 +1093,7 @@ public class DroidChessController {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void redoMoveNoUpdate() {
|
private void redoMoveNoUpdate() {
|
||||||
if (game.canRedoMove()) {
|
if (game.canRedoMove()) {
|
||||||
searchId++;
|
searchId++;
|
||||||
game.redoMove();
|
game.redoMove();
|
||||||
@@ -1109,7 +1109,7 @@ public class DroidChessController {
|
|||||||
* Move a piece from one square to another.
|
* Move a piece from one square to another.
|
||||||
* @return True if the move was legal, false otherwise.
|
* @return True if the move was legal, false otherwise.
|
||||||
*/
|
*/
|
||||||
private final boolean doMove(Move move) {
|
private boolean doMove(Move move) {
|
||||||
Position pos = game.currPos();
|
Position pos = game.currPos();
|
||||||
ArrayList<Move> moves = new MoveGen().legalMoves(pos);
|
ArrayList<Move> moves = new MoveGen().legalMoves(pos);
|
||||||
int promoteTo = move.promoteTo;
|
int promoteTo = move.promoteTo;
|
||||||
@@ -1132,7 +1132,7 @@ public class DroidChessController {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void updateGUI() {
|
private void updateGUI() {
|
||||||
GUIInterface.GameStatus s = new GUIInterface.GameStatus();
|
GUIInterface.GameStatus s = new GUIInterface.GameStatus();
|
||||||
s.state = game.getGameState();
|
s.state = game.getGameState();
|
||||||
if (s.state == GameState.ALIVE) {
|
if (s.state == GameState.ALIVE) {
|
||||||
@@ -1180,12 +1180,12 @@ public class DroidChessController {
|
|||||||
gui.updateMaterialDifferenceTitle(Util.getMaterialDiff(game.currPos()));
|
gui.updateMaterialDifferenceTitle(Util.getMaterialDiff(game.currPos()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private final synchronized void setThinkingInfo(ThinkingInfo ti) {
|
private synchronized void setThinkingInfo(ThinkingInfo ti) {
|
||||||
if ((ti.id == searchId) && (ti == latestThinkingInfo))
|
if ((ti.id == searchId) && (ti == latestThinkingInfo))
|
||||||
gui.setThinkingInfo(ti);
|
gui.setThinkingInfo(ti);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void updateMoveList() {
|
private void updateMoveList() {
|
||||||
if (game == null)
|
if (game == null)
|
||||||
return;
|
return;
|
||||||
if (!gameTextListener.isUpToDate()) {
|
if (!gameTextListener.isUpToDate()) {
|
||||||
@@ -1205,7 +1205,7 @@ public class DroidChessController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Mark last played move in the GUI. */
|
/** Mark last played move in the GUI. */
|
||||||
private final void setSelection() {
|
private void setSelection() {
|
||||||
Move m = game.getLastMove();
|
Move m = game.getLastMove();
|
||||||
int sq = ((m != null) && (m.from != m.to)) ? m.to : -1;
|
int sq = ((m != null) && (m.from != m.to)) ? m.to : -1;
|
||||||
gui.setSelection(sq);
|
gui.setSelection(sq);
|
||||||
@@ -1215,7 +1215,7 @@ public class DroidChessController {
|
|||||||
gui.setAnimMove(sourcePos, move, forward);
|
gui.setAnimMove(sourcePos, move, forward);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final boolean findValidDrawClaim(String ms) {
|
private boolean findValidDrawClaim(String ms) {
|
||||||
if (!ms.isEmpty())
|
if (!ms.isEmpty())
|
||||||
ms = " " + ms;
|
ms = " " + ms;
|
||||||
if (game.getGameState() != GameState.ALIVE) return true;
|
if (game.getGameState() != GameState.ALIVE) return true;
|
||||||
|
|||||||
@@ -134,14 +134,14 @@ public class Game {
|
|||||||
* Second item is move played, or null if no move was played. */
|
* Second item is move played, or null if no move was played. */
|
||||||
public final Pair<Boolean, Move> processString(String str) {
|
public final Pair<Boolean, Move> processString(String str) {
|
||||||
if (getGameState() != GameState.ALIVE)
|
if (getGameState() != GameState.ALIVE)
|
||||||
return new Pair<Boolean,Move>(false, null);
|
return new Pair<>(false, null);
|
||||||
if (str.startsWith("draw ")) {
|
if (str.startsWith("draw ")) {
|
||||||
String drawCmd = str.substring(str.indexOf(" ") + 1);
|
String drawCmd = str.substring(str.indexOf(" ") + 1);
|
||||||
Move m = handleDrawCmd(drawCmd, true);
|
Move m = handleDrawCmd(drawCmd, true);
|
||||||
return new Pair<Boolean,Move>(true, m);
|
return new Pair<>(true, m);
|
||||||
} else if (str.equals("resign")) {
|
} else if (str.equals("resign")) {
|
||||||
addToGameTree(new Move(0, 0, 0), "resign");
|
addToGameTree(new Move(0, 0, 0), "resign");
|
||||||
return new Pair<Boolean,Move>(true, null);
|
return new Pair<>(true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
Move m = TextIO.UCIstringToMove(str);
|
Move m = TextIO.UCIstringToMove(str);
|
||||||
@@ -154,10 +154,10 @@ public class Game {
|
|||||||
m = null;
|
m = null;
|
||||||
}
|
}
|
||||||
if (m == null)
|
if (m == null)
|
||||||
return new Pair<Boolean,Move>(false, null);
|
return new Pair<>(false, null);
|
||||||
|
|
||||||
addToGameTree(m, pendingDrawOffer ? "draw offer" : "");
|
addToGameTree(m, pendingDrawOffer ? "draw offer" : "");
|
||||||
return new Pair<Boolean,Move>(true, m);
|
return new Pair<>(true, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Try claim a draw using a command string. Does not play the move involved
|
/** Try claim a draw using a command string. Does not play the move involved
|
||||||
@@ -169,7 +169,7 @@ public class Game {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void addToGameTree(Move m, String playerAction) {
|
private void addToGameTree(Move m, String playerAction) {
|
||||||
if (m.equals(new Move(0, 0, 0))) { // Don't create more than one game-ending move at a node
|
if (m.equals(new Move(0, 0, 0))) { // Don't create more than one game-ending move at a node
|
||||||
List<Move> varMoves = tree.variations();
|
List<Move> varMoves = tree.variations();
|
||||||
for (int i = varMoves.size() - 1; i >= 0; i--)
|
for (int i = varMoves.size() - 1; i >= 0; i--)
|
||||||
@@ -240,7 +240,7 @@ public class Game {
|
|||||||
return gameEnd;
|
return gameEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void updateTimeControl(boolean discardElapsed) {
|
private void updateTimeControl(boolean discardElapsed) {
|
||||||
Position currPos = currPos();
|
Position currPos = currPos();
|
||||||
int move = currPos.fullMoveCounter;
|
int move = currPos.fullMoveCounter;
|
||||||
boolean wtm = currPos.whiteMove;
|
boolean wtm = currPos.whiteMove;
|
||||||
@@ -454,7 +454,7 @@ public class Game {
|
|||||||
Pair<List<Node>, Integer> ml = tree.getMoveList();
|
Pair<List<Node>, Integer> ml = tree.getMoveList();
|
||||||
List<Node> moveList = ml.first;
|
List<Node> moveList = ml.first;
|
||||||
Position pos = new Position(tree.startPos);
|
Position pos = new Position(tree.startPos);
|
||||||
ArrayList<Move> mList = new ArrayList<Move>();
|
ArrayList<Move> mList = new ArrayList<>();
|
||||||
Position currPos = new Position(pos);
|
Position currPos = new Position(pos);
|
||||||
UndoInfo ui = new UndoInfo();
|
UndoInfo ui = new UndoInfo();
|
||||||
int nMoves = ml.second;
|
int nMoves = ml.second;
|
||||||
@@ -467,10 +467,10 @@ public class Game {
|
|||||||
mList.clear();
|
mList.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new Pair<Position, ArrayList<Move>>(pos, mList);
|
return new Pair<>(pos, mList);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Move handleDrawCmd(String drawCmd, boolean playDrawMove) {
|
private Move handleDrawCmd(String drawCmd, boolean playDrawMove) {
|
||||||
Move ret = null;
|
Move ret = null;
|
||||||
Position pos = tree.currentPos;
|
Position pos = tree.currentPos;
|
||||||
if (drawCmd.startsWith("rep") || drawCmd.startsWith("50")) {
|
if (drawCmd.startsWith("rep") || drawCmd.startsWith("50")) {
|
||||||
|
|||||||
@@ -91,14 +91,14 @@ public class GameTree {
|
|||||||
timeControl = "?";
|
timeControl = "?";
|
||||||
whiteTimeControl = "?";
|
whiteTimeControl = "?";
|
||||||
blackTimeControl = "?";
|
blackTimeControl = "?";
|
||||||
tagPairs = new ArrayList<TagPair>();
|
tagPairs = new ArrayList<>();
|
||||||
rootNode = new Node();
|
rootNode = new Node();
|
||||||
currentNode = rootNode;
|
currentNode = rootNode;
|
||||||
currentPos = new Position(startPos);
|
currentPos = new Position(startPos);
|
||||||
updateListener();
|
updateListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void updateListener() {
|
private void updateListener() {
|
||||||
if (gameStateListener != null)
|
if (gameStateListener != null)
|
||||||
gameStateListener.clear();
|
gameStateListener.clear();
|
||||||
}
|
}
|
||||||
@@ -222,7 +222,7 @@ public class GameTree {
|
|||||||
|
|
||||||
/** Update moveStrLocal in all game nodes. */
|
/** Update moveStrLocal in all game nodes. */
|
||||||
public final void translateMoves() {
|
public final void translateMoves() {
|
||||||
List<Integer> currPath = new ArrayList<Integer>();
|
List<Integer> currPath = new ArrayList<>();
|
||||||
while (currentNode != rootNode) {
|
while (currentNode != rootNode) {
|
||||||
Node child = currentNode;
|
Node child = currentNode;
|
||||||
goBack();
|
goBack();
|
||||||
@@ -234,8 +234,8 @@ public class GameTree {
|
|||||||
goForward(currPath.get(i), false);
|
goForward(currPath.get(i), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void translateMovesHelper() {
|
private void translateMovesHelper() {
|
||||||
ArrayList<Integer> currPath = new ArrayList<Integer>();
|
ArrayList<Integer> currPath = new ArrayList<>();
|
||||||
currPath.add(0);
|
currPath.add(0);
|
||||||
while (!currPath.isEmpty()) {
|
while (!currPath.isEmpty()) {
|
||||||
int last = currPath.size() - 1;
|
int last = currPath.size() - 1;
|
||||||
@@ -325,7 +325,7 @@ public class GameTree {
|
|||||||
out.processToken(null, PgnToken.EOF, null);
|
out.processToken(null, PgnToken.EOF, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void addTagPair(PgnToken.PgnTokenReceiver out, String tagName, String tagValue) {
|
private void addTagPair(PgnToken.PgnTokenReceiver out, String tagName, String tagValue) {
|
||||||
out.processToken(null, PgnToken.LEFT_BRACKET, null);
|
out.processToken(null, PgnToken.LEFT_BRACKET, null);
|
||||||
out.processToken(null, PgnToken.SYMBOL, tagName);
|
out.processToken(null, PgnToken.SYMBOL, tagName);
|
||||||
out.processToken(null, PgnToken.STRING, tagValue);
|
out.processToken(null, PgnToken.STRING, tagValue);
|
||||||
@@ -338,7 +338,7 @@ public class GameTree {
|
|||||||
List<PgnToken> savedTokens;
|
List<PgnToken> savedTokens;
|
||||||
|
|
||||||
PgnScanner(String pgn) {
|
PgnScanner(String pgn) {
|
||||||
savedTokens = new ArrayList<PgnToken>();
|
savedTokens = new ArrayList<>();
|
||||||
// Skip "escape" lines, ie lines starting with a '%' character
|
// Skip "escape" lines, ie lines starting with a '%' character
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
int len = pgn.length();
|
int len = pgn.length();
|
||||||
@@ -489,7 +489,7 @@ public class GameTree {
|
|||||||
PgnToken tok = scanner.nextToken();
|
PgnToken tok = scanner.nextToken();
|
||||||
|
|
||||||
// Parse tag section
|
// Parse tag section
|
||||||
List<TagPair> tagPairs = new ArrayList<TagPair>();
|
List<TagPair> tagPairs = new ArrayList<>();
|
||||||
while (tok.type == PgnToken.LEFT_BRACKET) {
|
while (tok.type == PgnToken.LEFT_BRACKET) {
|
||||||
TagPair tp = new TagPair();
|
TagPair tp = new TagPair();
|
||||||
tok = scanner.nextTokenDropComments();
|
tok = scanner.nextTokenDropComments();
|
||||||
@@ -725,7 +725,7 @@ public class GameTree {
|
|||||||
public final ArrayList<Move> variations() {
|
public final ArrayList<Move> variations() {
|
||||||
if (currentNode.verifyChildren(currentPos))
|
if (currentNode.verifyChildren(currentPos))
|
||||||
updateListener();
|
updateListener();
|
||||||
ArrayList<Move> ret = new ArrayList<Move>();
|
ArrayList<Move> ret = new ArrayList<>();
|
||||||
for (Node child : currentNode.children)
|
for (Node child : currentNode.children)
|
||||||
ret.add(child.move);
|
ret.add(child.move);
|
||||||
return ret;
|
return ret;
|
||||||
@@ -798,7 +798,7 @@ public class GameTree {
|
|||||||
|
|
||||||
/** Get linear game history, using default variations at branch points. */
|
/** Get linear game history, using default variations at branch points. */
|
||||||
public final Pair<List<Node>, Integer> getMoveList() {
|
public final Pair<List<Node>, Integer> getMoveList() {
|
||||||
List<Node> ret = new ArrayList<Node>();
|
List<Node> ret = new ArrayList<>();
|
||||||
Node node = currentNode;
|
Node node = currentNode;
|
||||||
while (node != rootNode) {
|
while (node != rootNode) {
|
||||||
ret.add(node);
|
ret.add(node);
|
||||||
@@ -822,7 +822,7 @@ public class GameTree {
|
|||||||
}
|
}
|
||||||
if (changed)
|
if (changed)
|
||||||
updateListener();
|
updateListener();
|
||||||
return new Pair<List<Node>, Integer>(ret, numMovesPlayed);
|
return new Pair<>(ret, numMovesPlayed);
|
||||||
}
|
}
|
||||||
|
|
||||||
final void setRemainingTime(int remaining) {
|
final void setRemainingTime(int remaining) {
|
||||||
@@ -943,7 +943,7 @@ public class GameTree {
|
|||||||
|
|
||||||
/** Evaluate PGN result string at the end of the main line. */
|
/** Evaluate PGN result string at the end of the main line. */
|
||||||
public final String getPGNResultStringMainLine() {
|
public final String getPGNResultStringMainLine() {
|
||||||
List<Integer> currPath = new ArrayList<Integer>();
|
List<Integer> currPath = new ArrayList<>();
|
||||||
while (currentNode != rootNode) {
|
while (currentNode != rootNode) {
|
||||||
Node child = currentNode;
|
Node child = currentNode;
|
||||||
goBack();
|
goBack();
|
||||||
@@ -1047,7 +1047,7 @@ public class GameTree {
|
|||||||
this.playerAction = "";
|
this.playerAction = "";
|
||||||
this.remainingTime = Integer.MIN_VALUE;
|
this.remainingTime = Integer.MIN_VALUE;
|
||||||
this.parent = null;
|
this.parent = null;
|
||||||
this.children = new ArrayList<Node>();
|
this.children = new ArrayList<>();
|
||||||
this.defaultChild = 0;
|
this.defaultChild = 0;
|
||||||
this.nag = 0;
|
this.nag = 0;
|
||||||
this.preComment = "";
|
this.preComment = "";
|
||||||
@@ -1063,7 +1063,7 @@ public class GameTree {
|
|||||||
this.playerAction = playerAction;
|
this.playerAction = playerAction;
|
||||||
this.remainingTime = remainingTime;
|
this.remainingTime = remainingTime;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.children = new ArrayList<Node>();
|
this.children = new ArrayList<>();
|
||||||
this.defaultChild = 0;
|
this.defaultChild = 0;
|
||||||
this.nag = nag;
|
this.nag = nag;
|
||||||
this.preComment = preComment;
|
this.preComment = preComment;
|
||||||
@@ -1075,10 +1075,10 @@ public class GameTree {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** nodePos must represent the same position as this Node object. */
|
/** nodePos must represent the same position as this Node object. */
|
||||||
private final boolean verifyChildren(Position nodePos) {
|
private boolean verifyChildren(Position nodePos) {
|
||||||
return verifyChildren(nodePos, null);
|
return verifyChildren(nodePos, null);
|
||||||
}
|
}
|
||||||
private final boolean verifyChildren(Position nodePos, ArrayList<Move> moves) {
|
private boolean verifyChildren(Position nodePos, ArrayList<Move> moves) {
|
||||||
boolean anyToRemove = false;
|
boolean anyToRemove = false;
|
||||||
for (Node child : children) {
|
for (Node child : children) {
|
||||||
if (child.move == null) {
|
if (child.move == null) {
|
||||||
@@ -1096,7 +1096,7 @@ public class GameTree {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (anyToRemove) {
|
if (anyToRemove) {
|
||||||
ArrayList<Node> validChildren = new ArrayList<Node>();
|
ArrayList<Node> validChildren = new ArrayList<>();
|
||||||
for (Node child : children)
|
for (Node child : children)
|
||||||
if (child.move != null)
|
if (child.move != null)
|
||||||
validChildren.add(child);
|
validChildren.add(child);
|
||||||
@@ -1106,7 +1106,7 @@ public class GameTree {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final ArrayList<Integer> getPathFromRoot() {
|
final ArrayList<Integer> getPathFromRoot() {
|
||||||
ArrayList<Integer> ret = new ArrayList<Integer>(64);
|
ArrayList<Integer> ret = new ArrayList<>(64);
|
||||||
Node node = this;
|
Node node = this;
|
||||||
while (node.parent != null) {
|
while (node.parent != null) {
|
||||||
ret.add(node.getChildNo());
|
ret.add(node.getChildNo());
|
||||||
@@ -1209,7 +1209,7 @@ public class GameTree {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Export this node in PGN (or display text) format. */
|
/** Export this node in PGN (or display text) format. */
|
||||||
private final boolean addPgnDataOneNode(PgnToken.PgnTokenReceiver out, MoveNumber mn,
|
private boolean addPgnDataOneNode(PgnToken.PgnTokenReceiver out, MoveNumber mn,
|
||||||
boolean needMoveNr, PGNOptions options) {
|
boolean needMoveNr, PGNOptions options) {
|
||||||
if ((preComment.length() > 0) && options.exp.comments) {
|
if ((preComment.length() > 0) && options.exp.comments) {
|
||||||
out.processToken(this, PgnToken.COMMENT, preComment);
|
out.processToken(this, PgnToken.COMMENT, preComment);
|
||||||
@@ -1260,7 +1260,7 @@ public class GameTree {
|
|||||||
return needMoveNr;
|
return needMoveNr;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void addExtendedInfo(PgnToken.PgnTokenReceiver out,
|
private void addExtendedInfo(PgnToken.PgnTokenReceiver out,
|
||||||
String extCmd, String extData) {
|
String extCmd, String extData) {
|
||||||
out.processToken(this, PgnToken.COMMENT, "[%" + extCmd + " " + extData + "]");
|
out.processToken(this, PgnToken.COMMENT, "[%" + extCmd + " " + extData + "]");
|
||||||
}
|
}
|
||||||
@@ -1289,13 +1289,13 @@ public class GameTree {
|
|||||||
return ret.toString();
|
return ret.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Node addChild(Node child) {
|
private Node addChild(Node child) {
|
||||||
child.parent = this;
|
child.parent = this;
|
||||||
children.add(child);
|
children.add(child);
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void parsePgn(PgnScanner scanner, Node node, PGNOptions options) {
|
public static void parsePgn(PgnScanner scanner, Node node, PGNOptions options) {
|
||||||
Node nodeToAdd = new Node();
|
Node nodeToAdd = new Node();
|
||||||
boolean moveAdded = false;
|
boolean moveAdded = false;
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -1424,7 +1424,7 @@ public class GameTree {
|
|||||||
param = comment.substring(start + match.length(), end);
|
param = comment.substring(start + match.length(), end);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new Pair<String, String>(remaining, param);
|
return new Pair<>(remaining, param);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Convert hh:mm:ss to milliseconds */
|
/** Convert hh:mm:ss to milliseconds */
|
||||||
@@ -1518,7 +1518,7 @@ public class GameTree {
|
|||||||
else if (tag.equals("White")) white = val;
|
else if (tag.equals("White")) white = val;
|
||||||
else if (tag.equals("Black")) black = val;
|
else if (tag.equals("Black")) black = val;
|
||||||
else if (tag.equals("Result")) {
|
else if (tag.equals("Result")) {
|
||||||
List<Integer> currPath = new ArrayList<Integer>();
|
List<Integer> currPath = new ArrayList<>();
|
||||||
while (currentNode != rootNode) {
|
while (currentNode != rootNode) {
|
||||||
Node child = currentNode;
|
Node child = currentNode;
|
||||||
goBack();
|
goBack();
|
||||||
@@ -1607,7 +1607,7 @@ public class GameTree {
|
|||||||
private ArrayList<TimeControlField> stringToTCFields(String tcStr) {
|
private ArrayList<TimeControlField> stringToTCFields(String tcStr) {
|
||||||
String[] fields = tcStr.split(":");
|
String[] fields = tcStr.split(":");
|
||||||
int nf = fields.length;
|
int nf = fields.length;
|
||||||
ArrayList<TimeControlField> ret = new ArrayList<TimeControlField>(nf);
|
ArrayList<TimeControlField> ret = new ArrayList<>(nf);
|
||||||
for (int i = 0; i < nf; i++) {
|
for (int i = 0; i < nf; i++) {
|
||||||
String f = fields[i].trim();
|
String f = fields[i].trim();
|
||||||
if (f.equals("?") || f.equals("-") || f.contains("*")) {
|
if (f.equals("?") || f.equals("-") || f.contains("*")) {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public class MoveGen {
|
|||||||
* Pseudo-legal means that the moves don't necessarily defend from check threats.
|
* Pseudo-legal means that the moves don't necessarily defend from check threats.
|
||||||
*/
|
*/
|
||||||
public final ArrayList<Move> pseudoLegalMoves(Position pos) {
|
public final ArrayList<Move> pseudoLegalMoves(Position pos) {
|
||||||
ArrayList<Move> moveList = new ArrayList<Move>(60);
|
ArrayList<Move> moveList = new ArrayList<>(60);
|
||||||
final boolean wtm = pos.whiteMove;
|
final boolean wtm = pos.whiteMove;
|
||||||
for (int x = 0; x < 8; x++) {
|
for (int x = 0; x < 8; x++) {
|
||||||
for (int y = 0; y < 8; y++) {
|
for (int y = 0; y < 8; y++) {
|
||||||
@@ -224,7 +224,7 @@ public class MoveGen {
|
|||||||
* This function removes the moves that don't defend from check threats.
|
* This function removes the moves that don't defend from check threats.
|
||||||
*/
|
*/
|
||||||
public static final ArrayList<Move> removeIllegal(Position pos, ArrayList<Move> moveList) {
|
public static final ArrayList<Move> removeIllegal(Position pos, ArrayList<Move> moveList) {
|
||||||
ArrayList<Move> ret = new ArrayList<Move>();
|
ArrayList<Move> ret = new ArrayList<>();
|
||||||
UndoInfo ui = new UndoInfo();
|
UndoInfo ui = new UndoInfo();
|
||||||
int mlSize = moveList.size();
|
int mlSize = moveList.size();
|
||||||
for (int mi = 0; mi < mlSize; mi++) {
|
for (int mi = 0; mi < mlSize; mi++) {
|
||||||
@@ -244,7 +244,7 @@ public class MoveGen {
|
|||||||
* @param maxSteps Max steps until reaching a border. Set to 1 for non-sliding pieces.
|
* @param maxSteps Max steps until reaching a border. Set to 1 for non-sliding pieces.
|
||||||
* @ return True if the enemy king could be captured, false otherwise.
|
* @ return True if the enemy king could be captured, false otherwise.
|
||||||
*/
|
*/
|
||||||
private final boolean addDirection(ArrayList<Move> moveList, Position pos, int sq0, int maxSteps, int delta) {
|
private boolean addDirection(ArrayList<Move> moveList, Position pos, int sq0, int maxSteps, int delta) {
|
||||||
int sq = sq0;
|
int sq = sq0;
|
||||||
boolean wtm = pos.whiteMove;
|
boolean wtm = pos.whiteMove;
|
||||||
final int oKing = (wtm ? Piece.BKING : Piece.WKING);
|
final int oKing = (wtm ? Piece.BKING : Piece.WKING);
|
||||||
@@ -273,7 +273,7 @@ public class MoveGen {
|
|||||||
/**
|
/**
|
||||||
* Generate all possible pawn moves from (x0,y0) to (x1,y1), taking pawn promotions into account.
|
* Generate all possible pawn moves from (x0,y0) to (x1,y1), taking pawn promotions into account.
|
||||||
*/
|
*/
|
||||||
private final void addPawnMoves(ArrayList<Move> moveList, int sq0, int sq1) {
|
private void addPawnMoves(ArrayList<Move> moveList, int sq0, int sq1) {
|
||||||
if (sq1 >= 56) { // White promotion
|
if (sq1 >= 56) { // White promotion
|
||||||
moveList.add(getMoveObj(sq0, sq1, Piece.WQUEEN));
|
moveList.add(getMoveObj(sq0, sq1, Piece.WQUEEN));
|
||||||
moveList.add(getMoveObj(sq0, sq1, Piece.WKNIGHT));
|
moveList.add(getMoveObj(sq0, sq1, Piece.WKNIGHT));
|
||||||
|
|||||||
@@ -359,7 +359,7 @@ public class Position {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void removeCastleRights(int square) {
|
private void removeCastleRights(int square) {
|
||||||
if (square == Position.getSquare(0, 0)) {
|
if (square == Position.getSquare(0, 0)) {
|
||||||
setCastleMask(castleMask & ~(1 << Position.A1_CASTLE));
|
setCastleMask(castleMask & ~(1 << Position.A1_CASTLE));
|
||||||
} else if (square == Position.getSquare(7, 0)) {
|
} else if (square == Position.getSquare(7, 0)) {
|
||||||
@@ -411,7 +411,7 @@ public class Position {
|
|||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static long getRandomHashVal(int rndNo) {
|
private static long getRandomHashVal(int rndNo) {
|
||||||
try {
|
try {
|
||||||
MessageDigest md = MessageDigest.getInstance("SHA-1");
|
MessageDigest md = MessageDigest.getInstance("SHA-1");
|
||||||
byte[] input = new byte[4];
|
byte[] input = new byte[4];
|
||||||
|
|||||||
@@ -456,7 +456,6 @@ public class TextIO {
|
|||||||
* Decide if move is valid in position pos.
|
* Decide if move is valid in position pos.
|
||||||
* @param pos Position for which to test move.
|
* @param pos Position for which to test move.
|
||||||
* @param move The move to check for validity.
|
* @param move The move to check for validity.
|
||||||
* @param moves If non-null, list of valid moves in position pos.
|
|
||||||
* @return True if move is valid in position pos, false otherwise.
|
* @return True if move is valid in position pos, false otherwise.
|
||||||
*/
|
*/
|
||||||
public static final boolean isValid(Position pos, Move move) {
|
public static final boolean isValid(Position pos, Move move) {
|
||||||
@@ -566,7 +565,7 @@ public class TextIO {
|
|||||||
if (moves == null)
|
if (moves == null)
|
||||||
moves = MoveGen.instance.legalMoves(pos);
|
moves = MoveGen.instance.legalMoves(pos);
|
||||||
|
|
||||||
ArrayList<Move> matches = new ArrayList<Move>(2);
|
ArrayList<Move> matches = new ArrayList<>(2);
|
||||||
for (int i = 0; i < moves.size(); i++) {
|
for (int i = 0; i < moves.size(); i++) {
|
||||||
Move m = moves.get(i);
|
Move m = moves.get(i);
|
||||||
int p = pos.getPiece(m.from);
|
int p = pos.getPiece(m.from);
|
||||||
@@ -755,7 +754,7 @@ public class TextIO {
|
|||||||
return ret.toString();
|
return ret.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static String pieceToChar(int p) {
|
private static String pieceToChar(int p) {
|
||||||
switch (p) {
|
switch (p) {
|
||||||
case Piece.WQUEEN: case Piece.BQUEEN: return "Q";
|
case Piece.WQUEEN: case Piece.BQUEEN: return "Q";
|
||||||
case Piece.WROOK: case Piece.BROOK: return "R";
|
case Piece.WROOK: case Piece.BROOK: return "R";
|
||||||
@@ -777,7 +776,7 @@ public class TextIO {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static int charToPiece(boolean white, char c) {
|
private static int charToPiece(boolean white, char c) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'Q': case 'q': return white ? Piece.WQUEEN : Piece.BQUEEN;
|
case 'Q': case 'q': return white ? Piece.WQUEEN : Piece.BQUEEN;
|
||||||
case 'R': case 'r': return white ? Piece.WROOK : Piece.BROOK;
|
case 'R': case 'r': return white ? Piece.WROOK : Piece.BROOK;
|
||||||
|
|||||||
@@ -171,14 +171,14 @@ public class TimeControl {
|
|||||||
currMove++;
|
currMove++;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (tc.get(tcIdx).movesPerSession <= 0)
|
if (tc.get(tcIdx).movesPerSession <= 0)
|
||||||
return new Pair<Integer,Integer>(tcIdx, 0);
|
return new Pair<>(tcIdx, 0);
|
||||||
nextTC += tc.get(tcIdx).movesPerSession;
|
nextTC += tc.get(tcIdx).movesPerSession;
|
||||||
if (nextTC > currMove)
|
if (nextTC > currMove)
|
||||||
break;
|
break;
|
||||||
if (tcIdx < lastTcIdx)
|
if (tcIdx < lastTcIdx)
|
||||||
tcIdx++;
|
tcIdx++;
|
||||||
}
|
}
|
||||||
return new Pair<Integer,Integer>(tcIdx, nextTC - currMove);
|
return new Pair<>(tcIdx, nextTC - currMove);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** De-serialize from input stream. */
|
/** De-serialize from input stream. */
|
||||||
|
|||||||
@@ -40,17 +40,17 @@ public final class TimeControlData {
|
|||||||
|
|
||||||
/** Constructor. Set a default time control. */
|
/** Constructor. Set a default time control. */
|
||||||
public TimeControlData() {
|
public TimeControlData() {
|
||||||
tcW = new ArrayList<TimeControlField>();
|
tcW = new ArrayList<>();
|
||||||
tcW.add(new TimeControlField(5*60*1000, 60, 0));
|
tcW.add(new TimeControlField(5*60*1000, 60, 0));
|
||||||
tcB = new ArrayList<TimeControlField>();
|
tcB = new ArrayList<>();
|
||||||
tcB.add(new TimeControlField(5*60*1000, 60, 0));
|
tcB.add(new TimeControlField(5*60*1000, 60, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Set a single time control for both white and black. */
|
/** Set a single time control for both white and black. */
|
||||||
public final void setTimeControl(int time, int moves, int inc) {
|
public final void setTimeControl(int time, int moves, int inc) {
|
||||||
tcW = new ArrayList<TimeControlField>();
|
tcW = new ArrayList<>();
|
||||||
tcW.add(new TimeControlField(time, moves, inc));
|
tcW.add(new TimeControlField(time, moves, inc));
|
||||||
tcB = new ArrayList<TimeControlField>();
|
tcB = new ArrayList<>();
|
||||||
tcB.add(new TimeControlField(time, moves, inc));
|
tcB.add(new TimeControlField(time, moves, inc));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ public final class TimeControlData {
|
|||||||
/** De-serialize from input stream. */
|
/** De-serialize from input stream. */
|
||||||
public void readFromStream(DataInputStream dis, int version) throws IOException {
|
public void readFromStream(DataInputStream dis, int version) throws IOException {
|
||||||
for (int c = 0; c < 2; c++) {
|
for (int c = 0; c < 2; c++) {
|
||||||
ArrayList<TimeControlField> tc = new ArrayList<TimeControlField>();
|
ArrayList<TimeControlField> tc = new ArrayList<>();
|
||||||
if (c == 0)
|
if (c == 0)
|
||||||
tcW = tc;
|
tcW = tc;
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class GtbProbe {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String currTbPath = "";
|
private String currTbPath = "";
|
||||||
private ConcurrentLinkedQueue<String> tbPathQueue = new ConcurrentLinkedQueue<String>();
|
private ConcurrentLinkedQueue<String> tbPathQueue = new ConcurrentLinkedQueue<>();
|
||||||
|
|
||||||
GtbProbe() {
|
GtbProbe() {
|
||||||
}
|
}
|
||||||
@@ -106,5 +106,5 @@ class GtbProbe {
|
|||||||
byte[] blackPieces,
|
byte[] blackPieces,
|
||||||
int[] result);
|
int[] result);
|
||||||
|
|
||||||
private final native static boolean init(String tbPath);
|
private native static boolean init(String tbPath);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,10 +73,8 @@ public class Probe {
|
|||||||
/**
|
/**
|
||||||
* Probe GTB tablebases.
|
* Probe GTB tablebases.
|
||||||
* @param pos The position to probe.
|
* @param pos The position to probe.
|
||||||
* @param result Two element array. Set to [tbinfo, plies].
|
|
||||||
* @return True if success.
|
|
||||||
*/
|
*/
|
||||||
private final GtbProbeResult gtbProbe(Position pos) {
|
private GtbProbeResult gtbProbe(Position pos) {
|
||||||
GtbProbeResult ret = gtbProbeRaw(pos);
|
GtbProbeResult ret = gtbProbeRaw(pos);
|
||||||
if (ret.result == GtbProbeResult.DRAW && pos.getEpSquare() != -1) {
|
if (ret.result == GtbProbeResult.DRAW && pos.getEpSquare() != -1) {
|
||||||
ArrayList<Move> moveList = MoveGen.instance.legalMoves(pos);
|
ArrayList<Move> moveList = MoveGen.instance.legalMoves(pos);
|
||||||
@@ -109,7 +107,7 @@ public class Probe {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final GtbProbeResult gtbProbeRaw(Position pos) {
|
private GtbProbeResult gtbProbeRaw(Position pos) {
|
||||||
int castleMask = 0;
|
int castleMask = 0;
|
||||||
if (pos.a1Castle()) castleMask |= GtbProbe.A1_CASTLE;
|
if (pos.a1Castle()) castleMask |= GtbProbe.A1_CASTLE;
|
||||||
if (pos.h1Castle()) castleMask |= GtbProbe.H1_CASTLE;
|
if (pos.h1Castle()) castleMask |= GtbProbe.H1_CASTLE;
|
||||||
@@ -215,7 +213,7 @@ public class Probe {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ProbeResult rtbProbe(Position pos) {
|
private ProbeResult rtbProbe(Position pos) {
|
||||||
if (pos.nPieces() > 7)
|
if (pos.nPieces() > 7)
|
||||||
return new ProbeResult(ProbeResult.Type.NONE, 0, 0);
|
return new ProbeResult(ProbeResult.Type.NONE, 0, 0);
|
||||||
|
|
||||||
@@ -273,8 +271,8 @@ public class Probe {
|
|||||||
/** Return a list of all moves in moveList that are not known to be non-optimal.
|
/** Return a list of all moves in moveList that are not known to be non-optimal.
|
||||||
* Returns null if no legal move could be excluded. */
|
* Returns null if no legal move could be excluded. */
|
||||||
public final ArrayList<Move> removeNonOptimal(Position pos, ArrayList<Move> moveList) {
|
public final ArrayList<Move> removeNonOptimal(Position pos, ArrayList<Move> moveList) {
|
||||||
ArrayList<Move> optimalMoves = new ArrayList<Move>();
|
ArrayList<Move> optimalMoves = new ArrayList<>();
|
||||||
ArrayList<Move> unknownMoves = new ArrayList<Move>();
|
ArrayList<Move> unknownMoves = new ArrayList<>();
|
||||||
final int MATE0 = 100000;
|
final int MATE0 = 100000;
|
||||||
int bestScore = -1000000;
|
int bestScore = -1000000;
|
||||||
UndoInfo ui = new UndoInfo();
|
UndoInfo ui = new UndoInfo();
|
||||||
@@ -323,7 +321,7 @@ public class Probe {
|
|||||||
int p = pos.getPiece(fromSq);
|
int p = pos.getPiece(fromSq);
|
||||||
if ((p == Piece.EMPTY) || (pos.whiteMove != Piece.isWhite(p)))
|
if ((p == Piece.EMPTY) || (pos.whiteMove != Piece.isWhite(p)))
|
||||||
return null;
|
return null;
|
||||||
ArrayList<Pair<Integer,ProbeResult>> ret = new ArrayList<Pair<Integer,ProbeResult>>();
|
ArrayList<Pair<Integer,ProbeResult>> ret = new ArrayList<>();
|
||||||
|
|
||||||
ArrayList<Move> moveList = new MoveGen().legalMoves(pos);
|
ArrayList<Move> moveList = new MoveGen().legalMoves(pos);
|
||||||
UndoInfo ui = new UndoInfo();
|
UndoInfo ui = new UndoInfo();
|
||||||
@@ -342,7 +340,7 @@ public class Probe {
|
|||||||
} else if (res.type != ProbeResult.Type.WDL) {
|
} else if (res.type != ProbeResult.Type.WDL) {
|
||||||
res.score++;
|
res.score++;
|
||||||
}
|
}
|
||||||
ret.add(new Pair<Integer,ProbeResult>(m.to, res));
|
ret.add(new Pair<>(m.to, res));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -355,7 +353,7 @@ public class Probe {
|
|||||||
if (p == Piece.EMPTY)
|
if (p == Piece.EMPTY)
|
||||||
return null;
|
return null;
|
||||||
boolean isPawn = (Piece.makeWhite(p) == Piece.WPAWN);
|
boolean isPawn = (Piece.makeWhite(p) == Piece.WPAWN);
|
||||||
ArrayList<Pair<Integer,ProbeResult>> ret = new ArrayList<Pair<Integer,ProbeResult>>();
|
ArrayList<Pair<Integer,ProbeResult>> ret = new ArrayList<>();
|
||||||
for (int sq = 0; sq < 64; sq++) {
|
for (int sq = 0; sq < 64; sq++) {
|
||||||
if ((sq != fromSq) && (pos.getPiece(sq) != Piece.EMPTY))
|
if ((sq != fromSq) && (pos.getPiece(sq) != Piece.EMPTY))
|
||||||
continue;
|
continue;
|
||||||
@@ -370,7 +368,7 @@ public class Probe {
|
|||||||
continue;
|
continue;
|
||||||
if (!pos.whiteMove)
|
if (!pos.whiteMove)
|
||||||
res.wdl = -res.wdl;
|
res.wdl = -res.wdl;
|
||||||
ret.add(new Pair<Integer,ProbeResult>(sq, res));
|
ret.add(new Pair<>(sq, res));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class RtbProbe {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String currTbPath = "";
|
private String currTbPath = "";
|
||||||
private ConcurrentLinkedQueue<String> tbPathQueue = new ConcurrentLinkedQueue<String>();
|
private ConcurrentLinkedQueue<String> tbPathQueue = new ConcurrentLinkedQueue<>();
|
||||||
|
|
||||||
RtbProbe() {
|
RtbProbe() {
|
||||||
}
|
}
|
||||||
@@ -91,5 +91,5 @@ public class RtbProbe {
|
|||||||
int fullMoveCounter,
|
int fullMoveCounter,
|
||||||
int[] result);
|
int[] result);
|
||||||
|
|
||||||
private final native static boolean init(String tbPath);
|
private native static boolean init(String tbPath);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ public abstract class ChessBoard extends View {
|
|||||||
decorationPaint = new Paint();
|
decorationPaint = new Paint();
|
||||||
decorationPaint.setAntiAlias(true);
|
decorationPaint.setAntiAlias(true);
|
||||||
|
|
||||||
moveMarkPaint = new ArrayList<Paint>();
|
moveMarkPaint = new ArrayList<>();
|
||||||
for (int i = 0; i < ColorTheme.MAX_ARROWS; i++) {
|
for (int i = 0; i < ColorTheme.MAX_ARROWS; i++) {
|
||||||
Paint p = new Paint();
|
Paint p = new Paint();
|
||||||
p.setStyle(Paint.Style.FILL);
|
p.setStyle(Paint.Style.FILL);
|
||||||
@@ -174,7 +174,7 @@ public abstract class ChessBoard extends View {
|
|||||||
now = System.currentTimeMillis();
|
now = System.currentTimeMillis();
|
||||||
return animActive();
|
return animActive();
|
||||||
}
|
}
|
||||||
private final boolean animActive() {
|
private boolean animActive() {
|
||||||
if (paused || (startTime < 0) || (now >= stopTime) || (posHash != pos.zobristHash()))
|
if (paused || (startTime < 0) || (now >= stopTime) || (posHash != pos.zobristHash()))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
@@ -452,7 +452,7 @@ public abstract class ChessBoard extends View {
|
|||||||
// System.out.printf("draw: %d\n", t1-t0);
|
// System.out.printf("draw: %d\n", t1-t0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void drawMoveHints(Canvas canvas) {
|
private void drawMoveHints(Canvas canvas) {
|
||||||
if ((moveHints == null) || blindMode)
|
if ((moveHints == null) || blindMode)
|
||||||
return;
|
return;
|
||||||
float h = (float)(sqSize / 2.0);
|
float h = (float)(sqSize / 2.0);
|
||||||
@@ -550,7 +550,7 @@ public abstract class ChessBoard extends View {
|
|||||||
|
|
||||||
private Rect labelBounds = null;
|
private Rect labelBounds = null;
|
||||||
|
|
||||||
private final void drawLabel(Canvas canvas, int xCrd, int yCrd, boolean right,
|
private void drawLabel(Canvas canvas, int xCrd, int yCrd, boolean right,
|
||||||
boolean bottom, char c) {
|
boolean bottom, char c) {
|
||||||
String s = Character.toString(c);
|
String s = Character.toString(c);
|
||||||
if (labelBounds == null) {
|
if (labelBounds == null) {
|
||||||
@@ -680,7 +680,7 @@ public abstract class ChessBoard extends View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void drawDecorations(Canvas canvas) {
|
private void drawDecorations(Canvas canvas) {
|
||||||
if (decorations == null)
|
if (decorations == null)
|
||||||
return;
|
return;
|
||||||
long decorated = 0;
|
long decorated = 0;
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class FrameLayoutWithHole extends FrameLayout {
|
|||||||
}
|
}
|
||||||
public void addAnimatorSet(AnimatorSet animatorSet){
|
public void addAnimatorSet(AnimatorSet animatorSet){
|
||||||
if (mAnimatorSetArrayList==null){
|
if (mAnimatorSetArrayList==null){
|
||||||
mAnimatorSetArrayList = new ArrayList<AnimatorSet>();
|
mAnimatorSetArrayList = new ArrayList<>();
|
||||||
}
|
}
|
||||||
mAnimatorSetArrayList.add(animatorSet);
|
mAnimatorSetArrayList.add(animatorSet);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,17 +51,17 @@ public class Book {
|
|||||||
this.verbose = verbose;
|
this.verbose = verbose;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void initBook() {
|
private void initBook() {
|
||||||
if (numBookMoves >= 0)
|
if (numBookMoves >= 0)
|
||||||
return;
|
return;
|
||||||
long t0 = System.currentTimeMillis();
|
long t0 = System.currentTimeMillis();
|
||||||
bookMap = new HashMap<Long, List<BookEntry>>();
|
bookMap = new HashMap<>();
|
||||||
rndGen = new SecureRandom();
|
rndGen = new SecureRandom();
|
||||||
rndGen.setSeed(System.currentTimeMillis());
|
rndGen.setSeed(System.currentTimeMillis());
|
||||||
numBookMoves = 0;
|
numBookMoves = 0;
|
||||||
try {
|
try {
|
||||||
InputStream inStream = getClass().getResourceAsStream("/book.bin");
|
InputStream inStream = getClass().getResourceAsStream("/book.bin");
|
||||||
List<Byte> buf = new ArrayList<Byte>(8192);
|
List<Byte> buf = new ArrayList<>(8192);
|
||||||
byte[] tmpBuf = new byte[1024];
|
byte[] tmpBuf = new byte[1024];
|
||||||
while (true) {
|
while (true) {
|
||||||
int len = inStream.read(tmpBuf);
|
int len = inStream.read(tmpBuf);
|
||||||
@@ -104,10 +104,10 @@ public class Book {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Add a move to a position in the opening book. */
|
/** Add a move to a position in the opening book. */
|
||||||
private final void addToBook(Position pos, Move moveToAdd) {
|
private void addToBook(Position pos, Move moveToAdd) {
|
||||||
List<BookEntry> ent = bookMap.get(pos.zobristHash());
|
List<BookEntry> ent = bookMap.get(pos.zobristHash());
|
||||||
if (ent == null) {
|
if (ent == null) {
|
||||||
ent = new ArrayList<BookEntry>();
|
ent = new ArrayList<>();
|
||||||
bookMap.put(pos.zobristHash(), ent);
|
bookMap.put(pos.zobristHash(), ent);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < ent.size(); i++) {
|
for (int i = 0; i < ent.size(); i++) {
|
||||||
@@ -202,7 +202,7 @@ public class Book {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<Byte> createBinBook(String inFileName) {
|
public static List<Byte> createBinBook(String inFileName) {
|
||||||
List<Byte> binBook = new ArrayList<Byte>(0);
|
List<Byte> binBook = new ArrayList<>(0);
|
||||||
try {
|
try {
|
||||||
InputStream inStream = new FileInputStream(inFileName);
|
InputStream inStream = new FileInputStream(inFileName);
|
||||||
InputStreamReader inFile = new InputStreamReader(inStream);
|
InputStreamReader inFile = new InputStreamReader(inStream);
|
||||||
|
|||||||
@@ -295,7 +295,7 @@ public class Evaluate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Compute score based on piece square tables. Positive values are good for white. */
|
/** Compute score based on piece square tables. Positive values are good for white. */
|
||||||
private final int pieceSquareEval(Position pos) {
|
private int pieceSquareEval(Position pos) {
|
||||||
int score = 0;
|
int score = 0;
|
||||||
final int wMtrl = pos.wMtrl;
|
final int wMtrl = pos.wMtrl;
|
||||||
final int bMtrl = pos.bMtrl;
|
final int bMtrl = pos.bMtrl;
|
||||||
@@ -405,7 +405,7 @@ public class Evaluate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Implement the "when ahead trade pieces, when behind trade pawns" rule. */
|
/** Implement the "when ahead trade pieces, when behind trade pawns" rule. */
|
||||||
private final int tradeBonus(Position pos) {
|
private int tradeBonus(Position pos) {
|
||||||
final int wM = pos.wMtrl;
|
final int wM = pos.wMtrl;
|
||||||
final int bM = pos.bMtrl;
|
final int bM = pos.bMtrl;
|
||||||
final int wPawn = pos.wMtrlPawns;
|
final int wPawn = pos.wMtrlPawns;
|
||||||
@@ -436,7 +436,7 @@ public class Evaluate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Score castling ability. */
|
/** Score castling ability. */
|
||||||
private final int castleBonus(Position pos) {
|
private int castleBonus(Position pos) {
|
||||||
if (pos.getCastleMask() == 0) return 0;
|
if (pos.getCastleMask() == 0) return 0;
|
||||||
|
|
||||||
final int k1 = kt1b[7*8+6] - kt1b[7*8+4];
|
final int k1 = kt1b[7*8+6] - kt1b[7*8+4];
|
||||||
@@ -464,7 +464,7 @@ public class Evaluate {
|
|||||||
return wBonus - bBonus;
|
return wBonus - bBonus;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int pawnBonus(Position pos) {
|
private int pawnBonus(Position pos) {
|
||||||
long key = pos.pawnZobristHash();
|
long key = pos.pawnZobristHash();
|
||||||
PawnHashData phd = pawnHash[(int)key & (pawnHash.length - 1)];
|
PawnHashData phd = pawnHash[(int)key & (pawnHash.length - 1)];
|
||||||
if (phd.key != key)
|
if (phd.key != key)
|
||||||
@@ -562,7 +562,7 @@ public class Evaluate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Compute pawn hash data for pos. */
|
/** Compute pawn hash data for pos. */
|
||||||
private final void computePawnHashData(Position pos, PawnHashData ph) {
|
private void computePawnHashData(Position pos, PawnHashData ph) {
|
||||||
int score = 0;
|
int score = 0;
|
||||||
|
|
||||||
// Evaluate double pawns and pawn islands
|
// Evaluate double pawns and pawn islands
|
||||||
@@ -658,7 +658,7 @@ public class Evaluate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Compute rook bonus. Rook on open/half-open file. */
|
/** Compute rook bonus. Rook on open/half-open file. */
|
||||||
private final int rookBonus(Position pos) {
|
private int rookBonus(Position pos) {
|
||||||
int score = 0;
|
int score = 0;
|
||||||
final long wPawns = pos.pieceTypeBB[Piece.WPAWN];
|
final long wPawns = pos.pieceTypeBB[Piece.WPAWN];
|
||||||
final long bPawns = pos.pieceTypeBB[Piece.BPAWN];
|
final long bPawns = pos.pieceTypeBB[Piece.BPAWN];
|
||||||
@@ -703,7 +703,7 @@ public class Evaluate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Compute bishop evaluation. */
|
/** Compute bishop evaluation. */
|
||||||
private final int bishopEval(Position pos, int oldScore) {
|
private int bishopEval(Position pos, int oldScore) {
|
||||||
int score = 0;
|
int score = 0;
|
||||||
final long occupied = pos.whiteBB | pos.blackBB;
|
final long occupied = pos.whiteBB | pos.blackBB;
|
||||||
long wBishops = pos.pieceTypeBB[Piece.WBISHOP];
|
long wBishops = pos.pieceTypeBB[Piece.WBISHOP];
|
||||||
@@ -828,7 +828,7 @@ public class Evaluate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Compute king safety for both kings. */
|
/** Compute king safety for both kings. */
|
||||||
private final int kingSafety(Position pos) {
|
private int kingSafety(Position pos) {
|
||||||
final int minM = rV + bV;
|
final int minM = rV + bV;
|
||||||
final int m = (pos.wMtrl - pos.wMtrlPawns + pos.bMtrl - pos.bMtrlPawns) / 2;
|
final int m = (pos.wMtrl - pos.wMtrlPawns + pos.bMtrl - pos.bMtrlPawns) / 2;
|
||||||
if (m <= minM)
|
if (m <= minM)
|
||||||
@@ -884,7 +884,7 @@ public class Evaluate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int kingSafetyKPPart(Position pos) {
|
private int kingSafetyKPPart(Position pos) {
|
||||||
final long key = pos.pawnZobristHash() ^ pos.kingZobristHash();
|
final long key = pos.pawnZobristHash() ^ pos.kingZobristHash();
|
||||||
KingSafetyHashData ksh = kingSafetyHash[(int)key & (kingSafetyHash.length - 1)];
|
KingSafetyHashData ksh = kingSafetyHash[(int)key & (kingSafetyHash.length - 1)];
|
||||||
if (ksh.key != key) {
|
if (ksh.key != key) {
|
||||||
@@ -958,7 +958,7 @@ public class Evaluate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Implements special knowledge for some endgame situations. */
|
/** Implements special knowledge for some endgame situations. */
|
||||||
private final int endGameEval(Position pos, int oldScore) {
|
private int endGameEval(Position pos, int oldScore) {
|
||||||
int score = oldScore;
|
int score = oldScore;
|
||||||
if (pos.wMtrl + pos.bMtrl > 6 * rV)
|
if (pos.wMtrl + pos.bMtrl > 6 * rV)
|
||||||
return score;
|
return score;
|
||||||
|
|||||||
@@ -366,7 +366,7 @@ public final class MoveGen {
|
|||||||
{
|
{
|
||||||
ArrayList<Move> allMoves = pseudoLegalMoves(pos);
|
ArrayList<Move> allMoves = pseudoLegalMoves(pos);
|
||||||
allMoves = MoveGen.removeIllegal(pos, allMoves);
|
allMoves = MoveGen.removeIllegal(pos, allMoves);
|
||||||
HashSet<String> evMoves = new HashSet<String>();
|
HashSet<String> evMoves = new HashSet<>();
|
||||||
for (Move m : moveList)
|
for (Move m : moveList)
|
||||||
evMoves.add(TextIO.moveToUCIString(m));
|
evMoves.add(TextIO.moveToUCIString(m));
|
||||||
for (Move m : allMoves)
|
for (Move m : allMoves)
|
||||||
@@ -967,7 +967,7 @@ public final class MoveGen {
|
|||||||
moveList.size = length;
|
moveList.size = length;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static boolean addPawnMovesByMask(MoveList moveList, Position pos, long mask,
|
private static boolean addPawnMovesByMask(MoveList moveList, Position pos, long mask,
|
||||||
int delta, boolean allPromotions) {
|
int delta, boolean allPromotions) {
|
||||||
if (mask == 0)
|
if (mask == 0)
|
||||||
return false;
|
return false;
|
||||||
@@ -1008,7 +1008,7 @@ public final class MoveGen {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static void addPawnDoubleMovesByMask(MoveList moveList, Position pos,
|
private static void addPawnDoubleMovesByMask(MoveList moveList, Position pos,
|
||||||
long mask, int delta) {
|
long mask, int delta) {
|
||||||
while (mask != 0) {
|
while (mask != 0) {
|
||||||
int sq = BitBoard.numberOfTrailingZeros(mask);
|
int sq = BitBoard.numberOfTrailingZeros(mask);
|
||||||
@@ -1017,7 +1017,7 @@ public final class MoveGen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static boolean addMovesByMask(MoveList moveList, Position pos, int sq0, long mask) {
|
private static boolean addMovesByMask(MoveList moveList, Position pos, int sq0, long mask) {
|
||||||
long oKingMask = pos.pieceTypeBB[pos.whiteMove ? Piece.BKING : Piece.WKING];
|
long oKingMask = pos.pieceTypeBB[pos.whiteMove ? Piece.BKING : Piece.WKING];
|
||||||
if ((mask & oKingMask) != 0) {
|
if ((mask & oKingMask) != 0) {
|
||||||
int sq = BitBoard.numberOfTrailingZeros(mask & oKingMask);
|
int sq = BitBoard.numberOfTrailingZeros(mask & oKingMask);
|
||||||
@@ -1033,7 +1033,7 @@ public final class MoveGen {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static void setMove(MoveList moveList, int from, int to, int promoteTo) {
|
private static void setMove(MoveList moveList, int from, int to, int promoteTo) {
|
||||||
Move m = moveList.m[moveList.size++];
|
Move m = moveList.m[moveList.size++];
|
||||||
m.from = from;
|
m.from = from;
|
||||||
m.to = to;
|
m.to = to;
|
||||||
@@ -1047,7 +1047,7 @@ public final class MoveGen {
|
|||||||
|
|
||||||
private static final int MAX_MOVES = 256;
|
private static final int MAX_MOVES = 256;
|
||||||
|
|
||||||
private final MoveList getMoveListObj() {
|
private MoveList getMoveListObj() {
|
||||||
MoveList ml;
|
MoveList ml;
|
||||||
if (moveListsInCache > 0) {
|
if (moveListsInCache > 0) {
|
||||||
ml = (MoveList)moveListCache[--moveListsInCache];
|
ml = (MoveList)moveListCache[--moveListsInCache];
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public class Parameters {
|
|||||||
return inst;
|
return inst;
|
||||||
}
|
}
|
||||||
public final String[] getParamNames() {
|
public final String[] getParamNames() {
|
||||||
ArrayList<String> parNames = new ArrayList<String>();
|
ArrayList<String> parNames = new ArrayList<>();
|
||||||
for (Map.Entry<String, ParamBase> e : params.entrySet())
|
for (Map.Entry<String, ParamBase> e : params.entrySet())
|
||||||
if (e.getValue().visible)
|
if (e.getValue().visible)
|
||||||
parNames.add(e.getKey());
|
parNames.add(e.getKey());
|
||||||
@@ -97,7 +97,7 @@ public class Parameters {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static final Parameters inst = new Parameters();
|
private static final Parameters inst = new Parameters();
|
||||||
private Map<String, ParamBase> params = new TreeMap<String, ParamBase>();
|
private Map<String, ParamBase> params = new TreeMap<>();
|
||||||
|
|
||||||
private Parameters() {
|
private Parameters() {
|
||||||
addPar(new SpinParam("qV", false, -200, 200, 0));
|
addPar(new SpinParam("qV", false, -200, 200, 0));
|
||||||
@@ -107,7 +107,7 @@ public class Parameters {
|
|||||||
addPar(new SpinParam("pV", false, -200, 200, 0));
|
addPar(new SpinParam("pV", false, -200, 200, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void addPar(ParamBase p) {
|
private void addPar(ParamBase p) {
|
||||||
params.put(p.name.toLowerCase(), p);
|
params.put(p.name.toLowerCase(), p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ public class Position {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Move a non-pawn piece to an empty square. */
|
/** Move a non-pawn piece to an empty square. */
|
||||||
private final void movePieceNotPawn(int from, int to) {
|
private void movePieceNotPawn(int from, int to) {
|
||||||
final int piece = squares[from];
|
final int piece = squares[from];
|
||||||
hashKey ^= psHashKeys[piece][from];
|
hashKey ^= psHashKeys[piece][from];
|
||||||
hashKey ^= psHashKeys[piece][to];
|
hashKey ^= psHashKeys[piece][to];
|
||||||
@@ -562,7 +562,7 @@ public class Position {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void removeCastleRights(int square) {
|
private void removeCastleRights(int square) {
|
||||||
if (square == Position.getSquare(0, 0)) {
|
if (square == Position.getSquare(0, 0)) {
|
||||||
setCastleMask(castleMask & ~(1 << Position.A1_CASTLE));
|
setCastleMask(castleMask & ~(1 << Position.A1_CASTLE));
|
||||||
} else if (square == Position.getSquare(7, 0)) {
|
} else if (square == Position.getSquare(7, 0)) {
|
||||||
@@ -620,7 +620,7 @@ public class Position {
|
|||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static long getRandomHashVal(int rndNo) {
|
private static long getRandomHashVal(int rndNo) {
|
||||||
try {
|
try {
|
||||||
MessageDigest md = MessageDigest.getInstance("SHA-1");
|
MessageDigest md = MessageDigest.getInstance("SHA-1");
|
||||||
byte[] input = new byte[4];
|
byte[] input = new byte[4];
|
||||||
|
|||||||
@@ -597,7 +597,7 @@ public class TextIO {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static String pieceToChar(int p) {
|
private static String pieceToChar(int p) {
|
||||||
switch (p) {
|
switch (p) {
|
||||||
case Piece.WQUEEN: case Piece.BQUEEN: return "Q";
|
case Piece.WQUEEN: case Piece.BQUEEN: return "Q";
|
||||||
case Piece.WROOK: case Piece.BROOK: return "R";
|
case Piece.WROOK: case Piece.BROOK: return "R";
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import java.util.ArrayList;
|
|||||||
public class FileUtil {
|
public class FileUtil {
|
||||||
/** Read a text file. Return string array with one string per line. */
|
/** Read a text file. Return string array with one string per line. */
|
||||||
public static String[] readFile(String filename) throws IOException {
|
public static String[] readFile(String filename) throws IOException {
|
||||||
ArrayList<String> ret = new ArrayList<String>();
|
ArrayList<String> ret = new ArrayList<>();
|
||||||
InputStream inStream = new FileInputStream(filename);
|
InputStream inStream = new FileInputStream(filename);
|
||||||
InputStreamReader inFile = new InputStreamReader(inStream, "UTF-8");
|
InputStreamReader inFile = new InputStreamReader(inStream, "UTF-8");
|
||||||
BufferedReader inBuf = new BufferedReader(inFile);
|
BufferedReader inBuf = new BufferedReader(inFile);
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public class EcoBuilder {
|
|||||||
int ecoIdx; // Index in string array, or -1
|
int ecoIdx; // Index in string array, or -1
|
||||||
int opnIdx; // Index in string array, or -1
|
int opnIdx; // Index in string array, or -1
|
||||||
int varIdx; // Index in string array, or -1
|
int varIdx; // Index in string array, or -1
|
||||||
ArrayList<Node> children = new ArrayList<Node>();
|
ArrayList<Node> children = new ArrayList<>();
|
||||||
Node parent;
|
Node parent;
|
||||||
}
|
}
|
||||||
private ArrayList<Node> nodes;
|
private ArrayList<Node> nodes;
|
||||||
@@ -57,9 +57,9 @@ public class EcoBuilder {
|
|||||||
|
|
||||||
/** Constructor. */
|
/** Constructor. */
|
||||||
private EcoBuilder() {
|
private EcoBuilder() {
|
||||||
nodes = new ArrayList<Node>();
|
nodes = new ArrayList<>();
|
||||||
strs = new ArrayList<String>();
|
strs = new ArrayList<>();
|
||||||
strToIndex = new HashMap<String, Integer>();
|
strToIndex = new HashMap<>();
|
||||||
Node rootNode = new Node();
|
Node rootNode = new Node();
|
||||||
rootNode.index = 0;
|
rootNode.index = 0;
|
||||||
rootNode.move = new Move(0, 0, 0);
|
rootNode.move = new Move(0, 0, 0);
|
||||||
@@ -99,7 +99,7 @@ public class EcoBuilder {
|
|||||||
game.readPGN(pgn, options);
|
game.readPGN(pgn, options);
|
||||||
|
|
||||||
// Determine name of opening
|
// Determine name of opening
|
||||||
HashMap<String,String> headers = new HashMap<String,String>();
|
HashMap<String,String> headers = new HashMap<>();
|
||||||
GameTree tree = game.tree;
|
GameTree tree = game.tree;
|
||||||
tree.getHeaders(headers);
|
tree.getHeaders(headers);
|
||||||
int ecoIdx = addData(headers, "ECO");
|
int ecoIdx = addData(headers, "ECO");
|
||||||
|
|||||||
@@ -134,14 +134,14 @@ public class Game {
|
|||||||
* Second item is move played, or null if no move was played. */
|
* Second item is move played, or null if no move was played. */
|
||||||
public final Pair<Boolean, Move> processString(String str) {
|
public final Pair<Boolean, Move> processString(String str) {
|
||||||
if (getGameState() != GameState.ALIVE)
|
if (getGameState() != GameState.ALIVE)
|
||||||
return new Pair<Boolean,Move>(false, null);
|
return new Pair<>(false, null);
|
||||||
if (str.startsWith("draw ")) {
|
if (str.startsWith("draw ")) {
|
||||||
String drawCmd = str.substring(str.indexOf(" ") + 1);
|
String drawCmd = str.substring(str.indexOf(" ") + 1);
|
||||||
Move m = handleDrawCmd(drawCmd, true);
|
Move m = handleDrawCmd(drawCmd, true);
|
||||||
return new Pair<Boolean,Move>(true, m);
|
return new Pair<>(true, m);
|
||||||
} else if (str.equals("resign")) {
|
} else if (str.equals("resign")) {
|
||||||
addToGameTree(new Move(0, 0, 0), "resign");
|
addToGameTree(new Move(0, 0, 0), "resign");
|
||||||
return new Pair<Boolean,Move>(true, null);
|
return new Pair<>(true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
Move m = TextIO.UCIstringToMove(str);
|
Move m = TextIO.UCIstringToMove(str);
|
||||||
@@ -154,10 +154,10 @@ public class Game {
|
|||||||
m = null;
|
m = null;
|
||||||
}
|
}
|
||||||
if (m == null)
|
if (m == null)
|
||||||
return new Pair<Boolean,Move>(false, null);
|
return new Pair<>(false, null);
|
||||||
|
|
||||||
addToGameTree(m, pendingDrawOffer ? "draw offer" : "");
|
addToGameTree(m, pendingDrawOffer ? "draw offer" : "");
|
||||||
return new Pair<Boolean,Move>(true, m);
|
return new Pair<>(true, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Try claim a draw using a command string. Does not play the move involved
|
/** Try claim a draw using a command string. Does not play the move involved
|
||||||
@@ -169,7 +169,7 @@ public class Game {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void addToGameTree(Move m, String playerAction) {
|
private void addToGameTree(Move m, String playerAction) {
|
||||||
if (m.equals(new Move(0, 0, 0))) { // Don't create more than one game-ending move at a node
|
if (m.equals(new Move(0, 0, 0))) { // Don't create more than one game-ending move at a node
|
||||||
List<Move> varMoves = tree.variations();
|
List<Move> varMoves = tree.variations();
|
||||||
for (int i = varMoves.size() - 1; i >= 0; i--)
|
for (int i = varMoves.size() - 1; i >= 0; i--)
|
||||||
@@ -240,7 +240,7 @@ public class Game {
|
|||||||
return gameEnd;
|
return gameEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void updateTimeControl(boolean discardElapsed) {
|
private void updateTimeControl(boolean discardElapsed) {
|
||||||
Position currPos = currPos();
|
Position currPos = currPos();
|
||||||
int move = currPos.fullMoveCounter;
|
int move = currPos.fullMoveCounter;
|
||||||
boolean wtm = currPos.whiteMove;
|
boolean wtm = currPos.whiteMove;
|
||||||
@@ -454,7 +454,7 @@ public class Game {
|
|||||||
Pair<List<Node>, Integer> ml = tree.getMoveList();
|
Pair<List<Node>, Integer> ml = tree.getMoveList();
|
||||||
List<Node> moveList = ml.first;
|
List<Node> moveList = ml.first;
|
||||||
Position pos = new Position(tree.startPos);
|
Position pos = new Position(tree.startPos);
|
||||||
ArrayList<Move> mList = new ArrayList<Move>();
|
ArrayList<Move> mList = new ArrayList<>();
|
||||||
Position currPos = new Position(pos);
|
Position currPos = new Position(pos);
|
||||||
UndoInfo ui = new UndoInfo();
|
UndoInfo ui = new UndoInfo();
|
||||||
int nMoves = ml.second;
|
int nMoves = ml.second;
|
||||||
@@ -467,10 +467,10 @@ public class Game {
|
|||||||
mList.clear();
|
mList.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new Pair<Position, ArrayList<Move>>(pos, mList);
|
return new Pair<>(pos, mList);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Move handleDrawCmd(String drawCmd, boolean playDrawMove) {
|
private Move handleDrawCmd(String drawCmd, boolean playDrawMove) {
|
||||||
Move ret = null;
|
Move ret = null;
|
||||||
Position pos = tree.currentPos;
|
Position pos = tree.currentPos;
|
||||||
if (drawCmd.startsWith("rep") || drawCmd.startsWith("50")) {
|
if (drawCmd.startsWith("rep") || drawCmd.startsWith("50")) {
|
||||||
|
|||||||
@@ -90,14 +90,14 @@ public class GameTree {
|
|||||||
timeControl = "?";
|
timeControl = "?";
|
||||||
whiteTimeControl = "?";
|
whiteTimeControl = "?";
|
||||||
blackTimeControl = "?";
|
blackTimeControl = "?";
|
||||||
tagPairs = new ArrayList<TagPair>();
|
tagPairs = new ArrayList<>();
|
||||||
rootNode = new Node();
|
rootNode = new Node();
|
||||||
currentNode = rootNode;
|
currentNode = rootNode;
|
||||||
currentPos = new Position(startPos);
|
currentPos = new Position(startPos);
|
||||||
updateListener();
|
updateListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void updateListener() {
|
private void updateListener() {
|
||||||
if (gameStateListener != null)
|
if (gameStateListener != null)
|
||||||
gameStateListener.clear();
|
gameStateListener.clear();
|
||||||
}
|
}
|
||||||
@@ -221,7 +221,7 @@ public class GameTree {
|
|||||||
|
|
||||||
/** Update moveStrLocal in all game nodes. */
|
/** Update moveStrLocal in all game nodes. */
|
||||||
public final void translateMoves() {
|
public final void translateMoves() {
|
||||||
List<Integer> currPath = new ArrayList<Integer>();
|
List<Integer> currPath = new ArrayList<>();
|
||||||
while (currentNode != rootNode) {
|
while (currentNode != rootNode) {
|
||||||
Node child = currentNode;
|
Node child = currentNode;
|
||||||
goBack();
|
goBack();
|
||||||
@@ -233,8 +233,8 @@ public class GameTree {
|
|||||||
goForward(currPath.get(i), false);
|
goForward(currPath.get(i), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void translateMovesHelper() {
|
private void translateMovesHelper() {
|
||||||
ArrayList<Integer> currPath = new ArrayList<Integer>();
|
ArrayList<Integer> currPath = new ArrayList<>();
|
||||||
currPath.add(0);
|
currPath.add(0);
|
||||||
while (!currPath.isEmpty()) {
|
while (!currPath.isEmpty()) {
|
||||||
int last = currPath.size() - 1;
|
int last = currPath.size() - 1;
|
||||||
@@ -309,7 +309,7 @@ public class GameTree {
|
|||||||
out.processToken(null, PgnToken.EOF, null);
|
out.processToken(null, PgnToken.EOF, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void addTagPair(PgnToken.PgnTokenReceiver out, String tagName, String tagValue) {
|
private void addTagPair(PgnToken.PgnTokenReceiver out, String tagName, String tagValue) {
|
||||||
out.processToken(null, PgnToken.LEFT_BRACKET, null);
|
out.processToken(null, PgnToken.LEFT_BRACKET, null);
|
||||||
out.processToken(null, PgnToken.SYMBOL, tagName);
|
out.processToken(null, PgnToken.SYMBOL, tagName);
|
||||||
out.processToken(null, PgnToken.STRING, tagValue);
|
out.processToken(null, PgnToken.STRING, tagValue);
|
||||||
@@ -322,7 +322,7 @@ public class GameTree {
|
|||||||
List<PgnToken> savedTokens;
|
List<PgnToken> savedTokens;
|
||||||
|
|
||||||
PgnScanner(String pgn) {
|
PgnScanner(String pgn) {
|
||||||
savedTokens = new ArrayList<PgnToken>();
|
savedTokens = new ArrayList<>();
|
||||||
// Skip "escape" lines, ie lines starting with a '%' character
|
// Skip "escape" lines, ie lines starting with a '%' character
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
int len = pgn.length();
|
int len = pgn.length();
|
||||||
@@ -473,7 +473,7 @@ public class GameTree {
|
|||||||
PgnToken tok = scanner.nextToken();
|
PgnToken tok = scanner.nextToken();
|
||||||
|
|
||||||
// Parse tag section
|
// Parse tag section
|
||||||
List<TagPair> tagPairs = new ArrayList<TagPair>();
|
List<TagPair> tagPairs = new ArrayList<>();
|
||||||
while (tok.type == PgnToken.LEFT_BRACKET) {
|
while (tok.type == PgnToken.LEFT_BRACKET) {
|
||||||
TagPair tp = new TagPair();
|
TagPair tp = new TagPair();
|
||||||
tok = scanner.nextTokenDropComments();
|
tok = scanner.nextTokenDropComments();
|
||||||
@@ -709,7 +709,7 @@ public class GameTree {
|
|||||||
public final ArrayList<Move> variations() {
|
public final ArrayList<Move> variations() {
|
||||||
if (currentNode.verifyChildren(currentPos))
|
if (currentNode.verifyChildren(currentPos))
|
||||||
updateListener();
|
updateListener();
|
||||||
ArrayList<Move> ret = new ArrayList<Move>();
|
ArrayList<Move> ret = new ArrayList<>();
|
||||||
for (Node child : currentNode.children)
|
for (Node child : currentNode.children)
|
||||||
ret.add(child.move);
|
ret.add(child.move);
|
||||||
return ret;
|
return ret;
|
||||||
@@ -782,7 +782,7 @@ public class GameTree {
|
|||||||
|
|
||||||
/** Get linear game history, using default variations at branch points. */
|
/** Get linear game history, using default variations at branch points. */
|
||||||
public final Pair<List<Node>, Integer> getMoveList() {
|
public final Pair<List<Node>, Integer> getMoveList() {
|
||||||
List<Node> ret = new ArrayList<Node>();
|
List<Node> ret = new ArrayList<>();
|
||||||
Node node = currentNode;
|
Node node = currentNode;
|
||||||
while (node != rootNode) {
|
while (node != rootNode) {
|
||||||
ret.add(node);
|
ret.add(node);
|
||||||
@@ -806,7 +806,7 @@ public class GameTree {
|
|||||||
}
|
}
|
||||||
if (changed)
|
if (changed)
|
||||||
updateListener();
|
updateListener();
|
||||||
return new Pair<List<Node>, Integer>(ret, numMovesPlayed);
|
return new Pair<>(ret, numMovesPlayed);
|
||||||
}
|
}
|
||||||
|
|
||||||
final void setRemainingTime(int remaining) {
|
final void setRemainingTime(int remaining) {
|
||||||
@@ -927,7 +927,7 @@ public class GameTree {
|
|||||||
|
|
||||||
/** Evaluate PGN result string at the end of the main line. */
|
/** Evaluate PGN result string at the end of the main line. */
|
||||||
public final String getPGNResultStringMainLine() {
|
public final String getPGNResultStringMainLine() {
|
||||||
List<Integer> currPath = new ArrayList<Integer>();
|
List<Integer> currPath = new ArrayList<>();
|
||||||
while (currentNode != rootNode) {
|
while (currentNode != rootNode) {
|
||||||
Node child = currentNode;
|
Node child = currentNode;
|
||||||
goBack();
|
goBack();
|
||||||
@@ -1031,7 +1031,7 @@ public class GameTree {
|
|||||||
this.playerAction = "";
|
this.playerAction = "";
|
||||||
this.remainingTime = Integer.MIN_VALUE;
|
this.remainingTime = Integer.MIN_VALUE;
|
||||||
this.parent = null;
|
this.parent = null;
|
||||||
this.children = new ArrayList<Node>();
|
this.children = new ArrayList<>();
|
||||||
this.defaultChild = 0;
|
this.defaultChild = 0;
|
||||||
this.nag = 0;
|
this.nag = 0;
|
||||||
this.preComment = "";
|
this.preComment = "";
|
||||||
@@ -1047,7 +1047,7 @@ public class GameTree {
|
|||||||
this.playerAction = playerAction;
|
this.playerAction = playerAction;
|
||||||
this.remainingTime = remainingTime;
|
this.remainingTime = remainingTime;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.children = new ArrayList<Node>();
|
this.children = new ArrayList<>();
|
||||||
this.defaultChild = 0;
|
this.defaultChild = 0;
|
||||||
this.nag = nag;
|
this.nag = nag;
|
||||||
this.preComment = preComment;
|
this.preComment = preComment;
|
||||||
@@ -1059,10 +1059,10 @@ public class GameTree {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** nodePos must represent the same position as this Node object. */
|
/** nodePos must represent the same position as this Node object. */
|
||||||
private final boolean verifyChildren(Position nodePos) {
|
private boolean verifyChildren(Position nodePos) {
|
||||||
return verifyChildren(nodePos, null);
|
return verifyChildren(nodePos, null);
|
||||||
}
|
}
|
||||||
private final boolean verifyChildren(Position nodePos, ArrayList<Move> moves) {
|
private boolean verifyChildren(Position nodePos, ArrayList<Move> moves) {
|
||||||
boolean anyToRemove = false;
|
boolean anyToRemove = false;
|
||||||
for (Node child : children) {
|
for (Node child : children) {
|
||||||
if (child.move == null) {
|
if (child.move == null) {
|
||||||
@@ -1080,7 +1080,7 @@ public class GameTree {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (anyToRemove) {
|
if (anyToRemove) {
|
||||||
ArrayList<Node> validChildren = new ArrayList<Node>();
|
ArrayList<Node> validChildren = new ArrayList<>();
|
||||||
for (Node child : children)
|
for (Node child : children)
|
||||||
if (child.move != null)
|
if (child.move != null)
|
||||||
validChildren.add(child);
|
validChildren.add(child);
|
||||||
@@ -1090,7 +1090,7 @@ public class GameTree {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final ArrayList<Integer> getPathFromRoot() {
|
final ArrayList<Integer> getPathFromRoot() {
|
||||||
ArrayList<Integer> ret = new ArrayList<Integer>(64);
|
ArrayList<Integer> ret = new ArrayList<>(64);
|
||||||
Node node = this;
|
Node node = this;
|
||||||
while (node.parent != null) {
|
while (node.parent != null) {
|
||||||
ret.add(node.getChildNo());
|
ret.add(node.getChildNo());
|
||||||
@@ -1193,7 +1193,7 @@ public class GameTree {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Export this node in PGN (or display text) format. */
|
/** Export this node in PGN (or display text) format. */
|
||||||
private final boolean addPgnDataOneNode(PgnToken.PgnTokenReceiver out, MoveNumber mn,
|
private boolean addPgnDataOneNode(PgnToken.PgnTokenReceiver out, MoveNumber mn,
|
||||||
boolean needMoveNr, PGNOptions options) {
|
boolean needMoveNr, PGNOptions options) {
|
||||||
if ((preComment.length() > 0) && options.exp.comments) {
|
if ((preComment.length() > 0) && options.exp.comments) {
|
||||||
out.processToken(this, PgnToken.COMMENT, preComment);
|
out.processToken(this, PgnToken.COMMENT, preComment);
|
||||||
@@ -1244,7 +1244,7 @@ public class GameTree {
|
|||||||
return needMoveNr;
|
return needMoveNr;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void addExtendedInfo(PgnToken.PgnTokenReceiver out,
|
private void addExtendedInfo(PgnToken.PgnTokenReceiver out,
|
||||||
String extCmd, String extData) {
|
String extCmd, String extData) {
|
||||||
out.processToken(this, PgnToken.COMMENT, "[%" + extCmd + " " + extData + "]");
|
out.processToken(this, PgnToken.COMMENT, "[%" + extCmd + " " + extData + "]");
|
||||||
}
|
}
|
||||||
@@ -1273,7 +1273,7 @@ public class GameTree {
|
|||||||
return ret.toString();
|
return ret.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Node addChild(Node child) {
|
private Node addChild(Node child) {
|
||||||
child.parent = this;
|
child.parent = this;
|
||||||
children.add(child);
|
children.add(child);
|
||||||
return child;
|
return child;
|
||||||
@@ -1408,7 +1408,7 @@ public class GameTree {
|
|||||||
param = comment.substring(start + match.length(), end);
|
param = comment.substring(start + match.length(), end);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new Pair<String, String>(remaining, param);
|
return new Pair<>(remaining, param);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Convert hh:mm:ss to milliseconds */
|
/** Convert hh:mm:ss to milliseconds */
|
||||||
@@ -1502,7 +1502,7 @@ public class GameTree {
|
|||||||
else if (tag.equals("White")) white = val;
|
else if (tag.equals("White")) white = val;
|
||||||
else if (tag.equals("Black")) black = val;
|
else if (tag.equals("Black")) black = val;
|
||||||
else if (tag.equals("Result")) {
|
else if (tag.equals("Result")) {
|
||||||
List<Integer> currPath = new ArrayList<Integer>();
|
List<Integer> currPath = new ArrayList<>();
|
||||||
while (currentNode != rootNode) {
|
while (currentNode != rootNode) {
|
||||||
Node child = currentNode;
|
Node child = currentNode;
|
||||||
goBack();
|
goBack();
|
||||||
@@ -1591,7 +1591,7 @@ public class GameTree {
|
|||||||
private ArrayList<TimeControlField> stringToTCFields(String tcStr) {
|
private ArrayList<TimeControlField> stringToTCFields(String tcStr) {
|
||||||
String[] fields = tcStr.split(":");
|
String[] fields = tcStr.split(":");
|
||||||
int nf = fields.length;
|
int nf = fields.length;
|
||||||
ArrayList<TimeControlField> ret = new ArrayList<TimeControlField>(nf);
|
ArrayList<TimeControlField> ret = new ArrayList<>(nf);
|
||||||
for (int i = 0; i < nf; i++) {
|
for (int i = 0; i < nf; i++) {
|
||||||
String f = fields[i].trim();
|
String f = fields[i].trim();
|
||||||
if (f.equals("?") || f.equals("-") || f.contains("*")) {
|
if (f.equals("?") || f.equals("-") || f.contains("*")) {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public class MoveGen {
|
|||||||
* Pseudo-legal means that the moves don't necessarily defend from check threats.
|
* Pseudo-legal means that the moves don't necessarily defend from check threats.
|
||||||
*/
|
*/
|
||||||
public final ArrayList<Move> pseudoLegalMoves(Position pos) {
|
public final ArrayList<Move> pseudoLegalMoves(Position pos) {
|
||||||
ArrayList<Move> moveList = new ArrayList<Move>(60);
|
ArrayList<Move> moveList = new ArrayList<>(60);
|
||||||
final boolean wtm = pos.whiteMove;
|
final boolean wtm = pos.whiteMove;
|
||||||
for (int x = 0; x < 8; x++) {
|
for (int x = 0; x < 8; x++) {
|
||||||
for (int y = 0; y < 8; y++) {
|
for (int y = 0; y < 8; y++) {
|
||||||
@@ -224,7 +224,7 @@ public class MoveGen {
|
|||||||
* This function removes the moves that don't defend from check threats.
|
* This function removes the moves that don't defend from check threats.
|
||||||
*/
|
*/
|
||||||
public static final ArrayList<Move> removeIllegal(Position pos, ArrayList<Move> moveList) {
|
public static final ArrayList<Move> removeIllegal(Position pos, ArrayList<Move> moveList) {
|
||||||
ArrayList<Move> ret = new ArrayList<Move>();
|
ArrayList<Move> ret = new ArrayList<>();
|
||||||
UndoInfo ui = new UndoInfo();
|
UndoInfo ui = new UndoInfo();
|
||||||
int mlSize = moveList.size();
|
int mlSize = moveList.size();
|
||||||
for (int mi = 0; mi < mlSize; mi++) {
|
for (int mi = 0; mi < mlSize; mi++) {
|
||||||
@@ -244,7 +244,7 @@ public class MoveGen {
|
|||||||
* @param maxSteps Max steps until reaching a border. Set to 1 for non-sliding pieces.
|
* @param maxSteps Max steps until reaching a border. Set to 1 for non-sliding pieces.
|
||||||
* @ return True if the enemy king could be captured, false otherwise.
|
* @ return True if the enemy king could be captured, false otherwise.
|
||||||
*/
|
*/
|
||||||
private final boolean addDirection(ArrayList<Move> moveList, Position pos, int sq0, int maxSteps, int delta) {
|
private boolean addDirection(ArrayList<Move> moveList, Position pos, int sq0, int maxSteps, int delta) {
|
||||||
int sq = sq0;
|
int sq = sq0;
|
||||||
boolean wtm = pos.whiteMove;
|
boolean wtm = pos.whiteMove;
|
||||||
final int oKing = (wtm ? Piece.BKING : Piece.WKING);
|
final int oKing = (wtm ? Piece.BKING : Piece.WKING);
|
||||||
@@ -273,7 +273,7 @@ public class MoveGen {
|
|||||||
/**
|
/**
|
||||||
* Generate all possible pawn moves from (x0,y0) to (x1,y1), taking pawn promotions into account.
|
* Generate all possible pawn moves from (x0,y0) to (x1,y1), taking pawn promotions into account.
|
||||||
*/
|
*/
|
||||||
private final void addPawnMoves(ArrayList<Move> moveList, int sq0, int sq1) {
|
private void addPawnMoves(ArrayList<Move> moveList, int sq0, int sq1) {
|
||||||
if (sq1 >= 56) { // White promotion
|
if (sq1 >= 56) { // White promotion
|
||||||
moveList.add(getMoveObj(sq0, sq1, Piece.WQUEEN));
|
moveList.add(getMoveObj(sq0, sq1, Piece.WQUEEN));
|
||||||
moveList.add(getMoveObj(sq0, sq1, Piece.WKNIGHT));
|
moveList.add(getMoveObj(sq0, sq1, Piece.WKNIGHT));
|
||||||
|
|||||||
@@ -359,7 +359,7 @@ public class Position {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void removeCastleRights(int square) {
|
private void removeCastleRights(int square) {
|
||||||
if (square == Position.getSquare(0, 0)) {
|
if (square == Position.getSquare(0, 0)) {
|
||||||
setCastleMask(castleMask & ~(1 << Position.A1_CASTLE));
|
setCastleMask(castleMask & ~(1 << Position.A1_CASTLE));
|
||||||
} else if (square == Position.getSquare(7, 0)) {
|
} else if (square == Position.getSquare(7, 0)) {
|
||||||
@@ -411,7 +411,7 @@ public class Position {
|
|||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static long getRandomHashVal(int rndNo) {
|
private static long getRandomHashVal(int rndNo) {
|
||||||
try {
|
try {
|
||||||
MessageDigest md = MessageDigest.getInstance("SHA-1");
|
MessageDigest md = MessageDigest.getInstance("SHA-1");
|
||||||
byte[] input = new byte[4];
|
byte[] input = new byte[4];
|
||||||
|
|||||||
@@ -565,7 +565,7 @@ public class TextIO {
|
|||||||
if (moves == null)
|
if (moves == null)
|
||||||
moves = MoveGen.instance.legalMoves(pos);
|
moves = MoveGen.instance.legalMoves(pos);
|
||||||
|
|
||||||
ArrayList<Move> matches = new ArrayList<Move>(2);
|
ArrayList<Move> matches = new ArrayList<>(2);
|
||||||
for (int i = 0; i < moves.size(); i++) {
|
for (int i = 0; i < moves.size(); i++) {
|
||||||
Move m = moves.get(i);
|
Move m = moves.get(i);
|
||||||
int p = pos.getPiece(m.from);
|
int p = pos.getPiece(m.from);
|
||||||
@@ -754,7 +754,7 @@ public class TextIO {
|
|||||||
return ret.toString();
|
return ret.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static String pieceToChar(int p) {
|
private static String pieceToChar(int p) {
|
||||||
switch (p) {
|
switch (p) {
|
||||||
case Piece.WQUEEN: case Piece.BQUEEN: return "Q";
|
case Piece.WQUEEN: case Piece.BQUEEN: return "Q";
|
||||||
case Piece.WROOK: case Piece.BROOK: return "R";
|
case Piece.WROOK: case Piece.BROOK: return "R";
|
||||||
@@ -776,7 +776,7 @@ public class TextIO {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static int charToPiece(boolean white, char c) {
|
private static int charToPiece(boolean white, char c) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'Q': case 'q': return white ? Piece.WQUEEN : Piece.BQUEEN;
|
case 'Q': case 'q': return white ? Piece.WQUEEN : Piece.BQUEEN;
|
||||||
case 'R': case 'r': return white ? Piece.WROOK : Piece.BROOK;
|
case 'R': case 'r': return white ? Piece.WROOK : Piece.BROOK;
|
||||||
|
|||||||
@@ -171,14 +171,14 @@ public class TimeControl {
|
|||||||
currMove++;
|
currMove++;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (tc.get(tcIdx).movesPerSession <= 0)
|
if (tc.get(tcIdx).movesPerSession <= 0)
|
||||||
return new Pair<Integer,Integer>(tcIdx, 0);
|
return new Pair<>(tcIdx, 0);
|
||||||
nextTC += tc.get(tcIdx).movesPerSession;
|
nextTC += tc.get(tcIdx).movesPerSession;
|
||||||
if (nextTC > currMove)
|
if (nextTC > currMove)
|
||||||
break;
|
break;
|
||||||
if (tcIdx < lastTcIdx)
|
if (tcIdx < lastTcIdx)
|
||||||
tcIdx++;
|
tcIdx++;
|
||||||
}
|
}
|
||||||
return new Pair<Integer,Integer>(tcIdx, nextTC - currMove);
|
return new Pair<>(tcIdx, nextTC - currMove);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** De-serialize from input stream. */
|
/** De-serialize from input stream. */
|
||||||
|
|||||||
@@ -40,17 +40,17 @@ public final class TimeControlData {
|
|||||||
|
|
||||||
/** Constructor. Set a default time control. */
|
/** Constructor. Set a default time control. */
|
||||||
public TimeControlData() {
|
public TimeControlData() {
|
||||||
tcW = new ArrayList<TimeControlField>();
|
tcW = new ArrayList<>();
|
||||||
tcW.add(new TimeControlField(5*60*1000, 60, 0));
|
tcW.add(new TimeControlField(5*60*1000, 60, 0));
|
||||||
tcB = new ArrayList<TimeControlField>();
|
tcB = new ArrayList<>();
|
||||||
tcB.add(new TimeControlField(5*60*1000, 60, 0));
|
tcB.add(new TimeControlField(5*60*1000, 60, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Set a single time control for both white and black. */
|
/** Set a single time control for both white and black. */
|
||||||
public final void setTimeControl(int time, int moves, int inc) {
|
public final void setTimeControl(int time, int moves, int inc) {
|
||||||
tcW = new ArrayList<TimeControlField>();
|
tcW = new ArrayList<>();
|
||||||
tcW.add(new TimeControlField(time, moves, inc));
|
tcW.add(new TimeControlField(time, moves, inc));
|
||||||
tcB = new ArrayList<TimeControlField>();
|
tcB = new ArrayList<>();
|
||||||
tcB.add(new TimeControlField(time, moves, inc));
|
tcB.add(new TimeControlField(time, moves, inc));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ public final class TimeControlData {
|
|||||||
/** De-serialize from input stream. */
|
/** De-serialize from input stream. */
|
||||||
public void readFromStream(DataInputStream dis, int version) throws IOException {
|
public void readFromStream(DataInputStream dis, int version) throws IOException {
|
||||||
for (int c = 0; c < 2; c++) {
|
for (int c = 0; c < 2; c++) {
|
||||||
ArrayList<TimeControlField> tc = new ArrayList<TimeControlField>();
|
ArrayList<TimeControlField> tc = new ArrayList<>();
|
||||||
if (c == 0)
|
if (c == 0)
|
||||||
tcW = tc;
|
tcW = tc;
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user