public int getBestVirtualMove() {
    _logNrPlayouts = Math.log(_totalPlayouts + 1.0f);
    _beta = getBeta();

    int bestMove = GoConstant.PASS;
    double bestResult = computeResult(_bestMove);
    if (_bestMove != GoConstant.PASS && bestResult > _bestResult) {
      assert (bestResult > 0.0);
      usedLastBest = true;
      // What was previously the best move, most likely still is as it only got better.
      _bestResult = bestResult;
      return _bestMove;
    }
    usedLastBest = false;

    for (int i = _emptyPoints.getSize(); --i >= 0; ) {
      int next = _emptyPoints.get(i);
      double result = computeResult(next);
      boolean better;
      if (result > bestResult) better = true;
      else if (result == bestResult)
        better =
            (bestMove == GoConstant.PASS || _virtualPlayouts[next] > _virtualPlayouts[bestMove]);
      else better = false;

      if (better) {
        bestMove = next;
        bestResult = result;
      }
    }
    _bestMove = bestMove;
    _bestResult = bestResult;
    assert (bestResult >= 0.0);
    return bestMove;
  }
 public int getBestMove() {
   int bestMove = GoConstant.PASS;
   for (int i = _emptyPoints.getSize(); --i >= 0; ) {
     int next = _emptyPoints.get(i);
     if (isBetterResultThan(next, bestMove)) bestMove = next;
   }
   return bestMove;
 }
  public void setPointSet(MonteCarloPluginAdministration administration) {
    MersenneTwisterFast random = administration.RANDOM;
    _boardSize = administration.getBoardSize();

    assert (_emptyPoints.getSize() == 0);
    PointSet copy = PointSetFactory.createPointSet();
    copy.copyFrom(administration.getEmptyPoints());
    //		boolean isTestVersion = GlobalParameters.isTestVersion();
    ProbabilityMap map = administration.getProbabilityMap();
    byte colorToMove = administration.getColorToMove();
    for (int size = copy.getSize(); size > 0; size--) {
      int xy = copy.get(random.nextInt(size));
      copy.remove(xy);
      if (administration.isLegal(xy) && !administration.isVerboten(xy)) {
        _emptyPoints.add(xy);
        //				if (isTestVersion)
        //				{
        //					float weight = (float)map.getWeight(xy, colorToMove);
        //					float factor = (float)Math.log(weight);
        //					if (weight<1.0)
        //						weight = 0.0f;
        //					else
        //						weight -= 1.0f;
        //					if (factor<1)
        //						factor = 1.0f;
        //					_virtualPlayouts[xy] = weight/factor;
        //					_virtualWins[xy] = weight;
        //				}
        //				else
        {
          _virtualPlayouts[xy] = 0.0f;
          _virtualWins[xy] = 0.0f;
        }
      }
    }
    copy.recycle();
    if (administration.isGameAlmostFinished()) {
      _virtualPlayouts[GoConstant.PASS] = 0;
      _virtualWins[GoConstant.PASS] = 0;
      _emptyPoints.add(GoConstant.PASS);
    }

    for (MoveGenerator generator : administration.getExplorationMoveGeneratorList()) {
      int xy = generator.generate();
      if (xy != GoConstant.UNDEFINED_COORDINATE)
        increaseVirtualPlayouts(xy, generator.getUrgency(), generator.getUrgency());
    }
    assert (_emptyPoints.freeze());
  }
  protected void init() {
    _xy = GoConstant.UNDEFINED_COORDINATE;
    _logNrPlayouts = 0.0;
    _beta = 0.0;
    _totalPlayouts = 0;
    _bestMove = GoConstant.PASS;
    _bestResult = -1.0;
    usedLastBest = false;

    _emptyPoints.clear();
    GoArray.clear(_playouts);
    GoArray.clear(_wins);
    GoArray.clear(_virtualWins);
    GoArray.clear(_virtualPlayouts);
    //		GoArray.clear(_results);
  }
 public void copyDataFrom(MonteCarloHashMapResult source) {
   _xy = source._xy;
   _color = source._color;
   _totalPlayouts = source._totalPlayouts;
   _wins = Arrays.copyOf(source._wins, source._wins.length);
   _playouts = Arrays.copyOf(source._playouts, source._playouts.length);
   _virtualWins = Arrays.copyOf(source._virtualWins, source._virtualWins.length);
   _virtualPlayouts = Arrays.copyOf(source._virtualPlayouts, source._virtualPlayouts.length);
   _emptyPoints.copyFrom(source._emptyPoints);
   _logNrPlayouts = source._logNrPlayouts;
   _beta = source._beta;
   _age = source._age;
   _checksum = source._checksum;
   _bestMove = source._bestMove;
   _bestResult = source._bestResult;
   usedLastBest = source.usedLastBest;
   _boardSize = source._boardSize;
 }
 //	@Override
 public void recycle() {
   assert (_emptyPoints.unfreeze());
   _owner.push(this);
 }