public final ArrayList<Move> removeNonOptimal(Position pos,ArrayList<Move> moveList){
  ArrayList<Move> optimalMoves=new ArrayList<Move>();
  ArrayList<Move> unknownMoves=new ArrayList<Move>();
  final int MATE0=100000;
  int bestScore=-1000000;
  UndoInfo ui=new UndoInfo();
  for (  Move m : moveList) {
    pos.makeMove(m,ui);
    int pliesToDraw=Math.max(100 - pos.halfMoveClock,1);
    GtbProbeResult res=gtbProbe(pos);
    pos.unMakeMove(m,ui);
    if (res.result == GtbProbeResult.UNKNOWN) {
      unknownMoves.add(m);
    }
 else {
      int wScore;
      if (res.result == GtbProbeResult.WMATE) {
        if (res.pliesToMate <= pliesToDraw)         wScore=MATE0 - res.pliesToMate;
 else         wScore=1;
      }
 else       if (res.result == GtbProbeResult.BMATE) {
        if (res.pliesToMate <= pliesToDraw)         wScore=-(MATE0 - res.pliesToMate);
 else         wScore=-1;
      }
 else {
        wScore=0;
      }
      int score=pos.whiteMove ? wScore : -wScore;
      if (score > bestScore) {
        optimalMoves.clear();
        optimalMoves.add(m);
        bestScore=score;
      }
 else       if (score == bestScore) {
        optimalMoves.add(m);
      }
 else {
      }
    }
  }
  for (  Move m : unknownMoves)   optimalMoves.add(m);
  return (optimalMoves.size() < moveList.size()) ? optimalMoves : null;
}

public final ArrayList < Move > removeNonOptimal ( Position pos , ArrayList < Move > moveList ) { ArrayList < Move > optimalMoves = new ArrayList < Move > ( ) ; ArrayList < Move > unknownMoves = new ArrayList < Move > ( ) ; final int MATE0 = 100000 ; int bestScore = - 1000000 ; UndoInfo ui = new UndoInfo ( ) ; for ( Move m : moveList ) { pos . makeMove ( m , ui ) ; int pliesToDraw = Math . max ( 100 - pos . halfMoveClock , 1 ) ; GtbProbeResult res = gtbProbe ( pos ) ; pos . unMakeMove ( m , ui ) ; if ( res . result == GtbProbeResult . UNKNOWN ) { unknownMoves . add ( m ) ; } else { int wScore ; if ( res . result == GtbProbeResult . WMATE ) { if ( res . pliesToMate <= pliesToDraw ) wScore = MATE0 - res . pliesToMate ; else wScore = 1 ; } else if ( res . result == GtbProbeResult . BMATE ) { if ( res . pliesToMate <= pliesToDraw ) wScore = - ( MATE0 - res . pliesToMate ) ; else wScore = - 1 ; } else { wScore = 0 ; } int score = pos . whiteMove ? wScore : - wScore ; if ( score > bestScore ) { optimalMoves . clear ( ) ; optimalMoves . add ( m ) ; bestScore = score ; } else if ( score == bestScore ) { optimalMoves . add ( m ) ; } else { } } } for ( Move m : unknownMoves ) optimalMoves . add ( m ) ; return ( optimalMoves . size ( ) < moveList . size ( ) ) ? optimalMoves : null ; }
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 .
