Exemplo n.º 1
0
  /** @see com.anji.roshambo.RoshamboPlayer#nextMove() */
  public int nextMove() {
    int nextmove;
    // sets unbeatable flag if no pattern is found
    unbeatable = true;
    for (int i = 0; i < nrofpatterns; i++) {
      if ((patternscore(i) > movenr / 5) || (patternscore(i) > historylength / 5)) {
        unbeatable = false;
        break;
      }
    }
    // determine the next move
    if (movenr < 3 || unbeatable) nextmove = Coin.flip();
    else {
      int best_p = bestpattern();
      p_chosen[best_p]++;
      nextmove = prediction(best_p);
    }
    // check op mogelijke illegale zet
    if ((nextmove > 2) || (nextmove < 0)) {
      nextmove = Coin.flip();
    }
    // store move
    history[MINE][movenr] = nextmove;

    if (!unbeatable) bp++;
    else ubp++;
    return nextmove;
  }
Exemplo n.º 2
0
 private int detectcopy(int who) {
   if (movenr < 2) return Coin.flip();
   int length = 10;
   if (movenr < 5) length = movenr - 1;
   if (movenr < 10) length = movenr - 3;
   int other = (who + 1) % 2;
   for (int i = 1; i < 5; i++) {
     int a = historySearch(who, other, other, length, length, i, i, 1, 0, 1);
     if (a != -3) return a;
     int b = historySearch(who, other, other, length, length, i, i, 1, 1, 1);
     if (b != -3) return b;
     int c = historySearch(who, other, other, length, length, i, i, 1, 2, 1);
     if (c != -3) return c;
   }
   return -3;
 }
  public static void main(String[] args) {
    final int FLIPS = 1000;
    int heads = 0;
    int tails = 0;

    Coin myCoin = new Coin();

    for (int count = 1; count <= FLIPS; count++) {
      myCoin.flip();

      if (myCoin.isHeads()) heads++;
      else tails++;
    }

    System.out.println("Number of flips: " + FLIPS);
    System.out.println("Number of heads: " + heads);
    System.out.println("Number of tails: " + tails);
  }
Exemplo n.º 4
0
 private int copyrotate(int who) {
   if (movenr == 0) return Coin.flip();
   return (history[who][movenr - 1] + movenr) % 3;
 }