Esempio n. 1
0
  public static WumpusEnvironment getNewWumpusEnvironment(
      final int n,
      final int nWumpus,
      final int nGold,
      final int nArrows,
      double pitProb,
      long seed) {
    WumpusEnvironment we = new WumpusEnvironment();

    we._rand = new Random(seed);
    we._nSize = n;
    we._bAlive = true;
    we._tsGoldMap = new TreeSet<Pair<Integer, Integer>>();
    we._tsPitMap = new TreeSet<Pair<Integer, Integer>>();
    we._tsWumpusMap = new TreeSet<Pair<Integer, Integer>>();
    we.currentLoc = new Pair<Integer, Integer>(0, 0);
    we._nArrow = nArrows;
    we._bWumpusDied = false;
    we._bTrialOver = false;
    we._nHasGold = 0;
    we._nTime = 0;
    we._nFacing = DIRECTION.DIRUP;

    while (true) {
      int x = we._rand.nextInt(n);
      int y = we._rand.nextInt(n);
      if (x == 0 && y == 0) {
        continue;
      }

      we._tsGoldMap.add(new Pair<Integer, Integer>(x, y));
      if (we._tsGoldMap.size() == nGold) {
        break;
      }
    }

    while (true) {
      int x = we._rand.nextInt(n);

      int y = we._rand.nextInt(n);
      if (x == 0 && y == 0) {
        continue;
      }

      we._tsWumpusMap.add(new Pair<Integer, Integer>(x, y));
      if (we._tsWumpusMap.size() == nWumpus) {
        break;
      }
    }

    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (i == 0 && j == 0) {
          continue;
        }
        double d = we._rand.nextDouble();
        if (d <= pitProb) {
          we._tsPitMap.add(new Pair<Integer, Integer>(i, j));
        }
      }
    }

    return we;
  }