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

📄 board.java

📁 java 3d编程的一些例子源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
      float begY;      for (int l=0; l<3; l++) {         begY =  28.0f + l*(5.f*23.3f);         for (int k=0; k<6; k++) {            begX =  11.65f + k*(5.f*11.65f);            int count = 0;            int face = l*6+k;            for (int i=0; i<4; i++) {               for (int j=0; j<4; j++) {                  posX = (int)begX + i*12;                  posY = (int)begY + j*12;                  if (x > posX-4 && x < posX+4 &&                      y > posY-4 && y < posY+4) {                     id = faces[face][count+2];                     if (occupied[id] == UNOCCUPIED) {                        positions.set(id, player);                        selection(id, player);                        canvas.repaint();                     }                     return;                  }                  count++;               }            }            if ((x > begX-4  && x < begX+40) &&                 (y > begY+45 && y < begY+60)   ) {               count = 0;               for (int i=0; i<4; i++) {                  for (int j=0; j<4; j++) {                     if (highlight[face])                        positions.clearHighlight(faces[face][count+2]);                     count++;                  }               }               if (highlight[face])                  highlight[face] = false;               else                  highlight[face] = true;               canvas.repaint();            }         }      }   }   /**    *  Record the player's move.    */   public void selection(int pos, int player) {       int num_combinations;      int comb;      this.player = player;      if (player == HUMAN) {         // If position is already occupied, return.         if (occupied[pos] != 0) return;         // Mark the position as HUMAN.         occupied[pos] = HUMAN;         // Update the logic arrays.         this.player = update_logic_arrays(pos);         // Have the computer determine its move.         choose_move();      }   }   /**    *  Determine the computer's move.    */   public void choose_move () {            if (player == MACHINE) {         // Babe in the woods.         if (skill_level == 0) {            if (!block_winning_move()) {               if (!pick_7()) {                  if (!check_outside_four()) {                     pick_best_position();                  }               }            }         }         // Walk and chew gum.         else if (skill_level == 1) {            if (!block_winning_move()) {               if (!block_intersecting_rows()) {                  if (!block_inside_four()) {                     if (!block_outside_four()) {                           pick_best_position();                     }                  }               }            }         }         // Jeopordy contestant.         else if (skill_level == 2) {            if (!block_winning_move()) {               if (!block_intersecting_rows()) {                  if (!block_inside_four()) {                     if (!block_outside_four()) {                        if (!pick_7()) {                           pick_best_position();                        }                     }                  }               }            }         }         // Rocket scientist.         else if (skill_level == 3) {            if (!block_winning_move()) {               if (!block_intersecting_rows()) {                  if (!block_chair_move()) {                     if (!check_face_three()) {                        if (!block_central_four()) {                           if (!block_inside_four()) {                              if (!block_outside_four()) {                                 if (!take_inside_four()) {                                    if (!take_outside_four()) {                                       if (!pick_7()) {                                          if (!check_outside_four()) {                                             pick_best_position();                                          }                                       }                                    }                                 }                              }                           }                        }                     }                  }               }            }         }         // Be afraid, be very afraid.         else if (skill_level == 4) {            if (!block_winning_move()) {               if (!block_intersecting_rows()) {                  if (!block_chair_move()) {                     if (!block_walk_move()) {                        if (!block_central_four()) {                           if (!block_inside_four()) {                              if (!block_outside_four()) {                                 if (!check_face_three()) {                                    if (!check_intersecting_rows2()) {                                       if (!take_inside_four()) {                                          if (!take_outside_four()) {                                             if (!pick_7()) {                                                if (!check_outside_four()) {                                                   pick_best_position();                                                }                                             }                                          }                                       }                                    }                                 }                              }                           }                        }                     }                  }               }            }         }      }   }   /**    *  Check for a winning move.    */   public boolean block_winning_move() {      // Loop through each combination and see if any player occupies       // three positions. If so, take the last remaining position.      int pos;      for (int i=0; i<76; i++) {         if (combinations[i][0] == 3) {            for (int j=2; j<6; j++) {               pos = combinations[i][j];               if (occupied[pos] == 0) {                  occupied[pos] = MACHINE;                  positions.set(pos, MACHINE);                  player = update_logic_arrays(pos);                  if (debug) System.out.println("block_winning_move:  true");                  return true;                 }            }         }      }      if (debug) System.out.println("check_winning_move:  false");      return false;   }   /**    *  Block outside four    */   public boolean block_outside_four() {      int pos;      int index = 0;      int max = 0;      // Block the opponent, if necessary.      for (int i=0; i<18; i++) {         if (outside_four[i][0] > 0 &&             outside_four[i][1] == HUMAN) {            if(outside_four[i][0] > max) {               index = i;               max = outside_four[i][0];            }         }      }      if (max > 0) {         for (int j=2; j<6; j++) {            pos = outside_four[index][j];            if (occupied[pos] == 0) {               occupied[pos] = MACHINE;               positions.set(pos, MACHINE);               player = update_logic_arrays(pos);               if (debug) System.out.println("block_outside_four:  true");               return true;            }         }      }      if (debug) System.out.println("block_outside_four:  false");      return false;   }   /**    *  Block central four    */   public boolean block_central_four() {       int pos;         int index = 0;      int max = 0;       // Block the opponent, if necessary.      for (int i=1; i<3; i++) {         if (inside_four[i][0] > 0 &&             inside_four[i][1] == HUMAN) {            if(inside_four[i][0] > max) {               index = i;               max = inside_four[i][0];            }         }      }          if (max > 0) {         for (int j=2; j<6; j++) {            pos = inside_four[index][j];            if (occupied[pos] == 0) {               occupied[pos] = MACHINE;               positions.set(pos, MACHINE);               player = update_logic_arrays(pos);               if (debug) System.out.println("block_central_four:  true");               return true;            }         }      }          if (debug) System.out.println("block_central_four:  false");      return false;   }    /**       *  Check each face for a forced win.    */      public boolean check_face_three() {           int pos;         int index = 0;      int human = 0;      int machine = 0;

⌨️ 快捷键说明

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