mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2024-11-23 19:34:08 +01:00
DroidFish: Simplified TextIO.isValid() method.
This commit is contained in:
parent
1f5f5c9522
commit
29f0b8766c
|
@ -764,13 +764,13 @@ public class DroidComputerPlayer {
|
||||||
|
|
||||||
if (canPonder) {
|
if (canPonder) {
|
||||||
Move bestM = TextIO.stringToMove(sr.currPos, bestMove);
|
Move bestM = TextIO.stringToMove(sr.currPos, bestMove);
|
||||||
if ((bestM == null) || !TextIO.isValid(sr.currPos, bestM, null))
|
if ((bestM == null) || !TextIO.isValid(sr.currPos, bestM))
|
||||||
canPonder = false;
|
canPonder = false;
|
||||||
if (canPonder) {
|
if (canPonder) {
|
||||||
Position tmpPos = new Position(sr.currPos);
|
Position tmpPos = new Position(sr.currPos);
|
||||||
UndoInfo ui = new UndoInfo();
|
UndoInfo ui = new UndoInfo();
|
||||||
tmpPos.makeMove(bestM, ui);
|
tmpPos.makeMove(bestM, ui);
|
||||||
if (!TextIO.isValid(tmpPos, nextPonderMove, null))
|
if (!TextIO.isValid(tmpPos, nextPonderMove))
|
||||||
canPonder = false;
|
canPonder = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -678,7 +678,7 @@ public class DroidChessController {
|
||||||
for (Move m : pv.pv) {
|
for (Move m : pv.pv) {
|
||||||
if (m == null)
|
if (m == null)
|
||||||
break;
|
break;
|
||||||
if (!TextIO.isValid(tmpPos, m, null))
|
if (!TextIO.isValid(tmpPos, m))
|
||||||
break;
|
break;
|
||||||
String moveStr = TextIO.moveToString(tmpPos, m, false);
|
String moveStr = TextIO.moveToString(tmpPos, m, false);
|
||||||
buf.append(String.format(" %s", moveStr));
|
buf.append(String.format(" %s", moveStr));
|
||||||
|
|
|
@ -125,7 +125,7 @@ public class Game {
|
||||||
|
|
||||||
Move m = TextIO.UCIstringToMove(str);
|
Move m = TextIO.UCIstringToMove(str);
|
||||||
if (m != null)
|
if (m != null)
|
||||||
if (!TextIO.isValid(currPos(), m, null))
|
if (!TextIO.isValid(currPos(), m))
|
||||||
m = null;
|
m = null;
|
||||||
if (m == null)
|
if (m == null)
|
||||||
m = TextIO.stringToMove(currPos(), str);
|
m = TextIO.stringToMove(currPos(), str);
|
||||||
|
|
|
@ -429,13 +429,11 @@ public class TextIO {
|
||||||
* @param moves If non-null, list of valid moves in position pos.
|
* @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, ArrayList<Move> moves) {
|
public static final boolean isValid(Position pos, Move move) {
|
||||||
if (move == null)
|
if (move == null)
|
||||||
return false;
|
return false;
|
||||||
if (moves == null) {
|
ArrayList<Move> moves = new MoveGen().pseudoLegalMoves(pos);
|
||||||
moves = new MoveGen().pseudoLegalMoves(pos);
|
moves = MoveGen.removeIllegal(pos, moves);
|
||||||
moves = MoveGen.removeIllegal(pos, moves);
|
|
||||||
}
|
|
||||||
for (int i = 0; i < moves.size(); i++)
|
for (int i = 0; i < moves.size(); i++)
|
||||||
if (move.equals(moves.get(i)))
|
if (move.equals(moves.get(i)))
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user