DroidFish: Simplified TextIO.isValid() method.

This commit is contained in:
Peter Osterlund 2012-07-22 09:30:18 +00:00
parent 1f5f5c9522
commit 29f0b8766c
4 changed files with 7 additions and 9 deletions

View File

@ -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;
} }
} }

View File

@ -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));

View File

@ -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);

View File

@ -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;