Esempio n. 1
0
  /* Search game tree by alpha-beta algorithm */
  public int alphabeta(int alpha, int beta, int depth) {
    int i, value, best;

    if (depth == 0) return eval();

    generateMoves();
    best = -INFINITY;

    for (i = gen_begin[ply]; i < gen_end[ply] && best < beta; i++) {
      if (best > alpha) alpha = best;

      if (move(gen_dat[i].m)) value = 1000 - ply;
      else value = -alphabeta(-beta, -alpha, depth - 1);
      unmove();

      if (value > best) {
        best = value;
        if (ply == 0) {
          newmove.from = gen_dat[i].m.from;
          newmove.dest = gen_dat[i].m.dest;
        }
      }
    }

    return best;
  }
Esempio n. 2
0
  public int takeAMove(int from, int to) {
    generateMoves();
    newmove.from = from;
    newmove.dest = to;
    int ret = MOVE_INVALID;
    for (int i = gen_begin[ply]; i < gen_end[ply]; i++) {
      if (gen_dat[i].m.from == newmove.from && gen_dat[i].m.dest == newmove.dest) {
        if (updateNewMove()) {
          return MOVE_WIN;
        }
        ret = MOVE_OK;
        side = xside;
        xside = 1 - xside;

        break;
      }
    }
    return ret;
  }
Esempio n. 3
0
  public void restoreStatus(DataInputStream dis) throws IOException {
    for (int i = 0; i < color.length; i++) {
      color[i] = dis.readInt();
    }
    for (int i = 0; i < piece.length; i++) {
      piece[i] = dis.readInt();
    }
    MAX_PLY = dis.readInt();
    nodecount = dis.readInt();
    brandtotal = dis.readInt();
    gencount = dis.readInt();
    ply = dis.readInt();
    side = dis.readInt();
    xside = dis.readInt();
    computerside = dis.readInt();

    newmove.from = dis.readInt();
    newmove.dest = dis.readInt();

    for (int i = 0; i < gen_dat.length; i++) {
      gen_dat[i].m.from = dis.readInt();
      gen_dat[i].m.dest = dis.readInt();
    }
    for (int i = 0; i < gen_begin.length; i++) {
      gen_begin[i] = dis.readInt();
    }
    for (int i = 0; i < gen_end.length; i++) {
      gen_end[i] = dis.readInt();
    }
    for (int i = 0; i < hist_dat.length; i++) {
      hist_dat[i].m.from = dis.readInt();
      hist_dat[i].m.dest = dis.readInt();
      hist_dat[i].capture = dis.readInt();
    }

    hdp = dis.readInt();
  }