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

📄 staticeval.java

📁 Eclipse高级编程3源码(书本源码)
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
               case SW_B: x++  ; y--  ; currLength++ ; break ;
               case S_B : x--  ; y-=2 ; currLength-- ; maxLength-- ; break ;
               case SE_B: x-=2 ; y--  ; currLength-=2 ; maxLength-=2 ; break ;
               case NE_B: x--  ; y++  ; currLength-- ;  maxLength-- ; break ;
               case N_B : x++  ; y+=2 ; currLength++ ; break ;
               case NW_B: x+=2 ; y++  ; currLength+=2 ; break ;
            }
         }
      }
   }
   // checks for open edge connection from x,y in given direction
   private boolean isOpen(int x,int y,int dir) {

      switch (dir) {
         case NE: 
            switch (y) {
               case 0: return true ;
               case 1: 
                  // for edge bridges the hexes must be empty
                  if ( (x!=0)&&(bd.isEmpty(x-1,0))&&(bd.isEmpty(x,0)) ) return true ;
                  break ;
               case 2: 
                  if ( (x>1)&&(!bd.isBlack(x-1,1))&&(!bd.isBlack(x,1))&&
                       (!bd.isBlack(x-2,0))&&(!bd.isBlack(x-1,0))&&(!bd.isBlack(x,0)) ) {
                     // above is good, now check one side or the other
                     switch (x) {
                        case 2: 
                           if ( (!bd.isBlack(3,2))&&(!bd.isBlack(3,1))&&(!bd.isBlack(3,0)) )
                              return true ;
                           break ;
                        case 6: 
                           if ( (!bd.isBlack(5,2))&&(!bd.isBlack(4,1))&&(!bd.isBlack(3,0)) )
                              return true ;
                           break ;
                        default: 
                           if ( ((!bd.isBlack(x+1,2))&&(!bd.isBlack(x+1,1))&&(!bd.isBlack(x+1,0)))||
                                ((!bd.isBlack(x-1,2))&&(!bd.isBlack(x-2,1))&&(!bd.isBlack(x-3,0))) )
                              return true ;
                           break ;
                     }
                  }
                  break ;
               case 3: 
                  if ( ((x==4)&&(!bd.isBlack(5,3)))||
                       ((x==5)&&(!bd.isBlack(4,3))&&(!bd.isBlack(6,3))) ) {
                     for (int i=2; i<7; i++) if (bd.isBlack(i,2)) return false ;
                     for (int i=1; i<7; i++) if (bd.isBlack(i,1)) return false ;
                     for (int i=0; i<7; i++) if (bd.isBlack(i,0)) return false ;
                     return true ;
                  }
                  break ;
            }
            break ;

         case SW: 
            switch (y) {
               case 3: 
                  if ( ((x==2)&&(!bd.isBlack(1,3)))||
                       ((x==1)&&(!bd.isBlack(0,3))&&(!bd.isBlack(2,3))) ) {
                     for (int i=0; i<5; i++) if (bd.isBlack(i,4)) return false ;
                     for (int i=0; i<6; i++) if (bd.isBlack(i,5)) return false ;
                     for (int i=0; i<7; i++) if (bd.isBlack(i,6)) return false ;
                     return true ;
                  }
                  break ;
               case 4: 
                  if ( (x<5)&&(!bd.isBlack(x,5))&&(!bd.isBlack(x+1,5))&&
                       (!bd.isBlack(x,6))&&(!bd.isBlack(x+1,6))&&(!bd.isBlack(x+2,6)) ) {
                     // below is good, now check one side or the other
                     switch (x) {
                        case 0: 
                           if ( (!bd.isBlack(1,4))&&(!bd.isBlack(2,5))&&(!bd.isBlack(3,6)) )
                              return true ;
                           break ;
                        case 4: 
                           if ( (!bd.isBlack(3,4))&&(!bd.isBlack(3,5))&&(!bd.isBlack(3,6)) )
                              return true ;
                           break ;
                        default: 
                           if ( ((!bd.isBlack(x-1,4))&&(!bd.isBlack(x-1,5))&&(!bd.isBlack(x-1,6)))||
                                ((!bd.isBlack(x+1,4))&&(!bd.isBlack(x+2,5))&&(!bd.isBlack(x+3,6))) )
                              return true ;
                           break ;
                     }
                  }
                  break ;
               // for edge bridges the hexes must be empty
               case 5: if ( (x!=6)&&(bd.isEmpty(x,6))&&(bd.isEmpty(x+1,6)) ) return true ;
                       break ;
               case 6: return true ;
            }
            break ;

         case W: 
            switch (x) {
               case 0: return true ;
               case 1: 
                  // for edge bridges the hexes must be empty
                  if ( (y!=0)&&(bd.isEmpty(0,y-1))&&(bd.isEmpty(0,y)) ) return true ;
                  break ;
               case 2: 
                  if ( (y>1)&&(!bd.isWhite(1,y-1))&&(!bd.isWhite(1,y))&&
                       (!bd.isWhite(0,y-2))&&(!bd.isWhite(0,y-1))&&(!bd.isWhite(0,y)) ) {
                     // left is good, now check one side or the other
                     switch (y) {
                        case 2: 
                           if ( (!bd.isWhite(2,3))&&(!bd.isWhite(1,3))&&(!bd.isWhite(0,3)) )
                              return true ;
                           break ;
                        case 6: 
                           if ( (!bd.isWhite(2,5))&&(!bd.isWhite(1,4))&&(!bd.isWhite(0,3)) )
                              return true ;
                           break ;
                        default: 
                           if ( ((!bd.isWhite(2,y+1))&&(!bd.isWhite(1,y+1))&&(!bd.isWhite(0,y+1)))||
                                ((!bd.isWhite(2,y-1))&&(!bd.isWhite(1,y-2))&&(!bd.isWhite(0,y-3))) )
                              return true ;
                           break ;
                     }
                  }
                  break ;
               case 3: 
                  if ( ((y==4)&&(!bd.isWhite(3,5)))||
                       ((y==5)&&(!bd.isWhite(3,4))&&(!bd.isWhite(3,6))) ) {
                     for (int j=2; j<7; j++) if (bd.isWhite(2,j)) return false ;
                     for (int j=1; j<7; j++) if (bd.isWhite(1,j)) return false ;
                     for (int j=0; j<7; j++) if (bd.isWhite(0,j)) return false ;
                     return true ;
                  }
                  break ;
            }
            break ;

         case E: 
            switch (x) {
               case 3: 
                  if ( ((y==2)&&(!bd.isWhite(3,1)))||
                       ((y==1)&&(!bd.isWhite(3,0))&&(!bd.isWhite(3,2))) ) {
                     for (int j=0; j<5; j++) if (bd.isWhite(4,j)) return false ;
                     for (int j=0; j<6; j++) if (bd.isWhite(5,j)) return false ;
                     for (int j=0; j<7; j++) if (bd.isWhite(6,j)) return false ;
                     return true ;
                  }
                  break ;
               case 4: 
                  if ( (y<5)&&(!bd.isWhite(5,y))&&(!bd.isWhite(5,y+1))&&
                       (!bd.isWhite(6,y))&&(!bd.isWhite(6,y+1))&&(!bd.isWhite(6,y+2)) ) {
                     // right is good, now check one side or the other
                     switch (y) {
                        case 0: 
                           if ( (!bd.isWhite(4,1))&&(!bd.isWhite(5,2))&&(!bd.isWhite(6,3)) )
                              return true ;
                           break ;
                        case 4: 
                           if ( (!bd.isWhite(4,3))&&(!bd.isWhite(5,3))&&(!bd.isWhite(6,3)) )
                              return true ;
                           break ;
                        default: 
                           if ( ((!bd.isWhite(4,y-1))&&(!bd.isWhite(5,y-1))&&(!bd.isWhite(6,y-1)))||
                                ((!bd.isWhite(4,y+1))&&(!bd.isWhite(5,y+2))&&(!bd.isWhite(6,y+3))) )
                              return true ;
                           break ;
                     }
                  }
                  break ;
               // for edge bridges the hexes must be empty
               case 5: if ( (y!=6)&&(bd.isEmpty(6,y))&&(bd.isEmpty(6,y+1)) ) return true ;
                       break ;
               case 6: return true ;
            }
            break ;
      }
      return false ;
   }
   // calculates value for each piece
   //    always calcs area value
   //    calcs bridges & links only if no chains
   private void calcHex() {

      for (int i=0; i<Game.SIZE; i++)
         for (int j=0; j<Game.SIZE; j++)
            if (!bd.isEmpty(i,j)) {

               if (bd.getHex(i,j)==Game.WHITE) {
                  switch (WhiteAreas[i][j]) {
                     case 0: wA0++ ; break ;
                     case 1: wA1++ ; break ;
                     case 2: wA2++ ; break ;
                     case 3: wA3++ ; break ;
                     case 4: wA4++ ; break ;
                  }
                  if (!isChain(Game.WHITE)) calcBridgesLinks(i,j,Game.WHITE) ;
               }
               else {
                  switch (BlackAreas[i][j]) {
                     case 0: bA0++ ; break ;
                     case 1: bA1++ ; break ;
                     case 2: bA2++ ; break ;
                     case 3: bA3++ ; break ;
                     case 4: bA4++ ; break ;
                  }
                  if (!isChain(Game.BLACK)) calcBridgesLinks(i,j,Game.BLACK) ;
               }
            }
   }
   // returns true if any type of chain exists
   private boolean isChain(int color) {
      if (color==Game.WHITE) {
         if ( (isFullChainWhite)||(w5Chain!=0)||(w4Chain!=0)||(w2Chain!=0)||(w1Chain!=0) )
            return true ;
      }
      else {
         if ( (isFullChainBlack)||(b5Chain!=0)||(b4Chain!=0)||(b2Chain!=0)||(b1Chain!=0) )
            return true ;
      }
      return false ;
   }
   // calculates bridges and links for one hex
   private void calcBridgesLinks(int i,int j,int color) {

      calcEdges(i,j,color) ;

      if (calc2Bridge(i,j,color)) {
         if (color==Game.WHITE) {
            calc1BridgeRight(i,j,color) ;
            if (!calc1BridgeLeft(i,j,color)) calc0Link(i,j,color) ;
         }
         else {
            calc1BridgeLeft(i,j,color) ;
            if (!calc1BridgeRight(i,j,color)) calc0Link(i,j,color) ;
         }
      }
      else {
         if (color==Game.WHITE) {
            if (!calc1BridgeRight(i,j,color)) calc1LinkRight(i,j,color) ;
            if (!calc1BridgeLeft(i,j,color)) calc1LinkLeft(i,j,color) ;
            calc0Link(i,j,color) ;
         }
         else {
            if (!calc1BridgeLeft(i,j,color)) calc1LinkLeft(i,j,color) ;
            if (!calc1BridgeRight(i,j,color)) calc1LinkRight(i,j,color) ;
            calc0Link(i,j,color) ;
         }
      }
   }
   // calculates edge connections for one hex
   private void calcEdges(int i,int j,int color) {
      if (color==Game.WHITE) {
         if ( ((j==0)&&(i!=(Game.SIZE-1))) || ((j==(Game.SIZE-1))&&(i!=0)) ) w1Edge++ ;
         else if ( (j==1)&&(isOpen(i,j,NE)) ) w2Edge++ ;
         else if ( (j==(Game.SIZE-2))&&(isOpen(i,j,SW)) ) w2Edge++ ;
      } else {
         if ( ((i==0)&&(j!=(Game.SIZE-1))) || ((i==(Game.SIZE-1))&&(j!=0)) ) b1Edge++ ;
         else if ( (i==1)&&(isOpen(i,j,W)) ) b2Edge++ ;
         else if ( (i==(Game.SIZE-2))&&(isOpen(i,j,E)) ) b2Edge++ ;
      }
   }
   private boolean calc2Bridge(int i,int j,int color) {
      if (color==Game.WHITE) {
         if (bd.isBridgeS(i,j,Game.WHITE)) { w2Bridge++ ; return true ; }
      } 
      else if (bd.isBridgeSE(i,j,Game.BLACK)) { b2Bridge++ ; return true ; }
      return false ;
   }
   private boolean calc1BridgeLeft(int i,int j,int color) {
      if (color==Game.WHITE) {
         if (bd.isBridgeSE(i,j,Game.WHITE)) { w1Bridge++ ; return true ; }
      } 
      else if (bd.isBridgeNE(i,j,Game.BLACK)) { b1Bridge++ ; return true ; }
      return false ;
   }
   private boolean calc1BridgeRight(int i,int j,int color) {
      if (color==Game.WHITE) {
         if (bd.isBridgeSW(i,j,Game.WHITE)) { w1Bridge++ ; return true ; }
      } 
      else if (bd.isBridgeS(i,j,Game.BLACK)) { b1Bridge++ ; return true ; }
      return false ;
   }
   private boolean calc1LinkLeft(int i,int j,int color) {
      if (color==Game.WHITE) {
         if (bd.isLinkSE(i,j,Game.WHITE)) { w1Link++ ; return true ; }
      }
      else if (bd.isLinkE(i,j,Game.BLACK)) { b1Link++ ; return true ; }
      return false ;
   }
   private boolean calc1LinkRight(int i,int j,int color) {
      if (color==Game.WHITE) { 
         if (bd.isLinkSW(i,j,Game.WHITE)) { w1Link++ ; return true ; } 
      }
      else if (bd.isLinkSE(i,j,Game.BLACK)) { b1Link++ ; return true ; }
      return false ;
   }
   private void calc0Link(int i,int j,int color) {
      if (color==Game.WHITE) { if (bd.isLinkE(i,j,Game.WHITE)) w0Link++ ; } 
      else if (bd.isLinkSW(i,j,Game.BLACK)) b0Link++ ;
   }
}

⌨️ 快捷键说明

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