コード例 #1
0
  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());
  }
コード例 #2
0
  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;
  }
コード例 #3
0
 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;
 }