⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 boardpanel.java

📁 五子棋游戏
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
               downsign = 0;
           }
       }
       else {
           tempy += 1;
           while (tt[tempy][tempx] == side) {
               c_count += 1;
               tempy++;
           }
           if (tt[tempy][tempx] == 0) {
               downsign = 1;
           }
           if (tt[tempy][tempx] != 0) {
               downsign = 0;
           }
       }
       mark += pow(base, c_count);
       if ( (uppersign + downsign) > 0) {
           if ( (uppersign + downsign) == 2) {
               mark *= (uppersign + downsign);
           }
           if ( (uppersign + downsign) == 1) {
               mark = mark / 2;
           }
       }
       else if (c_count == 5) {
           mark *= 4;
       }
       else {
           mark = 0;
       }
       if (c_count == 5) {
           mark += INVALID;
       }
       return mark;
   }
   /**
    *
    * @param x
    * @param y
    * @param side
    * @return
    */
   private long analyseLr(int x, int y, int side){
       int tt[][] = new int[17][17];
       int i, j,tx, ty;
       long mark = 0;

       int base = BASE,uppersign = 0,downsign = 0,c_count = 1;
       for (i = 0; i < 17; i++) {
           for (j = 0; j < 17; j++) {
               tt[i][j] = chessBoard[i][j];
           }
       }
       tt[y][x] = side;
       // left and right
       tx = x;
       ty = y;
       if (tt[ty][tx - 1] != side) {
           if (tt[ty][tx - 1] == 0) {
               uppersign = 1;
           }
           if (tt[ty][tx - 1] != 0) {
               uppersign = 0;
           }
       }
       else {
           tx -= 1;
           while (tt[ty][tx] == side) {
               c_count += 1;
               tx--;
           }
           if (tt[ty][tx] == 0) {
               uppersign = 1;
           }
           if (tt[ty][tx] != 0) {
               uppersign = 0;
           }
       }
       tx = x;
       ty = y;
       if (tt[ty][tx + 1] != side) {
           if (tt[ty][tx + 1] == 0) {
               downsign = 1;
           }
           if (tt[ty][tx + 1] != 0) {
               downsign = 0;
           }
       }
       else {
           tx += 1;
           while (tt[ty][tx] == side) {
               c_count += 1;
               tx++;
           }
           if (tt[ty][tx] == 0) {
               downsign = 1;
           }
           if (tt[ty][tx] != 0) {
               downsign = 0;
           }
       }
       mark += pow(base, c_count);
       if ( (uppersign + downsign) > 0) {
           if ( (uppersign + downsign) == 2) {
               mark *= (uppersign + downsign);
           }
           if ( (uppersign + downsign) == 1) {
               mark = mark / 2;
           }
       }
       else if (c_count == 5) {
           mark *= 4;
       }
       else {
           mark = 0;
       }
       if (c_count == 5) {
           mark += INVALID;
       }
       return mark;
   }
   /**
    *
    * @param x
    * @param y
    * @param side
    * @return
    */
   private long analyseLdru(int x, int y, int side){
       int tt[][] = new int[17][17];
       int i, j;
       int tx, ty;
       long mark = 0;

       int base = BASE;
       int uppersign = 0;
       int downsign = 0;
       int c_count = 1;
       for (i = 0; i < 17; i++) {
           for (j = 0; j < 17; j++) {
               tt[i][j] = chessBoard[i][j];
           }
       }
       tt[y][x] = side;
       /* left down and right upper */
       tx = x;
       ty = y;
       if (tt[ty - 1][tx - 1] != side) {
           if (tt[ty - 1][tx - 1] == 0) {
               uppersign = 1;
           }
           if (tt[ty - 1][tx - 1] != 0) {
               uppersign = 0;
           }
       }
       else {
           tx -= 1;
           ty -= 1;
           while (tt[ty][tx] == side) {
               c_count += 1;
               tx--;
               ty--;
           }
           if (tt[ty][tx] == 0) {
               uppersign = 1;
           }
           if (tt[ty][tx] != 0) {
               uppersign = 0;
           }
       }
       tx = x;
       ty = y;
       if (tt[ty + 1][tx + 1] != side) {
           if (tt[ty + 1][tx + 1] == 0) {
               downsign = 1;
           }
           if (tt[ty + 1][tx + 1] != 0) {
               downsign = 0;
           }
       }
       else {
           tx += 1;
           ty += 1;
           while (tt[ty][tx] == side) {
               c_count += 1;
               tx++;
               ty++;
           }
           if (tt[ty][tx] == 0) {
               downsign = 1;
           }
           if (tt[ty][tx] != 0) {
               downsign = 0;
           }
       }
       mark += pow(base, c_count);
       if ( (uppersign + downsign) > 0) {
           //mark*=(uppersign+downsign);
           if ( (uppersign + downsign) == 2) {
               mark *= (uppersign + downsign);
           }
           if ( (uppersign + downsign) == 1) {
               mark = mark / 2;
           }
       }
       else if (c_count == 5) {
           mark *= 4;
       }
       else {
           mark = 0;
       }
       if (c_count == 5) {
           mark += INVALID;
       }
       return mark;
   }
   private long analyseRdlu(int x, int y, int side){
       int tt[][] = new int[17][17];
       int i, j;
       int tx, ty;
       long mark = 0;

       int base = BASE;
       int uppersign = 0;
       int downsign = 0;
       int c_count = 1;
       for (i = 0; i < 17; i++) {
           for (j = 0; j < 17; j++) {
               tt[i][j] = chessBoard[i][j];
           }
       }
       tt[y][x] = side;
       /* left down and right upper */
       tx = x;
       ty = y;
       if (tt[ty - 1][tx + 1] != side) {
           if (tt[ty - 1][tx + 1] == 0) {
               uppersign = 1;
           }
           if (tt[ty - 1][tx + 1] != 0) {
               uppersign = 0;
           }
       }
       else {
           tx += 1;
           ty -= 1;
           while (tt[ty][tx] == side) {
               c_count += 1;
               tx++;
               ty--;
           }
           if (tt[ty][tx] == 0) {
               uppersign = 1;
           }
           if (tt[ty][tx] != 0) {
               uppersign = 0;
           }
       }
       tx = x;
       ty = y;
       if (tt[ty + 1][tx - 1] != side) {
           if (tt[ty + 1][tx - 1] == 0) {
               downsign = 1;
           }
           if (tt[ty + 1][tx - 1] != 0) {
               downsign = 0;
           }
       }
       else {
           tx -= 1;
           ty += 1;
           while (tt[ty][tx] == side) {
               c_count += 1;
               tx--;
               ty++;
           }
           if (tt[ty][tx] == 0) {
               downsign = 1;
           }
           if (tt[ty][tx] != 0) {
               downsign = 0;
           }
       }
       mark += pow(base, c_count);
       if ( (uppersign + downsign) > 0) {
           if ( (uppersign + downsign) == 2) {
               mark *= (uppersign + downsign);
           }
           if ( (uppersign + downsign) == 1) {
               mark = mark / 2;
           }
       }
       else if (c_count == 5) {
           mark *= 4;
       }
       else {
           mark = 0;
       }
       if (c_count == 5) {
           mark += INVALID;
       }
       return mark;
   }
   /**
    *
    * @param x
    * @param y
    * @param side
    * @return
    */
   private long analyse(int x, int y, int side){
       long mark = 0;
       mark += analyseUd(x, y, side);
       mark += analyseLr(x, y, side);
       mark += analyseLdru(x, y, side);
       mark += analyseRdlu(x, y, side);
       return mark;
   }
   /**
    *
    * @param chess
    * @param deepth
    * @return
    */
   private Queue searchPoint(int chess[][],int deepth){
       //temp
       int cx, cy;
       //int newdeepth;
       char s[] = new char[10];
       //temp
       Queue pq[] = null, pq_temp[] = null, pq_final;
       int temp_chess[][] = new int[17][17];
       long mark = 0;
       int duce;
       int i, j;
       int m, n, p, q;
       int media;
       int MAX;
       int k, b;
       //mark
       MAX=MAX1<=(225-STEPCOUNTER)?MAX1:(225-STEPCOUNTER);
            if(MAX==(225-STEPCOUNTER)){
        MINDEEPTH=1;
            }
       pq = new Queue[MAX + 1];
       for (m = 0; m < MAX; m++) {
           pq[m] = new Queue();
       }
       for (m = 0; m < MAX; m++) {
           pq[m].mark = 0;
           pq[m].position = 0;
       }
       for (i = 1; i <= 15; i++) {
         //  System.out.println();
           for (j = 1; j <= 15; j++) {
               if (chess[i][j] != 0) {
                   mark = 0;
               }
               else {
                   mark = analyse(j, i, 1) / 2 + analyse(j, i, 2);
           //        System.out.print("\t" + mark);
               }

               //tempboard[i][j]=mark;
               for (m = 0; m < MAX; m++) {
                   if (mark > pq[m].mark) {
                       for (n = MAX - 1; n > m; n--) {
                           pq[n].mark = pq[n - 1].mark;
                           pq[n].position = pq[n - 1].position;
                       }
                       pq[m].mark = mark;
                       pq[m].position = i * 100 + j;
                       break;
                   }
               }
           }
       }
       //newdeepth=maxdeepth;
       if (pq[0].mark >= INVALID / 2) {
           MINDEEPTH = deepth;
       }
       if (deepth < MINDEEPTH) {
           for (m = 0; m < MAX; m++) {
               for (p = 0; p <= 16; p++) {
                   for (q = 0; q <= 16; q++) {
                       temp_chess[p][q] = chess[p][q];
                   }
               }
               if (deepth % 2 == 1) {
                   media = 2;
               }
               else {
                   media = 1;
               }
               temp_chess[pq[m].position / 100][pq[m].position % 100] = media;
               pq[m] = searchPoint(temp_chess, deepth + 1);
           }
       }
       pq_temp = new Queue[MAX + 1];
       for (m = 0; m < MAX; m++) {
           pq_temp[m] = new Queue();
       }

       for (p = 0; p < MAX; p++) {
           pq_temp[p].mark = 0;
           pq_temp[p].position = 0;
       }
       for (p = 0; p < MAX; p++) {
           for (q = 0; q < MAX; q++) {
               if (pq[p].mark > pq_temp[q].mark) {
                   for (i = MAX - 1; i > q; i--) {
                       pq_temp[i] = pq_temp[i - 1];
                   }
                   pq_temp[q] = pq[p];
                   break;
               }
           }
       }
       pq_final = pq_temp[0];
       return pq_final;
   }
   public int computerDo(){
       int position = 0;
       int cx, cy;
       position = (searchPoint(chessBoard, 3)).position;
       cx = position % 100;
       cy = position / 100;
//       System.out.print("\n" + cy + "\t" + cx + "\n");
       if (cx == 0 && cy == 0) {
           return 1;
       }
       return position;
   }
} ///:-)


}///:-)
/**
 * mouse Adapter
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: e-top</p>
 * @author cylix
 * @version 1.0
 */
class ChessWZQ_this_mouseAdapter extends java.awt.event.MouseAdapter {
    BoardPanel adaptee;

    ChessWZQ_this_mouseAdapter(BoardPanel adaptee) {
        this.adaptee = adaptee;
    }
    public void mouseClicked(MouseEvent e) {
        adaptee.this_mouseClicked(e);
    }
}///:-)
/**
 * mouse Adapter
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: e-top</p>
 * @author cylix
 * @version 1.0
 */
class ChessWZQ_this_mouseMotionAdapter extends java.awt.event.MouseMotionAdapter {
    BoardPanel adaptee;

    ChessWZQ_this_mouseMotionAdapter(BoardPanel adaptee) {
        this.adaptee = adaptee;
    }
    public void mouseMoved(MouseEvent e) {
        adaptee.this_mouseMoved(e);
    }
}///:-)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -