//    protected MoveValuePair handleTerminal(Position position, boolean maxTurn) {
  //        MoveValuePair finalMove = new MoveValuePair();
  //        if (position.isTerminal() && position.isMate()) {
  //            this.terminalFound = position.isTerminal();
  //            finalMove.eval = (maxTurn ? BE_MATED : MATE);
  //        } else if (position.isTerminal() && position.isStaleMate())
  //            finalMove.eval = 0;
  //        else {
  //            finalMove.eval = (int) ( (position.getMaterial() + position.getDomination()));
  //        }
  ////        System.out.print(finalMove.eval + " ");
  //        return finalMove;
  //    }
  protected LinkedList<MoveValuePair> getCapturingSortedMoves(Position position, boolean maxTurn)
      throws IllegalMoveException {
    LinkedList<MoveValuePair> sortedMoves = new LinkedList<MoveValuePair>();
    short[] moves = position.getAllCapturingMoves();
    MoveValuePair theMove = null;
    ASCENDING = maxTurn ? false : true;

    for (short move : moves) {
      position.doMove(move);
      if (p2tte.containsKey(position.getHashCode())) {
        theMove = new MoveValuePair(move, p2tte.get(position.getHashCode()).eval);
      } else {
        // for max turn, I assign worst values those unvisited positions
        //                theMove = new MoveValuePair(move, maxTurn ? BE_MATED : MATE);
        int eval = (int) ((maxTurn ? -1 : 1) * (position.getMaterial() + position.getDomination()));
        theMove = new MoveValuePair(move, eval);
      }
      position.undoMove();
      sortedMoves.add(theMove);
    }
    Collections.sort(
        sortedMoves,
        new Comparator<MoveValuePair>() {
          @Override
          public int compare(MoveValuePair c1, MoveValuePair c2) {
            //                System.out.println(c1.eval + " vs " + c2.eval);
            return (int) ((ASCENDING ? 1 : -1) * Math.signum(c1.eval - c2.eval)); // use your logic
          }
        });
    return sortedMoves;
  }