コード例 #1
0
ファイル: Gradual.java プロジェクト: dwdyer/ipdframework
  public Action getNextMove(GameHistory history) {
    int historyLength = history.getHistoryLength();
    if (mode == MODE_NORMAL
        && historyLength > 0
        && history.getOpponentActionForIteration(this, historyLength - 1) == Action.DEFECT) {
      mode = MODE_PUNISHMENT;
      defectionCount++;
      modeDuration = defectionCount;
      logger.debug("Gradual punishment triggered (duration: " + modeDuration + ").");
    }

    if (mode == MODE_PUNISHMENT) {
      logger.debug("In punishment mode.");
      if (modeDuration > 0) {
        logger.debug("Defecting...");
        modeDuration--;
        return Action.DEFECT;
      } else {
        logger.debug("Switched to reconcilliation.");
        mode = MODE_RECONCILLIATION;
        modeDuration = 2;
      }
    }
    if (mode == MODE_RECONCILLIATION && modeDuration <= 1) {
      mode = MODE_NORMAL;
    }
    modeDuration--;
    return Action.COOPERATE;
  }