亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? knightstour.java

?? 課程設計案例精編光盤源碼 課程設計案例精編光盤源碼
?? JAVA
字號:
import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.awt.image.*;public class KnightsTour extends JApplet {   public static int access[][] = {      {2,3,4,4,4,4,3,2},      {3,4,6,6,6,6,4,3},      {4,6,8,8,8,8,6,4},      {4,6,8,8,8,8,6,4},      {4,6,8,8,8,8,6,4},      {4,6,8,8,8,8,6,4},      {3,4,6,6,6,6,4,3},      {2,3,4,4,4,4,3,2}};   public static int accessbak[][] = arrayCopy ( access ) ;   // the value indicate the No.value moving   int countMoving = -1 ;   int tourXpos [] = new int [ 64 ];   int tourYpos [] = new int [ 64 ];   private int recordXpos [][];   private int recordYpos [][];   private int recordCount = - 1 ;   private int startx ;   private int starty ;   private boolean success = false;   MyPanel myPanel ;   public void tour ( int xpos ,int ypos ){//      int x,y;      countMoving ++ ;      //all the  64 squares has been touch , return      if (countMoving == 63 )      {         tourXpos [ countMoving ] = xpos ;         tourYpos [ countMoving ] = ypos ;//         if ( ( ( Math.abs( xpos -startx ) == 1)  & ( Math.abs ( ypos - starty ) ==2 ) ) |  //            ( ( Math.abs( xpos -startx ) == 2)  & ( Math.abs ( ypos - starty ) ==1 ) ) )         success = true ;         countMoving -- ;         return ;      }      AccessibleSquares nextSquare = new AccessibleSquares( xpos, ypos );      while (nextSquare.hasMoreAccessible())      {         // do moving         nextSquare.domoving();         //record this moving         tourXpos [ countMoving ] = xpos ;         tourYpos [ countMoving ] = ypos ;         // try the next moving         nextSquare.nextAccessible();         tour ( nextSquare.getXpos() , nextSquare.getYpos() );         //all the  64 squares has been touch , return         if ( success )         {            countMoving -- ;            return ;         }         //this moving try is a faillure, pick it up from the chess board         nextSquare.undomoving();      }// end of while      countMoving -- ;   }//end of tour method   public static int[] arrayCopy ( int array1[] )   {     int[]array2 = new int [array1.length];     for ( int row = 0 ; row < array1.length ; row ++ )     {          array2 [ row ] = array1  [ row ] ;     };     return array2;   }   public static int[][] arrayCopy ( int array1[][]  )   {      int[][] array2 = new int [array1.length][array1[0].length];     for ( int row = 0 ; row < array1.length ; row ++ )     {        for ( int column = 0 ; column < array1[0].length ; column ++ )        {          array2 [ row ][ column ] = array1  [ row ][ column ];        };     };     return array2;   }   public void initialArray ( int chessBoard[][]  )   {     for ( int row = 0 ; row < 8 ; row ++ )     {        for ( int column = 0 ; column < 8 ; column ++ )        {          chessBoard [ row ][ column ] = 0 ;        };     };   }/*   public static void main( String args[] ) {      KnightsTour application = new KnightsTour();      application.tour( 0 , 0 );   }*/   public void init () {      recordCount = -1 ;      recordXpos = new int [ 64 ][ 64 ] ;      recordYpos = new int [ 64 ][ 64 ] ;      for (int row = 0 ; row < 8 ;row ++){         for ( int column = 0 ; column < 8 ; column ++ ){            success = false ;            countMoving = -1;            startx = row ;            starty = column ;            access = arrayCopy ( accessbak );            tour ( row ,column );            recordCount ++ ;            recordXpos [ recordCount ] = arrayCopy ( tourXpos ) ;            recordYpos [ recordCount ] = arrayCopy ( tourYpos ) ;         }      }      recordCount = 0 ;      myPanel = new MyPanel( recordXpos [ 0 ] ,recordYpos [ 0 ]) ;      JPanel buttonPanel = new JPanel();      JButton nextMoving = new JButton( "Next Moving" );      JButton nextTour = new JButton( "Next Tour" );      buttonPanel.add( nextTour );      buttonPanel.add( nextMoving );      getContentPane().add( buttonPanel, BorderLayout.SOUTH );      getContentPane().add( myPanel );      nextMoving.addActionListener(         //anonymous inner class         new ActionListener() {            public void actionPerformed ( ActionEvent e ) {               myPanel.showNext() ;            }         }         );//end call to addActionListener         nextTour.addActionListener(            //anonymous inner class            new ActionListener() {               public void actionPerformed ( ActionEvent e ) {                  if ( recordCount < recordXpos.length - 1 ) {                     recordCount ++ ;                  } else {                     recordCount = 0 ;                  }                  myPanel.initboard ( recordXpos [ recordCount ] , recordYpos [ recordCount ] );                  myPanel.repaint();               }            }            );//end call to addActionListener   }   public void paint (Graphics g )   {      super.paint( g );   }}//end of class KnightsTourclass AccessibleSquares {   private static int horizontal[] = {2,1,-1,-2,-2,-1,1,2};   private static int vertical  [] = {-1,-2,-2,-1,1,2,2,1};   private int xpos[] ;   private int ypos[] ;   private int accessibility [];   private int ownxpos ,ownypos ;   private int ownAccessibility ;   private int arrayPos ;   private int countAccessibility;   public AccessibleSquares(int x , int y ){      int testXPos;      int testYPos;      xpos = new int [ 8 ];      ypos = new int [ 8 ];      accessibility = new int [ 8 ];      arrayPos = 0 ;      ownxpos = x ;      ownypos = y ;      ownAccessibility = KnightsTour.access[ x ][ y ];      for (int i = 0 ; i < horizontal.length ; i++ ){         testXPos = x + horizontal[ i ];         testYPos = y + vertical  [ i ];         if ( (testXPos >= 0 ) & ( testXPos < 8 ) &              (testYPos >= 0 ) & ( testYPos < 8 ) ) {            xpos [ arrayPos ] = testXPos ;            ypos [ arrayPos ] = testYPos ;            accessibility [ arrayPos ] = KnightsTour.access [testXPos][testYPos];            //because  accessibility [ arrayPos ] = 0 indicating the square has been occupied            if (accessibility [ arrayPos ] > 0 )               arrayPos ++ ;         }//end of if      }// end of for      countAccessibility = arrayPos ;      if (countAccessibility > 0 )         {sortAll();}      arrayPos = -1 ;   }// end of constructor   public boolean hasMoreAccessible(){      // arrayPos + 1 point to the next accessible      if ( (arrayPos + 1 ) < countAccessibility ){         return true;      }else {         return false;      }   }//end of the hasMoreAccessible()   public AccessibleSquares nextAccessible(){      arrayPos ++ ;      return this;   }   public AccessibleSquares accessibleAt( int pos){      if ((pos >= 0) & (pos < countAccessibility ))      arrayPos = pos ;      return this;   }   public int getXpos(){      return xpos[ arrayPos ];   }   public int getYpos(){      return ypos[ arrayPos ];   }   public int getAccessibility(){      return accessibility[ arrayPos ];   }   public int getTotalAccessible(){      return countAccessibility;   }   //bubble sorting   private void sortAll (){      for ( int begin = 0 ; begin < countAccessibility - 1 ; begin ++ ){         for ( int i = begin + 1; i < countAccessibility ; i ++ ){            if ( accessibility [ begin ] > accessibility [ i ] ){               swapAll( begin, i );            }//end of if         }// end of inner for      }// end of outer for   }// end of sortAll   private void swapAll ( int i , int j ){      int temp ;      temp = xpos [ i ];      xpos [ i ] = xpos [ j ];      xpos [ j ] = temp;      temp = ypos [ i ];      ypos [ i ] = ypos [ j ];      ypos [ j ] = temp;      temp = accessibility [ i ];      accessibility [ i ] = accessibility [ j ];      accessibility [ j ] = temp;   }   public void domoving(){      for ( int i = 0 ; i < countAccessibility ; i ++ ){         KnightsTour.access[ xpos [i] ][ ypos[i] ] -- ;      }       KnightsTour.access[ ownxpos ][ ownypos ] = 0 ;   }   public void undomoving(){      for ( int i = 0 ; i < countAccessibility ; i ++ ){         KnightsTour.access[ xpos [i] ][ ypos[i] ] ++ ;      }      KnightsTour.access[ ownxpos ][ ownypos ] = ownAccessibility ;   }}class MyPanel extends JPanel {   public static final int WHITE = 0 ;   public static final int BLACK = 1 ;   public static final int WKNIGHT = 2 ;   public static final int BKNIGHT = 3 ;   private int chessboard[][];   private int xrecord [] ;   private int yrecord [] ;   private int displayCount ;   private int lastxpos ,lastypos ,nextxpos ,nextypos ;   ImageIcon images[] ;   private boolean start ;   public MyPanel() {      initvariance();   }   public MyPanel( int [] newxrecord ,int [] newyrecord ) {      initvariance();      initboard( newxrecord , newyrecord );   }   public void initvariance () {      chessboard = new int[ 8 ][ 8 ];      xrecord = new int [ 64 ] ;      yrecord = new int [ 64 ];      images = new ImageIcon [ 4 ];      images[ 0 ] = new ImageIcon( "white.jpg");      images[ 1 ] = new ImageIcon( "black.jpg");      images[ 2 ] = new ImageIcon( "wknight.jpg");      images[ 3 ] = new ImageIcon( "bknight.jpg");   }   public void initboard ( int [] newxrecord ,int [] newyrecord ){      start = true ;      displayCount = -1 ;      for (int row = 0 ; row < 8 ;row ++){         for ( int column = 0 ; column < 8 ; column ++ ){            // white use 0 ,black use 1            chessboard [ row ][ column ] = ( row + column ) % 2 ;         }      }//end of outer for      for ( int row = 0 ; row < newxrecord .length ; row ++ ) {         xrecord [ row ] = newxrecord [ row ] ;         yrecord [ row ] = newyrecord [ row ] ;      }      displayCount = 0 ;      chessboard [ xrecord [ displayCount ] ][ yrecord [ displayCount ] ] += 2 ;   }//end of initboard   public void showNext() {      if ( displayCount < xrecord.length - 1 ){         displayCount ++ ;         chessboard [ xrecord [ displayCount ] ][ yrecord [ displayCount ] ] += 2 ;         repaint();      }   }   public void paintComponent ( Graphics g ) {      for (int row = 0 ; row < 8 ;row ++){         for ( int column = 0 ; column < 8 ; column ++ ){            images[ chessboard[ row ][ column ] ].paintIcon( this , g, 40 * row,40 * column );         }//end of inner for      }//end of outer for      if ( displayCount > 0 ){         lastxpos = xrecord [ displayCount  - 1];         lastypos = yrecord [ displayCount  - 1];         nextxpos = xrecord [ displayCount ];         nextypos = yrecord [ displayCount ];         g.setColor( Color.green);         g.drawRect( 40 * xrecord [ displayCount - 1 ] + 2,40 * yrecord [ displayCount - 1 ] + 2, 36, 36 );         g.setColor( Color.green);         g.drawRect( 40 * xrecord [ displayCount ] + 2 ,40 * yrecord [ displayCount ] + 2, 36, 36 );         g.setColor( Color.blue);         g.drawRect( 40 * Math.min( nextxpos, lastxpos ),            40 * Math.min( nextypos, lastypos ),            ( Math.abs( nextxpos - lastxpos ) + 1 ) * 40,            ( Math.abs( nextypos - lastypos ) + 1 ) * 40 );      }//end of if      g.setColor( Color.red );      g.drawRect ( 40 * xrecord [ 0 ] + 2,40 * yrecord [ 0 ] + 2, 36, 36 ) ;   }// end of the method paintComponent}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久尤物电影视频在线观看| 色综合天天性综合| 日韩区在线观看| 日本色综合中文字幕| 日韩一区二区三区观看| 国模娜娜一区二区三区| 国产日本亚洲高清| 91香蕉视频污在线| 水野朝阳av一区二区三区| 6080午夜不卡| 国产精品一品二品| 亚洲黄色免费电影| 欧美一区二区三区免费| 国产在线精品一区二区| 欧美激情资源网| 色94色欧美sute亚洲线路二| 午夜精品久久久久影视| 欧美mv日韩mv| 成人免费毛片高清视频| 一区二区三区在线观看国产 | 亚洲国产综合在线| 91精品国产综合久久婷婷香蕉| 一区二区三区色| 精品日本一线二线三线不卡| 暴力调教一区二区三区| 婷婷中文字幕综合| 国产日本欧美一区二区| 欧美伦理电影网| av午夜一区麻豆| 美腿丝袜亚洲三区| 综合久久给合久久狠狠狠97色| 欧美一区日本一区韩国一区| 不卡av在线免费观看| 美女www一区二区| 一二三四区精品视频| 久久久久九九视频| 欧美日韩美少妇| 波波电影院一区二区三区| 日韩成人一区二区三区在线观看| 国产精品欧美一级免费| 欧美电影免费提供在线观看| 色哟哟一区二区三区| 久久国产精品区| 国产精品视频一二三区| 日韩一区二区三区在线观看| 在线观看精品一区| 岛国一区二区在线观看| 免费看精品久久片| 亚洲一卡二卡三卡四卡五卡| 国产精品沙发午睡系列990531| 欧美一级xxx| 日本韩国一区二区| 丁香一区二区三区| 国产做a爰片久久毛片| 亚洲黄色尤物视频| 国产精品不卡在线| 久久久久久免费毛片精品| 日韩午夜激情免费电影| 欧美综合欧美视频| 成人性生交大片免费| 国模娜娜一区二区三区| 久久成人精品无人区| 日韩精品久久久久久| 亚洲国产精品天堂| 亚洲图片欧美色图| 亚洲综合色区另类av| 最新热久久免费视频| 国产日韩欧美一区二区三区乱码| 精品少妇一区二区三区免费观看 | 亚洲综合av网| 亚洲人精品一区| 国产午夜精品福利| 日本一区二区三区国色天香| 国产无一区二区| 国产日韩欧美a| 国产精品盗摄一区二区三区| 中文字幕精品一区二区三区精品| 国产日产精品一区| 亚洲欧洲成人精品av97| 亚洲天堂成人在线观看| 亚洲欧美日韩电影| 亚洲成人免费看| 免费一级欧美片在线观看| 久久激情综合网| 国产精品一线二线三线精华| 国产成人99久久亚洲综合精品| 国产福利一区在线观看| www.色综合.com| 在线精品视频小说1| 51午夜精品国产| 久久亚洲影视婷婷| 亚洲欧洲精品一区二区三区不卡| 亚洲人成网站精品片在线观看| 亚洲在线视频网站| 三级不卡在线观看| 国产一区福利在线| 白白色亚洲国产精品| 欧美日韩中文精品| 精品美女一区二区| 国产精品视频九色porn| 亚洲一区二区视频在线观看| 日韩av成人高清| 国产传媒日韩欧美成人| 91官网在线观看| 日韩精品中文字幕在线一区| 国产日韩欧美a| 亚洲国产另类av| 国内欧美视频一区二区| 成人免费高清在线观看| 欧美麻豆精品久久久久久| 久久久久久久久久久电影| 亚洲免费在线看| 国内欧美视频一区二区| 色又黄又爽网站www久久| 日韩欧美视频一区| 亚洲视频1区2区| 美日韩黄色大片| 色婷婷综合视频在线观看| 日韩精品一区在线观看| 亚洲欧洲综合另类| 国产在线精品一区二区不卡了| 色婷婷久久综合| 久久综合999| 三级一区在线视频先锋| av亚洲精华国产精华精| 欧美不卡一区二区三区四区| 亚洲最大的成人av| 国产成人精品免费视频网站| 欧美一区欧美二区| 亚洲精品少妇30p| 国产成人av电影| 日韩欧美在线123| 亚洲最新视频在线播放| 成人小视频免费观看| 欧美一区二区三区四区高清| 一区二区在线观看不卡| 国产一区二区三区免费看| 欧美色大人视频| 亚洲男帅同性gay1069| 国产高清不卡一区二区| 日韩免费视频一区| 午夜免费欧美电影| 91在线视频在线| 国产视频一区二区在线观看| 美女在线视频一区| 欧美精品久久99久久在免费线| 亚洲视频资源在线| 丁香婷婷综合激情五月色| 精品va天堂亚洲国产| 日韩国产精品久久久| 欧美亚洲综合网| 亚洲丝袜制服诱惑| 国产精品综合av一区二区国产馆| 日韩一区二区三区电影| 日韩国产欧美在线播放| 欧美精品粉嫩高潮一区二区| 亚洲福利视频一区二区| 一本久久综合亚洲鲁鲁五月天| 欧美国产一区在线| 国产成人精品www牛牛影视| 久久亚区不卡日本| 国产一区二区久久| 久久精品视频在线看| 国产乱妇无码大片在线观看| 亚洲精品在线免费播放| 捆绑调教一区二区三区| 日韩一级精品视频在线观看| 美女高潮久久久| 久久免费午夜影院| 成人中文字幕电影| 亚洲国产成人私人影院tom| 成人午夜在线播放| 亚洲欧美日韩中文播放| 色94色欧美sute亚洲线路二| 一区二区三区精品| 欧美精选午夜久久久乱码6080| 日韩电影一二三区| 欧美成人a∨高清免费观看| 国产精品99久久久久久宅男| 国产精品天天看| 色婷婷综合视频在线观看| 亚洲国产视频一区二区| 欧美高清视频一二三区| 美美哒免费高清在线观看视频一区二区| 日韩视频一区二区三区| 国产成人精品亚洲日本在线桃色| 中文字幕一区二区三区在线播放| 色综合中文字幕| 丝袜诱惑制服诱惑色一区在线观看| 欧美一区二区在线观看| 国产精品伊人色| 亚洲激情综合网| 91精品黄色片免费大全| 国产精品一区二区91| 亚洲最新视频在线播放| 日韩视频在线一区二区| 波多野结衣在线aⅴ中文字幕不卡| 亚洲综合免费观看高清在线观看| 欧美精品乱人伦久久久久久| 国产在线视频不卡二|