int selectCycle() {
   if (t < N) {
     return generator.nextInt(5);
   } else {
     if (Rtmp > alpha) {
       currentPath = previousPath;
     } else currentPath = generator.nextInt(5);
   }
   return currentPath;
 }
Exemple #2
0
 public static int rules(
     String top, Vector<String> first, Vector<String> second, Vector<String> afia) {
   while (!first.isEmpty() && !second.isEmpty()) {
     if (count % 2 == 0) {
       boolean check = false;
       for (int i = 0; i < first.size(); i++) {
         check =
             matcher(
                 top,
                 first.elementAt(
                     i)); // performs a linear search on player1's whot to see if any matches the
         // top card
         if (check == true) {
           place.addElement(first.elementAt(i));
           first.removeElementAt(i);
           break;
         }
       }
       if (check == false) {
         Random rd = new Random();
         int pick = Math.abs(rd.nextInt(afia.size() - 1)) % (afia.size() - 1);
         first.addElement(afia.elementAt(pick));
         afia.removeElementAt(pick);
       }
     } else {
       boolean check = false;
       for (int i = 0; i < second.size(); i++) {
         check =
             matcher(
                 top,
                 second.elementAt(
                     i)); // performs a linear search on player1's whot to see if any matches the
         // top card
         if (check == true) {
           place.addElement(second.elementAt(i));
           second.removeElementAt(i);
           break;
         }
       }
       if (check == false) {
         Random rd = new Random();
         int pick = Math.abs(rd.nextInt(afia.size() - 1)) % (afia.size() - 1);
         second.addElement(afia.elementAt(pick));
         afia.removeElementAt(pick);
       }
     }
   }
   return 1;
 }
Exemple #3
0
  // Executes the given action
  public void executeAction(Action a) {

    // For each state variable, retrieve the DD for it, evaluate it
    // w.r.t. the current state and build a new state.
    ArrayList new_state = new ArrayList();
    int c;
    for (c = 0; c < (_nVars << 1); c++) {
      new_state.add("-");
    }
    for (c = 0; c < (_nVars << 1); c++) {
      Object cur_assign = _state.get(c);
      if (cur_assign instanceof Boolean) {
        // System.out.println(a._tmID2DD);
        int nonprime_id = c + 1;
        int prime_id = nonprime_id - _nVars;
        Object DD = a._tmID2DD.get(new Integer(prime_id));
        _state.set(prime_id - 1, TRUE);
        double p_true = _mdp._context.evaluate(DD, _state);
        // System.out.println("ID: " + nonprime_id + ", " + prime_id + ": " +
        //		   _mdp._context.printNode(DD) + " -> " +
        //		   _mdp._df.format(p_true));
        new_state.set(c, (_r.nextFloat() < p_true) ? TRUE : FALSE);
      }
    }

    _state = new_state;
  }
Exemple #4
0
  // Derives QFunctions for the given value function and simulates the
  // greedy policy for the given number of trials and steps per trial.
  // Returns final value of every trial.
  public ArrayList simulate(int trials, int steps, long rand_seed) {
    ArrayList values = new ArrayList();
    _r = new Random(rand_seed);

    for (int trial = 1; trial <= trials; trial++) {

      System.out.println("\n -----------\n   Trial " + trial + "\n -----------");

      // Initialize state
      _state = new ArrayList();
      _nVars = _mdp._alVars.size();
      for (int c = 0; c < (_nVars << 1); c++) {
        _state.add("-");
      }
      Iterator i = _mdp._alVars.iterator();
      _vars = new TreeSet();
      while (i.hasNext()) {
        String s = (String) i.next();
        if (!s.endsWith("\'")) {
          Integer gid = (Integer) _mdp._tmVar2ID.get(s);
          _vars.add(gid);

          // Note: assign level (level is gid-1 b/c gids in order)
          _state.set(gid.intValue() - 1, _r.nextBoolean() ? TRUE : FALSE);
        }
      }
      // System.out.println(_mdp._context.printNode(_mdp._valueDD) + "\n" + _state);
      double reward = _mdp._context.evaluate(_mdp._rewardDD, _state);
      System.out.print(" " + PrintState(_state) + "  " + MDP._df.format(reward));

      // Run steps
      for (int step = 1; step <= steps; step++) {

        // Get action
        Action a;
        if (_bUseBasis) {
          a = getBasisAction();
        } else {
          a = getAction();
        }

        // Execute action
        executeAction(a);

        // Update reward
        reward =
            (_mdp._bdDiscount.doubleValue() * reward)
                + _mdp._context.evaluate(_mdp._rewardDD, _state);

        System.out.println(", a=" + a._sName);
        System.out.print(
            " " + PrintState(_state) + "  " + MDP._df.format(reward) + ": " + "Step " + step);
      }
      values.add(new Double(reward));
      System.out.println();
    }

    return values;
  }
Exemple #5
0
 static void test() {
   int q = 0;
   while (true) {
     if (++q == 100) {
       System.err.println("Test");
       q = 0;
     }
     int[] a = new int[rand.nextInt(100000) + 1];
     for (int i = 0; i < a.length; i++) {
       a[i] = rand.nextInt(100);
     }
     int e = rand.nextInt(5) + 1;
     for (int i = 0; i < e; i++) {
       a[rand.nextInt(a.length)] = allLucky.get(rand.nextInt(allLucky.size()));
     }
     solve(a);
   }
 }
 private static void sort(long[] l1) {
   for (int i = 0; i < l1.length; i++) {
     int q = i + usingRandomGenerator.nextInt(l1.length - i);
     long t = l1[i];
     l1[i] = l1[q];
     l1[q] = t;
   }
   Arrays.sort(l1);
 }
Exemple #7
0
 public static ArrayList<Vector> share(
     Vector<String> allgames) { // shares the games to the players
   Vector<String> play1 = new Vector<String>();
   Vector<String> play2 = new Vector<String>();
   ArrayList<Vector> al = new ArrayList<Vector>();
   Random rd = new Random();
   for (int i = 0; i < 4; i++) {
     int first = Math.abs(rd.nextInt(allgames.size() - 1)) % (allgames.size());
     play1.addElement(allgames.elementAt(first));
     allgames.removeElementAt(first);
     int second = Math.abs(rd.nextInt(allgames.size() - 1)) % (allgames.size());
     play2.addElement(allgames.elementAt(second));
     allgames.removeElementAt(second);
   }
   al.add(play1);
   al.add(play2);
   v = allgames;
   return al;
 }
  public String getNextWord() {
    // potentially infinite loop but because of the way
    // it's handled in the program, it will always return
    while (true) {
      temp = rand.nextInt(words.length);

      // if the prospective word hasn't been played
      if (!hasBeenPlayed(words[temp])) {
        played[index] = words[temp];
        index++;
        return words[temp];
      }
    }
  }
Exemple #9
0
  /** Return 1 if player 1 wins the initiative, 2 if player 2 wins the initiative. */
  public static int rollInitiative() {
    int result = random.nextInt(2);

    return (result + 1);
  }
Exemple #10
0
  /** Returns critical hit location for body locations with 12 critical hit locations. */
  public static int rollCritical2() // Critical roll for location with 12 slots
      {
    int result = random.nextInt(12);

    return (result);
  }
Exemple #11
0
  /** Returns result of rolling 2 six-sided dice. */
  public static int rollDice() // 2 dice rolled
      {
    int result = (random.nextInt(6) + 1) + (random.nextInt(6) + 1);

    return (result);
  }
Exemple #12
0
  /** Returns result of rolling 1 six-sided die. */
  public static int rollDie() // 1 die rolled
      {
    int result = (random.nextInt(6) + 1);

    return (result);
  }