算法是窮舉遞歸法,只不過用java重新寫了一遍
import java.awt.Color; import java.awt.Container; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.ButtonGroup; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JRadioButtonMenuItem; import javax.swing.SwingUtilities; import javax.swing.UIManager; /* *main方法創建了ChessFrame類的一個實例對象(cf), *並啓動屏幕顯示顯示該實例對象。 * **/ public class wuziqi { public static void main(String args[]) { ChessFrame cf = new ChessFrame(); cf.setVisible(true); } }; /* *類ChessFrame主要功能是創建五子棋遊戲主窗體和菜單 **/ class ChessFrame extends JFrame implements ActionListener { private static final long serialVersionUID = 2183726320279905885L; private String[] strmode={"人機對弈","人人對弈"}; private String[] strorder={"玩家先手","計算機先手"}; public static boolean iscomputer=true; public static boolean checkcomputer=true; public static boolean isorder=true; private int width=15,height=15; private ChessModel cm; private MainPanel mp; public static int qipan[][]=new int[15][15]; //構造五子棋遊戲的主窗體 public ChessFrame() { this.setTitle("五子棋遊戲"); cm=new ChessModel(1); mp=new MainPanel(cm); Container con=this.getContentPane(); con.add(mp,"Center"); this.setResizable(false); this.addWindowListener(new ChessWindowEvent()); MapSize(14,14); setLocation(400,100); JMenuBar mbar = new JMenuBar(); this.setJMenuBar(mbar); JMenu gameMenu = new JMenu("遊戲"); mbar.add(makeMenu(gameMenu, new Object[] { "開局","模式","先手順序","悔棋", null, "退出" }, this)); JMenu lookMenu =new JMenu("視圖"); mbar.add(makeMenu(lookMenu,new Object[] { "Metal","Motif","Windows" },this)); JMenu helpMenu = new JMenu("幫助"); mbar.add(makeMenu(helpMenu, new Object[] { "關於" }, this)); } //構造五子棋遊戲的主菜單 public JMenu makeMenu(Object parent, Object items[], Object target) { JMenu m = null; if(parent instanceof JMenu) m = (JMenu)parent; else if(parent instanceof String) m = new JMenu((String)parent); else return null; for(int i = 0; i < items.length; i++) if(items[i] == null) m.addSeparator(); else if(items[i] == "模式") { JMenu jm = new JMenu("模式"); ButtonGroup group=new ButtonGroup(); JRadioButtonMenuItem rmenu; for(int h=0;h<strmode.length;h++) { rmenu=makeRadioButtonMenuItem(strmode[h],target); if(h==0) rmenu.setSelected(true); jm.add(rmenu); group.add(rmenu); } m.add(jm); } else if(items[i]=="先手順序") { JMenu jm = new JMenu("先手順序"); ButtonGroup group=new ButtonGroup(); JRadioButtonMenuItem rmenu; for(int k=0;k<strorder.length;k++) { rmenu=makeRadioButtonMenuItem(strorder[k],target); if(k==0) rmenu.setSelected(true); jm.add(rmenu); group.add(rmenu); } m.add(jm); } else m.add(makeMenuItem(items[i], target)); return m; } //構造五子棋遊戲的菜單項 public JMenuItem makeMenuItem(Object item, Object target){ JMenuItem r = null; if(item instanceof String) r = new JMenuItem((String)item); else if(item instanceof JMenuItem) r = (JMenuItem)item; else return null; if(target instanceof ActionListener) r.addActionListener((ActionListener)target); return r; } //構造五子棋遊戲的單選按鈕式菜單項 public JRadioButtonMenuItem makeRadioButtonMenuItem( Object item, Object target){ JRadioButtonMenuItem r = null; if(item instanceof String) r = new JRadioButtonMenuItem((String)item); else if(item instanceof JRadioButtonMenuItem) r = (JRadioButtonMenuItem)item; else return null; if(target instanceof ActionListener) r.addActionListener((ActionListener)target); return r; } public void MapSize(int w,int h){ setSize(w * 30+67 , h * 30+110); if(!ChessFrame.checkcomputer) { ChessFrame.iscomputer=false; } else { ChessFrame.iscomputer=true; } mp.setModel(cm); mp.repaint(); } public boolean getiscomputer(){ return ChessFrame.iscomputer; } public void restart(){ int modeChess = cm.getModeChess(); if(modeChess <= 3 && modeChess >= 1){ cm = new ChessModel(modeChess); MapSize(cm.getWidth(),cm.getHeight()); System.out.println("/u81EA/u5B9A/u4E49"); } } public void actionPerformed(ActionEvent e){ String arg=e.getActionCommand(); try{ if (arg.equals("Windows")) UIManager.setLookAndFeel( "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); else if(arg.equals("Motif")) UIManager.setLookAndFeel( "com.sun.java.swing.plaf.motif.MotifLookAndFeel"); else UIManager.setLookAndFeel( "javax.swing.plaf.metal.MetalLookAndFeel" ); SwingUtilities.updateComponentTreeUI(this); }catch(Exception ee){} if(arg.equals("人機對弈")){ ChessFrame.checkcomputer=true; ChessFrame.iscomputer=true; cm=new ChessModel(cm.getModeChess()); MapSize(cm.getWidth(),cm.getHeight()); SwingUtilities.updateComponentTreeUI(this); } if(arg.equals("人人對弈")){ ChessFrame.checkcomputer=false; ChessFrame.iscomputer=false; cm=new ChessModel(cm.getModeChess()); MapSize(cm.getWidth(),cm.getHeight()); SwingUtilities.updateComponentTreeUI(this); } if(arg.equals("計算機先手")) { ChessFrame.isorder=false; cm=new ChessModel(cm.getModeChess()); MapSize(cm.getWidth(),cm.getHeight()); SwingUtilities.updateComponentTreeUI(this); } if(arg.equals("玩家先手")) { ChessFrame.isorder=true; cm=new ChessModel(cm.getModeChess()); MapSize(cm.getWidth(),cm.getHeight()); SwingUtilities.updateComponentTreeUI(this); } if(arg.equals("開局")){ restart(); if(ChessFrame.isorder==false) cm.first(); } if(arg.equals("悔棋")){ int modeChess = cm.getModeChess(); if(modeChess <= 3 && modeChess >= 1){ cm = new ChessModel(modeChess); for(int i=0;i<this.width;i++) { for(int j=0;j<this.height;j++) { cm.arrMapShow[i][j] =qipan[i][j]; } } MapSize(cm.getWidth(),cm.getHeight()); } } if(arg.equals("關於")) JOptionPane.showMessageDialog(this, "五子棋遊戲測試版本——By 江西財經大學08計一張帥", "關於", 0); if(arg.equals("退出")) System.exit(0); } } /* *類ChessModel實現了整個五子棋程序算法的核心 */ class ChessModel { //棋盤的寬度、高度、棋盤的模式(如20×15) private int width=15; private int modeChess; //棋盤方格的橫向、縱向座標 private int x=0,y=0; private int temp1; private int temp2; private int temp3; private int temp4; int[][] arrMapShow; //交換棋手的標識,棋盤方格上是否有棋子的標識符,先手順序的標識 private boolean isOdd,isExist; private ChessFrame cf; //1表示黑棋 ,2表示白棋,-1表示空白可下處 public ChessModel() {} //該構造方法根據不同的棋盤模式(modeChess)來構建對應大小的棋盤 public ChessModel(int modeChess){ this.isOdd=true; if(modeChess == 1){ PanelInit(14, 14, modeChess); } } //按照棋盤模式構建棋盤大小 private void PanelInit(int width, int height, int modeChess){ this.width = width; this.modeChess = modeChess; arrMapShow = new int[width+1][height+1]; for(int i = 0; i <=width; i++){ for(int j = 0; j <=height; j++){ arrMapShow[i][j] = -1; } } } //獲取是否交換棋手的標識符 public boolean getisOdd(){ return this.isOdd; } //設置交換棋手的標識符 public void setisOdd(boolean isodd){ if(isodd) this.isOdd=true; else this.isOdd=false; } //獲取某棋盤方格是否有棋子的標識值 public boolean getisExist(){ return this.isExist; } //獲取棋盤寬度 public int getWidth(){ return this.width; } //獲取棋盤高度 public int getHeight(){ return this.width; } //獲取棋盤模式 public int getModeChess(){ return this.modeChess; } //獲取棋盤方格上棋子的信息 public int[][] getarrMapShow(){ return arrMapShow; } //判斷下子的橫向、縱向座標是否越界 private boolean badxy(int x, int y){ if(x >= width+30 || x < 0) return true; return y >= width+30 || y < 0; } //計算棋盤上某一方格上八個方向棋子的最大值, //這八個方向分別是:左、右、上、下、左上、左下、右上、右下 public boolean chessExist(int i,int j){ if(this.arrMapShow[i][j]==1 || this.arrMapShow[i][j]==2) return true; return false; } //判斷該座標位置是否可下棋子 // public void readyplay(int x,int y){ // if(badxy(x,y)) // return; // if (chessExist(x,y)) // return; // this.arrMapShow[x][y]=3; // } //在該座標位置下棋子 public void play(int x,int y){ if(badxy(x,y)) return; if(chessExist(x,y)){ this.isExist=true; return; }else this.isExist=false; if(getisOdd()){ setisOdd(false); this.arrMapShow[x][y]=1; }else{ setisOdd(true); this.arrMapShow[x][y]=2; } } //計算機走棋 /* *說明:用窮舉法判斷每一個座標點的四個方向的的最大棋子數, *最後得出棋子數最大值的座標,下子 **/ void computerDo(int flag) { int max_black,max_white,count=0,max=0,max_temp,level,x[] ={-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2},y[]={-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2},i,j; setisOdd(true); for(i = 0; i < width; i++) { for(j = 0; j < width; j++) { if(this.arrMapShow[i][j]==-1) {//算法判斷是否下子 if(lian_si(i,j,2)||duan_lian_si(i,j,2)) { level=43; x[level]=i; y[level]=j; } else { if(lian_si(i,j,1)||duan_lian_si(i,j,1)) { level=42; x[level]=i; y[level]=j; } else { if(si_si(i,j,2)&&zhouwei3(i,j,2)||si_san(i,j,2)&&zhouwei3(i,j,2)) { level=41; x[level]=i; y[level]=j; } else { if(si_si(i,j,2)&&zhouwei2(i,j,2)||si_san(i,j,2)&&zhouwei2(i,j,2)) { level=40; x[level]=i; y[level]=j; } else { if(si_si(i,j,2)&&zhouwei1(i,j,2)||si_san(i,j,2)&&zhouwei1(i,j,2)) { level=39; x[level]=i; y[level]=j; } else { if(si_si(i,j,2)||si_san(i,j,2)) { level=38; x[level]=i; y[level]=j; } else { if(huo_lian_san(i,j,1)&&huo_lian_san(i,j,2)) { level=37; x[level]=i; y[level]=j; } else { if(huo_lian_san(i,j,2)&&huo_duan_er(i,j,2)||huo_lian_san(i,j,2)&&huo_er(i,j,2)) { level=36; x[level]=i; y[level]=j; } else { if(huo_lian_san(i,j,2)&&zhouwei3(i,j,2)||duan_lian_san(i,j,2)&&zhouwei3(i,j,2)) { level=35; x[level]=i; y[level]=j; } else { if(huo_lian_san(i,j,2)&&zhouwei2(i,j,2)||duan_lian_san(i,j,2)&&zhouwei2(i,j,2)) { level=34; x[level]=i; y[level]=j; } else { if(huo_lian_san(i,j,2)&&zhouwei1(i,j,2)||duan_lian_san(i,j,2)&&zhouwei1(i,j,2)) { level=33; x[level]=i; y[level]=j; } else { if(huo_lian_san(i,j,2)||duan_lian_san(i,j,2)) { level=32; x[level]=i; y[level]=j; } else { if(si_si(i,j,1)&&zhouwei3(i,j,1)||si_san(i,j,1)&&zhouwei3(i,j,1)) { level=31; x[level]=i; y[level]=j; } else { if(si_si(i,j,1)&&zhouwei2(i,j,1)||si_san(i,j,1)&&zhouwei2(i,j,1)) { level=30; x[level]=i; y[level]=j; } else { if(si_si(i,j,1)&&zhouwei1(i,j,1)||si_san(i,j,1)&&zhouwei1(i,j,1)) { level=29; x[level]=i; y[level]=j; } else { if(si_si(i,j,1)||si_san(i,j,1)) { level=28; x[level]=i; y[level]=j; } else { if(huo_lian_san(i,j,1)&&huo_er(i,j,2)||huo_lian_san(i,j,1)&&huo_duan_er(i,j,2)) { level=27; x[level]=i; y[level]=j; } else { if(huo_lian_san(i,j,1)&&zhouwei3(i,j,1)||duan_lian_san(i,j,1)&&zhouwei3(i,j,1)) { level=26; x[level]=i; y[level]=j; } else { if(huo_lian_san(i,j,1)&&zhouwei2(i,j,1)||duan_lian_san(i,j,1)&&zhouwei2(i,j,1)) { level=25; x[level]=i; y[level]=j; } else { if(huo_lian_san(i,j,1)&&zhouwei1(i,j,1)||duan_lian_san(i,j,1)&&zhouwei1(i,j,1)) { level=24; x[level]=i; y[level]=j; } else { if(huo_lian_san(i,j,1)||duan_lian_san(i,j,1)) { level=23; x[level]=i; y[level]=j; } else { if(lian_duan_si(i,j,2)&&huo_er(i,j,2)||lian_duan_si(i,j,2)&&huo_lian_san(i,j,2)||lian_duan_si(i,j,2)&&huo_duan_er(i,j,2)||si_lian_san(i,j,2)&&huo_er(i,j,2)||si_lian_san(i,j,2)&&huo_lian_san(i,j,2)||si_lian_san(i,j,2)&&huo_duan_er(i,j,2)) { level=22; x[level]=i; y[level]=j; } else { if(san_san(i,j,2)) { level=21; x[level]=i; y[level]=j; } else { if((huo_er(i,j,2)&&san_san(i,j,1))||(huo_duan_er(i,j,2)&&san_san(i,j,1))) { level=20; x[level]=i; y[level]=j; } else { if(san_san(i,j,1)) { level=19; x[level]=i; y[level]=j; } else { if(lian_duan_si(i,j,1)&&huo_er(i,j,1)||lian_duan_si(i,j,1)&&huo_lian_san(i,j,1)||lian_duan_si(i,j,1)&&huo_duan_er(i,j,1)||si_lian_san(i,j,1)&&huo_er(i,j,1)||si_lian_san(i,j,1)&&huo_lian_san(i,j,1)||si_lian_san(i,j,1)&&huo_duan_er(i,j,1)) { level=18; x[level]=i; y[level]=j; } else { if(si_lian_san(i,j,2)||lian_duan_si(i,j,2)) { level=17; x[level]=i; y[level]=j; } else { if(huo_er(i,j,2)&&shi_zi_er(i,j,2)) { level=16; x[level]=i; y[level]=j; } else { if((huo_er(i,j,2)&&huo_er(i,j,1))||(huo_duan_er(i,j,2)&&huo_er(i,j,1))||(huo_duan_er(i,j,2)&&huo_duan_er(i,j,1))||(huo_er(i,j,2)&&huo_duan_er(i,j,1))) { level=15; x[level]=i; y[level]=j; } else { if((huo_er(i,j,2)&&si_er(i,j,2))||(huo_er(i,j,2)&&si_er(i,j,1))) { level=14; x[level]=i; y[level]=j; } else { if(huo_er(i,j,2)||huo_duan_er(i,j,2)) { level=13; x[level]=i; y[level]=j; } else { if(huo_er(i,j,2)&&zhouwei3(i,j,2)||huo_duan_er(i,j,2)&&zhouwei3(i,j,2)) { level=12; x[level]=i; y[level]=j; } else { if(huo_er(i,j,2)&&zhouwei2(i,j,2)||huo_duan_er(i,j,2)&&zhouwei2(i,j,2)) { level=11; x[level]=i; y[level]=j; } else { if(huo_er(i,j,2)&&zhouwei1(i,j,2)||huo_duan_er(i,j,2)&&zhouwei1(i,j,2)) { level=10; x[level]=i; y[level]=j; } else { if(huo_er(i,j,1)&&shi_zi_er(i,j,1)) { level=9; x[level]=i; y[level]=j; } else { if(huo_er(i,j,1)&&zhouwei3(i,j,1)||huo_duan_er(i,j,1)&&zhouwei3(i,j,1)) { level=8; x[level]=i; y[level]=j; } else { if(huo_er(i,j,1)&&zhouwei2(i,j,1)||huo_duan_er(i,j,1)&&zhouwei2(i,j,1)) { level=7; x[level]=i; y[level]=j; } else { if(huo_er(i,j,1)&&zhouwei1(i,j,1)||huo_duan_er(i,j,1)&&zhouwei1(i,j,1)) { level=6; x[level]=i; y[level]=j; } else { if(huo_er(i,j,1)||huo_duan_er(i,j,1)) { level=5; x[level]=i; y[level]=j; } else { if(xie_zi_er(i,j,2)||shi_zi_er(i,j,2)) { level=4; x[level]=i; y[level]=j; } else { if(xie_zi_er(i,j,1)||shi_zi_er(i,j,1)) { level=3; x[level]=i; y[level]=j; } else { if(si_er(i,j,2)) { level=2; x[level]=i; y[level]=j; } else { max_white=checkMax(i,j,2);//判斷白子的最大值 max_black=checkMax(i,j,1);//判斷黑子的最大值 if(max_white>max_black) max_temp=max_white; else max_temp=max_black; if(max_temp>max&&count==0) { max=max_temp; count++; level=1; x[level]=i; y[level]=j; } else if(count==1) { for(int m=0;m<width-1;m++) for(int n=0;n<width-1;n++) if(arrMapShow[m][n]==2) { level=1; if(m<this.width-1&&m>=1&&n>=1&&n<this.width-1) { if(arrMapShow[m+1][n-1]==-1) { x[level]=m+1; y[level]=n-1; } else if(arrMapShow[m-1][n+1]==-1) { x[level]=m-1; y[level]=n+1; } } } count=0; } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } if(flag==4) { for(i=43;i>=1;i--) { if(x[i]!=-2) { temp4=i; break; } } } if(flag==3) { for(i=43;i>=1;i--) { if(x[i]!=-2) { this.arrMapShow[x[i]][y[i]]=1; computerDo(flag+1); this.arrMapShow[x[i]][y[i]]=-1; temp3=i; break; } } } if(flag==2) { for(i=43;i>=1;i--) { if(x[i]!=-2) { this.arrMapShow[x[i]][y[i]]=2; computerDo(flag+1); this.arrMapShow[x[i]][y[i]]=-1; temp2=i; break; } } } else if(flag==1) { for(i=43;i>=1;i--) { if(x[i]!=-2) { this.arrMapShow[x[i]][y[i]]=1; computerDo(flag+1); this.arrMapShow[x[i]][y[i]]=-1; temp1=i; break; } } } else if(flag==0) { for(i=43;i>=1;i--) { if(x[i]!=-2) { this.arrMapShow[x[i]][y[i]]=2; computerDo(flag+1); this.arrMapShow[x[i]][y[i]]=-1; if(i>=19&&(temp4!=19&&temp4!=20&&temp4!=31&&temp4!=23&&temp4!=24&&temp4!=25&&temp4!=26&&temp4!=27&&temp4!=28&&temp4!=29&&temp4!=30&&temp4!=42)||temp4>=19) { this.x=x[i]; this.y=y[i]; this.arrMapShow[this.x][this.y]=2; setX(this.x); setY(this.y); if(judgeSuccess(this.x,this.y,true)==true) { JPanel jp=new JPanel(); showDefeat(jp); cf.restart(); } return ; } if(i>=19&&(temp3!=20&&temp3!=19&&temp3!=31&&temp3!=23&&temp3!=24&&temp3!=25&&temp3!=26&&temp3!=27&&temp3!=28&&temp3!=29&&temp3!=30&&temp3!=37&&temp3!=42)||(temp3>=19&&(temp3!=20&&temp3!=19&&temp3!=31&&temp3!=23&&temp3!=24&&temp3!=25&&temp3!=26&&temp3!=27&&temp3!=28&&temp3!=29&&temp3!=30&&temp3!=37&&temp3!=42))) { this.x=x[i]; this.y=y[i]; this.arrMapShow[this.x][this.y]=2; setX(this.x); setY(this.y); if(judgeSuccess(this.x,this.y,true)==true) { JPanel jp=new JPanel(); showDefeat(jp); cf.restart(); } return ; } if(i>=19&&(temp2!=20&&temp2!=19&&temp2!=31&&temp2!=23&&temp2!=24&&temp2!=25&&temp2!=26&&temp2!=27&&temp2!=28&&temp2!=29&&temp2!=30&&temp2!=42)||temp2>=19) { this.x=x[i]; this.y=y[i]; this.arrMapShow[this.x][this.y]=2; setX(this.x); setY(this.y); if(judgeSuccess(this.x,this.y,true)==true) { JPanel jp=new JPanel(); showDefeat(jp); cf.restart(); } return ; } if(i>=19&&(temp1!=20&&temp1!=19&&temp1!=31&&temp1!=23&&temp1!=24&&temp1!=25&&temp1!=26&&temp1!=27&&temp1!=28&&temp1!=29&&temp1!=30&&temp1!=37&&temp1!=42)||(temp1>=19&&(temp1!=20&&temp1!=19&&temp1!=31&&temp1!=23&&temp1!=24&&temp1!=25&&temp1!=26&&temp1!=27&&temp1!=28&&temp1!=29&&temp1!=30&&temp1!=37&&temp1!=42))) { this.x=x[i]; this.y=y[i]; this.arrMapShow[this.x][this.y]=2; setX(this.x); setY(this.y); if(judgeSuccess(this.x,this.y,true)==true) { JPanel jp=new JPanel(); showDefeat(jp); cf.restart(); } return ; } } } for(i=43;i>=1;i--) { if(x[i]!=-2) { this.x=x[i]; this.y=y[i]; break; } } this.arrMapShow[this.x][this.y]=2; setX(this.x); setY(this.y); if(judgeSuccess(this.x,this.y,true)==true) { JPanel jp=new JPanel(); showDefeat(jp); cf.restart(); } } } public void first() { int height,width; width=getWidth(); height=getHeight(); setX(width/2); setY(height/2); this.arrMapShow[width/2][height/2]=2; } //記錄電腦下子後的橫向座標 public void setX(int x){ this.x=x; } //記錄電腦下子後的縱向座標 public void setY(int y){ this.y=y; } //獲取電腦下子的橫向座標 public int getX(){ return this.x; } //獲取電腦下子的縱向座標 public int getY(){ return this.y; } //計算棋盤上某一方格上八個方向棋子的最大值, //這八個方向分別是:左、右、上、下、左上、左下、右上、右下 int checkMax(int x, int y,int black_or_white) { int num=0,max_num,max_temp=0,i; int x_temp=x,y_temp=y; int x_temp1=x_temp,y_temp1=y_temp; //judge right for(i=1;i<5;i++){ x_temp1+=1; if(x_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else break; } //judge left x_temp1=x_temp; for(i=1;i<5;i++){ x_temp1-=1; if(x_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else break; } if(num<5) max_temp=num; //judge up x_temp1=x_temp; y_temp1=y_temp; num=0; for(i=1;i<5;i++){ y_temp1-=1; if(y_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else break; } //judge down y_temp1=y_temp; for(i=1;i<5;i++){ y_temp1+=1; if(y_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else break; } if(num>max_temp&&num<5) max_temp=num; //judge left_up x_temp1=x_temp; y_temp1=y_temp; num=0; for(i=1;i<5;i++){ x_temp1-=1; y_temp1-=1; if(y_temp1<0 || x_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else break; } //judge right_down x_temp1=x_temp; y_temp1=y_temp; for(i=1;i<5;i++){ x_temp1+=1; y_temp1+=1; if(y_temp1>=width || x_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else break; } if(num>max_temp&&num<5) max_temp=num; //judge right_up x_temp1=x_temp; y_temp1=y_temp; num=0; for(i=1;i<5;i++){ x_temp1+=1; y_temp1-=1; if(y_temp1<0 || x_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else break; } //judge left_down x_temp1=x_temp; y_temp1=y_temp; for(i=1;i<5;i++){ x_temp1-=1; y_temp1+=1; if(y_temp1>=width || x_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else break; } if(num>max_temp&&num<5) max_temp=num; max_num=max_temp; return max_num; } //判斷 三三類型 boolean san_san(int x,int y,int black_or_white) { int flag1=0,flag2=0,flag3=0,flag4=0,flag5=0,flag6=0,flag7=0,flag8=0,flag9=0,flag10=0,flag11=0,flag12=0; int x_temp=x,y_temp=y; int x_temp1=x_temp,y_temp1=y_temp; //judge up if(x_temp1>=4) { if(arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1]==-1&&arrMapShow[x_temp1-3][y_temp1]==black_or_white&&arrMapShow[x_temp1-4][y_temp1]==-1) flag1=1; else if(arrMapShow[x_temp1-1][y_temp1]==-1&&arrMapShow[x_temp1-2][y_temp1]==black_or_white&&arrMapShow[x_temp1-3][y_temp1]==black_or_white&&arrMapShow[x_temp1-4][y_temp1]==-1) flag1=1; else if(arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1]==black_or_white&&arrMapShow[x_temp1-3][y_temp1]==-1) flag1=1; } if(x_temp1>=4&&x_temp1<=width-1) if(arrMapShow[x_temp1+1][y_temp1]==-1&&arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1]==black_or_white&&arrMapShow[x_temp1-3][y_temp1]==-1) flag1=1; //judge down x_temp1=x_temp; if(x_temp1<width-4) { if(arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1]==-1&&arrMapShow[x_temp1+3][y_temp1]==black_or_white&&arrMapShow[x_temp1+4][y_temp1]==-1) flag2=1; else if(arrMapShow[x_temp1+1][y_temp1]==-1&&arrMapShow[x_temp1+2][y_temp1]==black_or_white&&arrMapShow[x_temp1+3][y_temp1]==black_or_white&&arrMapShow[x_temp1+4][y_temp1]==-1) flag2=1; else if(arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1]==black_or_white&&arrMapShow[x_temp1+3][y_temp1]==-1) flag2=1; } if(x_temp1>=1&&x_temp1<width-4) if(arrMapShow[x_temp1-1][y_temp1]==-1&&arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1]==black_or_white&&arrMapShow[x_temp1+3][y_temp1]==-1) flag2=1; if(x_temp1>=2&&x_temp1<width-2) { if(arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1]==-1&&arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1]==-1) flag9=1; else if(arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1]==-1&&arrMapShow[x_temp1+1][y_temp1]==-1&&arrMapShow[x_temp1+2][y_temp1]==black_or_white) flag9=1; else if(arrMapShow[x_temp1-1][y_temp1]==-1&&arrMapShow[x_temp1-2][y_temp1]==black_or_white&&arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1]==-1) flag9=1; } //judge left x_temp1=x_temp; if(y_temp1>=4) { if(arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1-2]==-1&&arrMapShow[x_temp1][y_temp1-3]==black_or_white&&arrMapShow[x_temp1][y_temp1-4]==-1) flag3=1; else if(arrMapShow[x_temp1][y_temp1-1]==-1&&arrMapShow[x_temp1][y_temp1-2]==black_or_white&&arrMapShow[x_temp1][y_temp1-3]==black_or_white&&arrMapShow[x_temp1][y_temp1-4]==-1) flag3=1; else if(arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1-2]==black_or_white&&arrMapShow[x_temp1][y_temp1-3]==-1) flag3=1; } if(y_temp1>=4&&y_temp1<width-1) if(arrMapShow[x_temp1][y_temp1+1]==-1&&arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1-2]==black_or_white&&arrMapShow[x_temp1][y_temp1-3]==-1) flag3=1; //judge right y_temp1=y_temp; if(y_temp1<width-4) { if(arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1+2]==-1&&arrMapShow[x_temp1][y_temp1+3]==black_or_white&&arrMapShow[x_temp1][y_temp1+4]==-1) flag4=1; else if(arrMapShow[x_temp1][y_temp1+1]==-1&&arrMapShow[x_temp1][y_temp1+2]==black_or_white&&arrMapShow[x_temp1][y_temp1+3]==black_or_white&&arrMapShow[x_temp1][y_temp1+4]==-1) flag4=1; else if(arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1+2]==black_or_white&&arrMapShow[x_temp1][y_temp1+3]==-1) flag4=1; } if(y_temp1>=1&&y_temp1<width-4) if(arrMapShow[x_temp1][y_temp1-1]==-1&&arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1+2]==black_or_white&&arrMapShow[x_temp1][y_temp1+3]==-1) flag4=1; if(y_temp1>=2&&y_temp1<width-2) { if(arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1-2]==-1&&arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1+2]==-1) flag10=1; else if(arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1-2]==-1&&arrMapShow[x_temp1][y_temp1+1]==-1&&arrMapShow[x_temp1][y_temp1+2]==black_or_white) flag10=1; else if(arrMapShow[x_temp1][y_temp1-1]==-1&&arrMapShow[x_temp1][y_temp1-2]==black_or_white&&arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1+2]==-1) flag10=1; } //judge left_up x_temp1=x_temp; y_temp1=y_temp; if(y_temp1>=4&&x_temp1>=4) { if(arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1-2]==-1&&arrMapShow[x_temp1-3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1-4][y_temp1-4]==-1) flag5=1; else if(arrMapShow[x_temp1-1][y_temp1-1]==-1&&arrMapShow[x_temp1-2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1-4][y_temp1-4]==-1) flag5=1; else if(arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1-3]==-1) flag5=1; } if(y_temp1>=4&&x_temp1>=4&&y_temp1<width-1&&x_temp1<width-1) if(arrMapShow[x_temp1+1][y_temp1+1]==-1&&arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1-3]==-1) flag5=1; //judge right_down if(y_temp1<width-4&&x_temp1<width-4) { if(arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1+2]==-1&&arrMapShow[x_temp1+3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1+4][y_temp1+4]==-1) flag6=1; else if(arrMapShow[x_temp1+1][y_temp1+1]==-1&&arrMapShow[x_temp1+2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1+4][y_temp1+4]==-1) flag6=1; else if(arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1+3]==-1) flag6=1; } if(y_temp1>=1&&x_temp1>=1&&y_temp1<width-4&&x_temp1<width-4) if(arrMapShow[x_temp1-1][y_temp1-1]==-1&&arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1+3]==-1) flag6=1; if(y_temp1>=2&&y_temp1<width-2&&x_temp1>=2&&x_temp1<width-2) { if(arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1-2]==-1&&arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1+2]==-1) flag11=1; else if(arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1-2]==-1&&arrMapShow[x_temp1+1][y_temp1+1]==-1&&arrMapShow[x_temp1+2][y_temp1+2]==black_or_white) flag11=1; else if(arrMapShow[x_temp1-1][y_temp1-1]==-1&&arrMapShow[x_temp1-2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1+2]==-1) flag11=1; } //judge left_down x_temp1=x_temp; y_temp1=y_temp; if(y_temp1>=4&&x_temp1<width-4) { if(arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1-2]==-1&&arrMapShow[x_temp1+3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1+4][y_temp1-4]==-1) flag7=1; else if(arrMapShow[x_temp1+1][y_temp1-1]==-1&&arrMapShow[x_temp1+2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1+4][y_temp1-4]==-1) flag7=1; else if(arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1-3]==-1) flag7=1; } if(y_temp1>=4&&x_temp1>=1&&y_temp1<width-1&&x_temp1<width-4) if(arrMapShow[x_temp1-1][y_temp1+1]==-1&&arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1-3]==-1) flag7=1; //judge right_up x_temp1=x_temp; y_temp1=y_temp; if(y_temp1<width-4&&x_temp1>=4) { if(arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1+2]==-1&&arrMapShow[x_temp1-3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1-4][y_temp1+4]==-1) flag8=1; else if(arrMapShow[x_temp1-1][y_temp1+1]==-1&&arrMapShow[x_temp1-2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1-4][y_temp1+4]==-1) flag8=1; else if(arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1+3]==-1) flag8=1; } if(y_temp1>=1&&x_temp1>=4&&y_temp1<width-4&&x_temp1<width-1) if(arrMapShow[x_temp1+1][y_temp1-1]==-1&&arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1+3]==-1) flag8=1; if(y_temp1>=2&&y_temp1<width-2&&x_temp1>=2&&x_temp1<width-2) { if(arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1-2]==-1&&arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1+2]==-1) flag12=1; else if(arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1-2]==-1&&arrMapShow[x_temp1-1][y_temp1+1]==-1&&arrMapShow[x_temp1-2][y_temp1+2]==black_or_white) flag12=1; else if(arrMapShow[x_temp1+1][y_temp1-1]==-1&&arrMapShow[x_temp1+2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1+2]==-1) flag12=1; } if(flag1+flag2+flag3+flag4+flag5+flag6+flag7+flag8+flag9+flag10+flag11+flag12>=2) { return true; } return false; } //判斷四三類型 boolean si_san(int x,int y,int black_or_white) { int flag1=0,flag2=0,flag3=0,flag4=0,flag5=0,flag6=0,flag7=0,flag8=0; int x_temp=x,y_temp=y; int x_temp1=x_temp,y_temp1=y_temp; //judge right_left_san if(x_temp1<width-4) { if(arrMapShow[x_temp1+1][y_temp1]==-1&&arrMapShow[x_temp1+2][y_temp1]==black_or_white&&arrMapShow[x_temp1+3][y_temp1]==black_or_white&&arrMapShow[x_temp1+4][y_temp1]==-1) flag1=1; else if(arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1]==black_or_white&&arrMapShow[x_temp1+3][y_temp1]==-1&&arrMapShow[x_temp1+4][y_temp1]==-1) flag1=1; else if(arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1]==-1&&arrMapShow[x_temp1+3][y_temp1]==black_or_white&&arrMapShow[x_temp1+4][y_temp1]==-1) flag1=1; } if(x_temp1>=4) { if(arrMapShow[x_temp1-1][y_temp1]==-1&&arrMapShow[x_temp1-2][y_temp1]==black_or_white&&arrMapShow[x_temp1-3][y_temp1]==black_or_white&&arrMapShow[x_temp1-4][y_temp1]==-1) flag1=1; else if(arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1]==black_or_white&&arrMapShow[x_temp1-3][y_temp1]==-1&&arrMapShow[x_temp1-4][y_temp1]==-1) flag1=1; else if(arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1]==-1&&arrMapShow[x_temp1-3][y_temp1]==black_or_white&&arrMapShow[x_temp1-4][y_temp1]==-1) flag1=1; } if(x_temp1>=2&&x_temp1<width-2) { if(arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1]==-1&&arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1]==-1) flag1=1; else if(arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1+1][y_temp1]==-1&&arrMapShow[x_temp1+2][y_temp1]==black_or_white) flag1=1; else if(arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1-1][y_temp1]==-1&&arrMapShow[x_temp1-2][y_temp1]==black_or_white) flag1=1; } // judge right_left_si if(x_temp1<width-5) { if(arrMapShow[x_temp1+1][y_temp1]==-1&&arrMapShow[x_temp1+2][y_temp1]==black_or_white&&arrMapShow[x_temp1+3][y_temp1]==black_or_white&&arrMapShow[x_temp1+4][y_temp1]==black_or_white&&arrMapShow[x_temp1+5][y_temp1]==3-black_or_white) flag2=1; else if(arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1]==-1&&arrMapShow[x_temp1+3][y_temp1]==black_or_white&&arrMapShow[x_temp1+4][y_temp1]==black_or_white&&arrMapShow[x_temp1+5][y_temp1]==3-black_or_white) flag2=1; } if(x_temp1<width-4&&x_temp1>=1) { if(arrMapShow[x_temp1-1][y_temp1]==-1&&arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1]==black_or_white&&arrMapShow[x_temp1+3][y_temp1]==black_or_white&&arrMapShow[x_temp1+4][y_temp1]==3-black_or_white) flag2=1; else if(arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1]==-1&&arrMapShow[x_temp1+3][y_temp1]==black_or_white&&arrMapShow[x_temp1+4][y_temp1]==3-black_or_white) flag2=1; else if(arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1+1][y_temp1]==-1&&arrMapShow[x_temp1+2][y_temp1]==black_or_white&&arrMapShow[x_temp1+3][y_temp1]==black_or_white&&arrMapShow[x_temp1+4][y_temp1]==3-black_or_white) flag2=1; } if(x_temp1<width-3&&x_temp1>=2) { if(arrMapShow[x_temp1-1][y_temp1]==-1&&arrMapShow[x_temp1-2][y_temp1]==black_or_white&&arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1]==black_or_white&&arrMapShow[x_temp1+3][y_temp1]==3-black_or_white) flag2=1; else if(arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1]==-1&&arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1]==black_or_white&&arrMapShow[x_temp1+3][y_temp1]==3-black_or_white) flag2=1; else if(arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1]==black_or_white&&arrMapShow[x_temp1+1][y_temp1]==-1&&arrMapShow[x_temp1+2][y_temp1]==black_or_white&&arrMapShow[x_temp1+3][y_temp1]==3-black_or_white) flag2=1; } if(x_temp1<width-2&&x_temp1>=3) { if(arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1]==-1&&arrMapShow[x_temp1-3][y_temp1]==black_or_white&&arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1]==3-black_or_white) flag2=1; else if(arrMapShow[x_temp1-1][y_temp1]==-1&&arrMapShow[x_temp1-2][y_temp1]==black_or_white&&arrMapShow[x_temp1-3][y_temp1]==black_or_white&&arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1]==3-black_or_white) flag2=1; } if(x_temp1>=5) { if(arrMapShow[x_temp1-1][y_temp1]==-1&&arrMapShow[x_temp1-2][y_temp1]==black_or_white&&arrMapShow[x_temp1-3][y_temp1]==black_or_white&&arrMapShow[x_temp1-4][y_temp1]==black_or_white&&arrMapShow[x_temp1-1][y_temp1]==3-black_or_white) flag2=1; else if(arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1]==-1&&arrMapShow[x_temp1-3][y_temp1]==black_or_white&&arrMapShow[x_temp1-4][y_temp1]==black_or_white&&arrMapShow[x_temp1-1][y_temp1]==3-black_or_white) flag2=1; } if(x_temp1>=4&&x_temp1<width-1) { if(arrMapShow[x_temp1+1][y_temp1]==-1&&arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1]==black_or_white&&arrMapShow[x_temp1-3][y_temp1]==black_or_white&&arrMapShow[x_temp1-4][y_temp1]==3-black_or_white) flag2=1; else if(arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1]==-1&&arrMapShow[x_temp1-3][y_temp1]==black_or_white&&arrMapShow[x_temp1-4][y_temp1]==3-black_or_white) flag2=1; else if(arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1-1][y_temp1]==-1&&arrMapShow[x_temp1-2][y_temp1]==black_or_white&&arrMapShow[x_temp1-3][y_temp1]==black_or_white&&arrMapShow[x_temp1-4][y_temp1]==3-black_or_white) flag2=1; } if(x_temp1>=3&&x_temp1<width-2) { if(arrMapShow[x_temp1+1][y_temp1]==-1&&arrMapShow[x_temp1+2][y_temp1]==black_or_white&&arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1]==black_or_white&&arrMapShow[x_temp1-3][y_temp1]==3-black_or_white) flag2=1; else if(arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1]==-1&&arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1]==black_or_white&&arrMapShow[x_temp1-3][y_temp1]==3-black_or_white) flag2=1; else if(arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1]==black_or_white&&arrMapShow[x_temp1-1][y_temp1]==-1&&arrMapShow[x_temp1-2][y_temp1]==black_or_white&&arrMapShow[x_temp1-3][y_temp1]==3-black_or_white) flag2=1; } if(x_temp1>=2&&x_temp1<width-3) { if(arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1]==-1&&arrMapShow[x_temp1+3][y_temp1]==black_or_white&&arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1]==3-black_or_white) flag2=1; else if(arrMapShow[x_temp1+1][y_temp1]==-1&&arrMapShow[x_temp1+2][y_temp1]==black_or_white&&arrMapShow[x_temp1+3][y_temp1]==black_or_white&&arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1]==3-black_or_white) flag2=1; } //judge up_down_san if(y_temp1<width-4&&y_temp1>=1) { if(arrMapShow[x_temp1][y_temp1+1]==-1&&arrMapShow[x_temp1][y_temp1+2]==black_or_white&&arrMapShow[x_temp1][y_temp1+3]==black_or_white&&arrMapShow[x_temp1][y_temp1+4]==-1) flag3=1; else if(arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1+2]==black_or_white&&arrMapShow[x_temp1][y_temp1+3]==-1&&arrMapShow[x_temp1][y_temp1+4]==-1) flag3=1; else if(arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1+2]==-1&&arrMapShow[x_temp1][y_temp1+3]==black_or_white&&arrMapShow[x_temp1][y_temp1+4]==-1) flag3=1; } if(y_temp1>=4) { if(arrMapShow[x_temp1][y_temp1-1]==-1&&arrMapShow[x_temp1][y_temp1-2]==black_or_white&&arrMapShow[x_temp1][y_temp1-3]==black_or_white&&arrMapShow[x_temp1][y_temp1-4]==-1) flag3=1; else if(arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1-2]==black_or_white&&arrMapShow[x_temp1][y_temp1-3]==-1&&arrMapShow[x_temp1][y_temp1-4]==-1) flag3=1; else if(arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1-2]==-1&&arrMapShow[x_temp1][y_temp1-3]==black_or_white&&arrMapShow[x_temp1][y_temp1-4]==-1) flag3=1; } if(y_temp1>=2&&y_temp1<width-2) { if(arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1-2]==-1&&arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1+2]==-1) flag3=1; else if(arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1+1]==-1&&arrMapShow[x_temp1][y_temp1+2]==black_or_white) flag3=1; else if(arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1-1]==-1&&arrMapShow[x_temp1][y_temp1-2]==black_or_white) flag3=1; } //judge up_down_si if(y_temp1<width-5) { if(arrMapShow[x_temp1][y_temp1+1]==-1&&arrMapShow[x_temp1][y_temp1+2]==black_or_white&&arrMapShow[x_temp1][y_temp1+3]==black_or_white&&arrMapShow[x_temp1][y_temp1+4]==black_or_white&&arrMapShow[x_temp1][y_temp1+5]==3-black_or_white) flag4=1; else if(arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1+2]==-1&&arrMapShow[x_temp1][y_temp1+3]==black_or_white&&arrMapShow[x_temp1][y_temp1+4]==black_or_white&&arrMapShow[x_temp1][y_temp1+5]==3-black_or_white) flag4=1; } if(y_temp1<width-4&&y_temp1>=1) { if(arrMapShow[x_temp1][y_temp1-1]==-1&&arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1+2]==black_or_white&&arrMapShow[x_temp1][y_temp1+3]==black_or_white&&arrMapShow[x_temp1][y_temp1+4]==3-black_or_white) flag4=1; else if(arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1+2]==-1&&arrMapShow[x_temp1][y_temp1+3]==black_or_white&&arrMapShow[x_temp1][y_temp1+4]==3-black_or_white) flag4=1; else if(arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1+1]==-1&&arrMapShow[x_temp1][y_temp1+2]==black_or_white&&arrMapShow[x_temp1][y_temp1+3]==black_or_white&&arrMapShow[x_temp1][y_temp1+4]==3-black_or_white) flag4=1; } if(y_temp1<width-3&&y_temp1>=2) { if(arrMapShow[x_temp1][y_temp1-1]==-1&&arrMapShow[x_temp1][y_temp1-2]==black_or_white&&arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1+2]==black_or_white&&arrMapShow[x_temp1][y_temp1+3]==3-black_or_white) flag4=1; else if(arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1-2]==-1&&arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1+2]==black_or_white&&arrMapShow[x_temp1][y_temp1+3]==3-black_or_white) flag4=1; else if(arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1-2]==black_or_white&&arrMapShow[x_temp1][y_temp1+1]==-1&&arrMapShow[x_temp1][y_temp1+2]==black_or_white&&arrMapShow[x_temp1][y_temp1+3]==3-black_or_white) flag4=1; } if(y_temp1<width-2&&y_temp1>=3) { if(arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1-2]==-1&&arrMapShow[x_temp1][y_temp1-3]==black_or_white&&arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1+2]==3-black_or_white) flag4=1; else if(arrMapShow[x_temp1][y_temp1-1]==-1&&arrMapShow[x_temp1][y_temp1-2]==black_or_white&&arrMapShow[x_temp1][y_temp1-3]==black_or_white&&arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1+2]==3-black_or_white) flag4=1; } if(y_temp1>=5) { if(arrMapShow[x_temp1][y_temp1-1]==-1&&arrMapShow[x_temp1][y_temp1-2]==black_or_white&&arrMapShow[x_temp1][y_temp1-3]==black_or_white&&arrMapShow[x_temp1][y_temp1-4]==black_or_white&&arrMapShow[x_temp1][y_temp1-1]==3-black_or_white) flag4=1; else if(arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1-2]==-1&&arrMapShow[x_temp1][y_temp1-3]==black_or_white&&arrMapShow[x_temp1][y_temp1-4]==black_or_white&&arrMapShow[x_temp1][y_temp1-1]==3-black_or_white) flag4=1; } if(y_temp1>=4&&y_temp1<width-1) { if(arrMapShow[x_temp1][y_temp1+1]==-1&&arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1-2]==black_or_white&&arrMapShow[x_temp1][y_temp1-3]==black_or_white&&arrMapShow[x_temp1][y_temp1-4]==3-black_or_white) flag4=1; else if(arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1-2]==-1&&arrMapShow[x_temp1][y_temp1-3]==black_or_white&&arrMapShow[x_temp1][y_temp1-4]==3-black_or_white) flag4=1; else if(arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1-1]==-1&&arrMapShow[x_temp1][y_temp1-2]==black_or_white&&arrMapShow[x_temp1][y_temp1-3]==black_or_white&&arrMapShow[x_temp1][y_temp1-4]==3-black_or_white) flag4=1; } if(y_temp1>=3&&y_temp1<width-2) { if(arrMapShow[x_temp1][y_temp1+1]==-1&&arrMapShow[x_temp1][y_temp1+2]==black_or_white&&arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1-2]==black_or_white&&arrMapShow[x_temp1][y_temp1-3]==3-black_or_white) flag4=1; else if(arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1+2]==-1&&arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1-2]==black_or_white&&arrMapShow[x_temp1][y_temp1-3]==3-black_or_white) flag4=1; else if(arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1+2]==black_or_white&&arrMapShow[x_temp1][y_temp1-1]==-1&&arrMapShow[x_temp1][y_temp1-2]==black_or_white&&arrMapShow[x_temp1][y_temp1-3]==3-black_or_white) flag4=1; } if(y_temp1>=2&&y_temp1<width-3) { if(arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1+2]==-1&&arrMapShow[x_temp1][y_temp1+3]==black_or_white&&arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1-2]==3-black_or_white) flag4=1; else if(arrMapShow[x_temp1][y_temp1+1]==-1&&arrMapShow[x_temp1][y_temp1+2]==black_or_white&&arrMapShow[x_temp1][y_temp1+3]==black_or_white&&arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1-2]==3-black_or_white) flag4=1; } //judge D_L_R_U_san if(y_temp1<width-4&&y_temp1>=1&&x_temp1>=4&&x_temp1<width-4) { if(arrMapShow[x_temp1-1][y_temp1+1]==-1&&arrMapShow[x_temp1-2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1-4][y_temp1+4]==-1) flag5=1; else if(arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1+3]==-1&&arrMapShow[x_temp1+4][y_temp1+4]==-1) flag5=1; else if(arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1+2]==-1&&arrMapShow[x_temp1-3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1-4][y_temp1+4]==-1) flag5=1; } if(y_temp1>=4&&y_temp1<width-1&&x_temp1<width-4&&x_temp1>=1) { if(arrMapShow[x_temp1+1][y_temp1-1]==-1&&arrMapShow[x_temp1+2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1+4][y_temp1-4]==-1) flag5=1; else if(arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1-3]==-1&&arrMapShow[x_temp1+4][y_temp1-4]==-1) flag5=1; else if(arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1-2]==-1&&arrMapShow[x_temp1+3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1+4][y_temp1-4]==-1) flag5=1; } if(y_temp1>=2&&x_temp1<width-2&&y_temp1<width-2&&x_temp1>=2) { if(arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1-2]==-1&&arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1+2]==-1) flag5=1; else if(arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-1][y_temp1+1]==-1&&arrMapShow[x_temp1-2][y_temp1+2]==black_or_white) flag5=1; else if(arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+1][y_temp1-1]==-1&&arrMapShow[x_temp1+2][y_temp1-2]==black_or_white) flag5=1; } //judge D_L_R_U_si if(y_temp1<width-5&&x_temp1>=5) { if(arrMapShow[x_temp1-1][y_temp1+1]==-1&&arrMapShow[x_temp1-2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1-4][y_temp1+4]==black_or_white&&arrMapShow[x_temp1-1][y_temp1+5]==3-black_or_white) flag6=1; else if(arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1+2]==-1&&arrMapShow[x_temp1-3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1-4][y_temp1+4]==black_or_white&&arrMapShow[x_temp1-1][y_temp1+5]==3-black_or_white) flag6=1; } if(y_temp1<width-4&&x_temp1>=4&&y_temp1>=1&&x_temp1<width-1) { if(arrMapShow[x_temp1+1][y_temp1-1]==-1&&arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1-4][y_temp1+4]==3-black_or_white) flag6=1; else if(arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1+2]==-1&&arrMapShow[x_temp1-3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1-4][y_temp1+4]==3-black_or_white) flag6=1; else if(arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-1][y_temp1+1]==-1&&arrMapShow[x_temp1-2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1-4][y_temp1+4]==3-black_or_white) flag6=1; } if(y_temp1<width-3&&x_temp1>=3&&y_temp1>=2&&x_temp1<width-2) { if(arrMapShow[x_temp1+1][y_temp1-1]==-1&&arrMapShow[x_temp1+2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1+3]==3-black_or_white) flag6=1; else if(arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1-2]==-1&&arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1+3]==3-black_or_white) flag6=1; else if(arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1-1][y_temp1+1]==-1&&arrMapShow[x_temp1-2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1+3]==3-black_or_white) flag6=1; } if(y_temp1<width-2&&x_temp1>=2&&y_temp1>=3&&x_temp1<width-3) { if(arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1-2]==-1&&arrMapShow[x_temp1+3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1+2]==3-black_or_white) flag6=1; else if(arrMapShow[x_temp1+1][y_temp1-1]==-1&&arrMapShow[x_temp1+2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1+2]==3-black_or_white) flag6=1; } if(y_temp1>=5&&x_temp1<width-5) { if(arrMapShow[x_temp1+1][y_temp1-1]==-1&&arrMapShow[x_temp1+2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1+4][y_temp1-4]==black_or_white&&arrMapShow[x_temp1+5][y_temp1-5]==3-black_or_white) flag6=1; else if(arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1-2]==-1&&arrMapShow[x_temp1+3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1+4][y_temp1-4]==black_or_white&&arrMapShow[x_temp1+5][y_temp1-5]==3-black_or_white) flag6=1; } if(y_temp1>=4&&x_temp1<width-4&&y_temp1<width-1&&x_temp1>=1) { if(arrMapShow[x_temp1-1][y_temp1+1]==-1&&arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1+4][y_temp1-4]==3-black_or_white) flag6=1; else if(arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1-2]==-1&&arrMapShow[x_temp1+3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1+4][y_temp1-4]==3-black_or_white) flag6=1; else if(arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+1][y_temp1-1]==-1&&arrMapShow[x_temp1+2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1+4][y_temp1-4]==3-black_or_white) flag6=1; } if(y_temp1>=3&&x_temp1<width-3&&y_temp1<width-2&&x_temp1>=2) { if(arrMapShow[x_temp1-1][y_temp1+1]==-1&&arrMapShow[x_temp1-2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1-3]==3-black_or_white) flag6=1; else if(arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1+2]==-1&&arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1-3]==3-black_or_white) flag6=1; else if(arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1+1][y_temp1-1]==-1&&arrMapShow[x_temp1+2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1-3]==3-black_or_white) flag6=1; } if(y_temp1>=2&&x_temp1<width-2&&y_temp1<width-3&&x_temp1>=3) { if(arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1+2]==-1&&arrMapShow[x_temp1-3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1-2]==3-black_or_white) flag6=1; else if(arrMapShow[x_temp1-1][y_temp1+1]==-1&&arrMapShow[x_temp1-2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1-2]==3-black_or_white) flag6=1; } //judge L_U_R_D_san if(y_temp1<width-4&&y_temp1>=1&&x_temp1<width-4&&x_temp1>=1) { if(arrMapShow[x_temp1+1][y_temp1+1]==-1&&arrMapShow[x_temp1+2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1+4][y_temp1+4]==-1) flag7=1; else if(arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1+3]==-1&&arrMapShow[x_temp1+4][y_temp1+4]==-1) flag7=1; else if(arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1+2]==-1&&arrMapShow[x_temp1+3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1+4][y_temp1+4]==-1) flag7=1; } if(y_temp1>=4&&x_temp1>=4&&y_temp1<width-1&&x_temp1<width-1) { if(arrMapShow[x_temp1-1][y_temp1-1]==-1&&arrMapShow[x_temp1-2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1-4][y_temp1-4]==-1) flag7=1; else if(arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1-3]==-1&&arrMapShow[x_temp1-4][y_temp1-4]==-1) flag7=1; else if(arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1-2]==-1&&arrMapShow[x_temp1-3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1-4][y_temp1-4]==-1) flag7=1; } if(y_temp1>=2&&x_temp1>=2&&y_temp1<width-2&&x_temp1<width-2) { if(arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1-2]==-1&&arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1+2]==-1) flag7=1; else if(arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+1][y_temp1+1]==-1&&arrMapShow[x_temp1+2][y_temp1+2]==black_or_white) flag7=1; else if(arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-1][y_temp1-1]==-1&&arrMapShow[x_temp1-2][y_temp1-2]==black_or_white) flag7=1; } //judge L_U_R_D_si if(y_temp1<width-5&&x_temp1<width-5) { if(arrMapShow[x_temp1+1][y_temp1+1]==-1&&arrMapShow[x_temp1+2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1+4][y_temp1+4]==black_or_white&&arrMapShow[x_temp1+5][y_temp1+5]==3-black_or_white) flag8=1; else if(arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1+2]==-1&&arrMapShow[x_temp1+3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1+4][y_temp1+4]==black_or_white&&arrMapShow[x_temp1+5][y_temp1+5]==3-black_or_white) flag8=1; } if(y_temp1<width-4&&x_temp1<width-4&&y_temp1>=1&&x_temp1>=1) { if(arrMapShow[x_temp1-1][y_temp1-1]==-1&&arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1+4][y_temp1+4]==3-black_or_white) flag8=1; else if(arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1+2]==-1&&arrMapShow[x_temp1+3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1+4][y_temp1+4]==3-black_or_white) flag8=1; else if(arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+1][y_temp1+1]==-1&&arrMapShow[x_temp1+2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1+4][y_temp1+4]==3-black_or_white) flag8=1; } if(y_temp1<width-3&&x_temp1<width-3&&y_temp1>=2&&x_temp1>=2) { if(arrMapShow[x_temp1-1][y_temp1-1]==-1&&arrMapShow[x_temp1-2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1+3]==3-black_or_white) flag8=1; else if(arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1-2]==-1&&arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1+3]==3-black_or_white) flag8=1; else if(arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1+1][y_temp1+1]==-1&&arrMapShow[x_temp1+2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1+3]==3-black_or_white) flag8=1; } if(y_temp1<width-2&&x_temp1<width-2&&y_temp1>=3&&x_temp1>=3) { if(arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1-2]==-1&&arrMapShow[x_temp1-3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1+2]==3-black_or_white) flag8=1; else if(arrMapShow[x_temp1-1][y_temp1-1]==-1&&arrMapShow[x_temp1-2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1+2]==3-black_or_white) flag8=1; } if(y_temp1>=5&&x_temp1>=5) { if(arrMapShow[x_temp1-1][y_temp1-1]==-1&&arrMapShow[x_temp1-2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1-4][y_temp1-4]==black_or_white&&arrMapShow[x_temp1-1][y_temp1-1]==3-black_or_white) flag8=1; else if(arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1-2]==-1&&arrMapShow[x_temp1-3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1-4][y_temp1-4]==black_or_white&&arrMapShow[x_temp1-1][y_temp1-1]==3-black_or_white) flag8=1; } if(y_temp1>=4&&x_temp1>=4&&y_temp1<width-1&&x_temp1<width-1) { if(arrMapShow[x_temp1+1][y_temp1+1]==-1&&arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1-4][y_temp1-4]==3-black_or_white) flag8=1; else if(arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1-2]==-1&&arrMapShow[x_temp1-3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1-4][y_temp1-4]==3-black_or_white) flag8=1; else if(arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-1][y_temp1-1]==-1&&arrMapShow[x_temp1-2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1-4][y_temp1-4]==3-black_or_white) flag8=1; } if(y_temp1>=3&&x_temp1>=3&&y_temp1<width-2&&x_temp1<width-2) { if(arrMapShow[x_temp1+1][y_temp1+1]==-1&&arrMapShow[x_temp1+2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1-3]==3-black_or_white) flag8=1; else if(arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1+2]==-1&&arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1-3]==3-black_or_white) flag8=1; else if(arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1-1][y_temp1-1]==-1&&arrMapShow[x_temp1-2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1-3]==3-black_or_white) flag8=1; } if(y_temp1>=2&&x_temp1>=2&&y_temp1<width-3&&x_temp1<width-3) { if(arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1+2]==-1&&arrMapShow[x_temp1+3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1-2]==3-black_or_white) flag8=1; else if(arrMapShow[x_temp1+1][y_temp1+1]==-1&&arrMapShow[x_temp1+2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1-2]==3-black_or_white) flag8=1; } if(flag1+flag3+flag5+flag7>=1&&flag2+flag4+flag6+flag8>=1) return true; return false; } //判斷四四類型 boolean si_si(int x,int y,int black_or_white) { int flag2=0,flag4=0,flag6=0,flag8=0; int x_temp=x,y_temp=y; int x_temp1=x_temp,y_temp1=y_temp; // judge right_left_si if(x_temp1<width-5) { if(arrMapShow[x_temp1+1][y_temp1]==-1&&arrMapShow[x_temp1+2][y_temp1]==black_or_white&&arrMapShow[x_temp1+3][y_temp1]==black_or_white&&arrMapShow[x_temp1+4][y_temp1]==black_or_white&&arrMapShow[x_temp1+5][y_temp1]==3-black_or_white) flag2=1; else if(arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1]==-1&&arrMapShow[x_temp1+3][y_temp1]==black_or_white&&arrMapShow[x_temp1+4][y_temp1]==black_or_white&&arrMapShow[x_temp1+5][y_temp1]==3-black_or_white) flag2=1; } if(x_temp1<width-4&&x_temp1>=1) { if(arrMapShow[x_temp1-1][y_temp1]==-1&&arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1]==black_or_white&&arrMapShow[x_temp1+3][y_temp1]==black_or_white&&arrMapShow[x_temp1+4][y_temp1]==3-black_or_white) flag2=1; else if(arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1]==-1&&arrMapShow[x_temp1+3][y_temp1]==black_or_white&&arrMapShow[x_temp1+4][y_temp1]==3-black_or_white) flag2=1; else if(arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1+1][y_temp1]==-1&&arrMapShow[x_temp1+2][y_temp1]==black_or_white&&arrMapShow[x_temp1+3][y_temp1]==black_or_white&&arrMapShow[x_temp1+4][y_temp1]==3-black_or_white) flag2=1; } if(x_temp1<width-3&&x_temp1>=2) { if(arrMapShow[x_temp1-1][y_temp1]==-1&&arrMapShow[x_temp1-2][y_temp1]==black_or_white&&arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1]==black_or_white&&arrMapShow[x_temp1+3][y_temp1]==3-black_or_white) flag2=1; else if(arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1]==-1&&arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1]==black_or_white&&arrMapShow[x_temp1+3][y_temp1]==3-black_or_white) flag2=1; else if(arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1]==black_or_white&&arrMapShow[x_temp1+1][y_temp1]==-1&&arrMapShow[x_temp1+2][y_temp1]==black_or_white&&arrMapShow[x_temp1+3][y_temp1]==3-black_or_white) flag2=1; } if(x_temp1<width-2&&x_temp1>=3) { if(arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1]==-1&&arrMapShow[x_temp1-3][y_temp1]==black_or_white&&arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1]==3-black_or_white) flag2=1; else if(arrMapShow[x_temp1-1][y_temp1]==-1&&arrMapShow[x_temp1-2][y_temp1]==black_or_white&&arrMapShow[x_temp1-3][y_temp1]==black_or_white&&arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1]==3-black_or_white) flag2=1; } if(x_temp1>=5) { if(arrMapShow[x_temp1-1][y_temp1]==-1&&arrMapShow[x_temp1-2][y_temp1]==black_or_white&&arrMapShow[x_temp1-3][y_temp1]==black_or_white&&arrMapShow[x_temp1-4][y_temp1]==black_or_white&&arrMapShow[x_temp1-1][y_temp1]==3-black_or_white) flag2=1; else if(arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1]==-1&&arrMapShow[x_temp1-3][y_temp1]==black_or_white&&arrMapShow[x_temp1-4][y_temp1]==black_or_white&&arrMapShow[x_temp1-1][y_temp1]==3-black_or_white) flag2=1; } if(x_temp1>=4&&x_temp1<width-1) { if(arrMapShow[x_temp1+1][y_temp1]==-1&&arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1]==black_or_white&&arrMapShow[x_temp1-3][y_temp1]==black_or_white&&arrMapShow[x_temp1-4][y_temp1]==3-black_or_white) flag2=1; else if(arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1]==-1&&arrMapShow[x_temp1-3][y_temp1]==black_or_white&&arrMapShow[x_temp1-4][y_temp1]==3-black_or_white) flag2=1; else if(arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1-1][y_temp1]==-1&&arrMapShow[x_temp1-2][y_temp1]==black_or_white&&arrMapShow[x_temp1-3][y_temp1]==black_or_white&&arrMapShow[x_temp1-4][y_temp1]==3-black_or_white) flag2=1; } if(x_temp1>=3&&x_temp1<width-2) { if(arrMapShow[x_temp1+1][y_temp1]==-1&&arrMapShow[x_temp1+2][y_temp1]==black_or_white&&arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1]==black_or_white&&arrMapShow[x_temp1-3][y_temp1]==3-black_or_white) flag2=1; else if(arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1]==-1&&arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1]==black_or_white&&arrMapShow[x_temp1-3][y_temp1]==3-black_or_white) flag2=1; else if(arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1]==black_or_white&&arrMapShow[x_temp1-1][y_temp1]==-1&&arrMapShow[x_temp1-2][y_temp1]==black_or_white&&arrMapShow[x_temp1-3][y_temp1]==3-black_or_white) flag2=1; } if(x_temp1>=2&&x_temp1<width-3) { if(arrMapShow[x_temp1+1][y_temp1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1]==-1&&arrMapShow[x_temp1+3][y_temp1]==black_or_white&&arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1]==3-black_or_white) flag2=1; else if(arrMapShow[x_temp1+1][y_temp1]==-1&&arrMapShow[x_temp1+2][y_temp1]==black_or_white&&arrMapShow[x_temp1+3][y_temp1]==black_or_white&&arrMapShow[x_temp1-1][y_temp1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1]==3-black_or_white) flag2=1; } //judge up_down_si if(y_temp1<width-5) { if(arrMapShow[x_temp1][y_temp1+1]==-1&&arrMapShow[x_temp1][y_temp1+2]==black_or_white&&arrMapShow[x_temp1][y_temp1+3]==black_or_white&&arrMapShow[x_temp1][y_temp1+4]==black_or_white&&arrMapShow[x_temp1][y_temp1+5]==3-black_or_white) flag4=1; else if(arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1+2]==-1&&arrMapShow[x_temp1][y_temp1+3]==black_or_white&&arrMapShow[x_temp1][y_temp1+4]==black_or_white&&arrMapShow[x_temp1][y_temp1+5]==3-black_or_white) flag4=1; } if(y_temp1<width-4&&y_temp1>=1) { if(arrMapShow[x_temp1][y_temp1-1]==-1&&arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1+2]==black_or_white&&arrMapShow[x_temp1][y_temp1+3]==black_or_white&&arrMapShow[x_temp1][y_temp1+4]==3-black_or_white) flag4=1; else if(arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1+2]==-1&&arrMapShow[x_temp1][y_temp1+3]==black_or_white&&arrMapShow[x_temp1][y_temp1+4]==3-black_or_white) flag4=1; else if(arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1+1]==-1&&arrMapShow[x_temp1][y_temp1+2]==black_or_white&&arrMapShow[x_temp1][y_temp1+3]==black_or_white&&arrMapShow[x_temp1][y_temp1+4]==3-black_or_white) flag4=1; } if(y_temp1<width-3&&y_temp1>=2) { if(arrMapShow[x_temp1][y_temp1-1]==-1&&arrMapShow[x_temp1][y_temp1-2]==black_or_white&&arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1+2]==black_or_white&&arrMapShow[x_temp1][y_temp1+3]==3-black_or_white) flag4=1; else if(arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1-2]==-1&&arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1+2]==black_or_white&&arrMapShow[x_temp1][y_temp1+3]==3-black_or_white) flag4=1; else if(arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1-2]==black_or_white&&arrMapShow[x_temp1][y_temp1+1]==-1&&arrMapShow[x_temp1][y_temp1+2]==black_or_white&&arrMapShow[x_temp1][y_temp1+3]==3-black_or_white) flag4=1; } if(y_temp1<width-2&&y_temp1>=3) { if(arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1-2]==-1&&arrMapShow[x_temp1][y_temp1-3]==black_or_white&&arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1+2]==3-black_or_white) flag4=1; else if(arrMapShow[x_temp1][y_temp1-1]==-1&&arrMapShow[x_temp1][y_temp1-2]==black_or_white&&arrMapShow[x_temp1][y_temp1-3]==black_or_white&&arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1+2]==3-black_or_white) flag4=1; } if(y_temp1>=5) { if(arrMapShow[x_temp1][y_temp1-1]==-1&&arrMapShow[x_temp1][y_temp1-2]==black_or_white&&arrMapShow[x_temp1][y_temp1-3]==black_or_white&&arrMapShow[x_temp1][y_temp1-4]==black_or_white&&arrMapShow[x_temp1][y_temp1-1]==3-black_or_white) flag4=1; else if(arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1-2]==-1&&arrMapShow[x_temp1][y_temp1-3]==black_or_white&&arrMapShow[x_temp1][y_temp1-4]==black_or_white&&arrMapShow[x_temp1][y_temp1-1]==3-black_or_white) flag4=1; } if(y_temp1>=4&&y_temp1<width-1) { if(arrMapShow[x_temp1][y_temp1+1]==-1&&arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1-2]==black_or_white&&arrMapShow[x_temp1][y_temp1-3]==black_or_white&&arrMapShow[x_temp1][y_temp1-4]==3-black_or_white) flag4=1; else if(arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1-2]==-1&&arrMapShow[x_temp1][y_temp1-3]==black_or_white&&arrMapShow[x_temp1][y_temp1-4]==3-black_or_white) flag4=1; else if(arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1-1]==-1&&arrMapShow[x_temp1][y_temp1-2]==black_or_white&&arrMapShow[x_temp1][y_temp1-3]==black_or_white&&arrMapShow[x_temp1][y_temp1-4]==3-black_or_white) flag4=1; } if(y_temp1>=3&&y_temp1<width-2) { if(arrMapShow[x_temp1][y_temp1+1]==-1&&arrMapShow[x_temp1][y_temp1+2]==black_or_white&&arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1-2]==black_or_white&&arrMapShow[x_temp1][y_temp1-3]==3-black_or_white) flag4=1; else if(arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1+2]==-1&&arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1-2]==black_or_white&&arrMapShow[x_temp1][y_temp1-3]==3-black_or_white) flag4=1; else if(arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1+2]==black_or_white&&arrMapShow[x_temp1][y_temp1-1]==-1&&arrMapShow[x_temp1][y_temp1-2]==black_or_white&&arrMapShow[x_temp1][y_temp1-3]==3-black_or_white) flag4=1; } if(y_temp1>=2&&y_temp1<width-3) { if(arrMapShow[x_temp1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1][y_temp1+2]==-1&&arrMapShow[x_temp1][y_temp1+3]==black_or_white&&arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1-2]==3-black_or_white) flag4=1; else if(arrMapShow[x_temp1][y_temp1+1]==-1&&arrMapShow[x_temp1][y_temp1+2]==black_or_white&&arrMapShow[x_temp1][y_temp1+3]==black_or_white&&arrMapShow[x_temp1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1][y_temp1-2]==3-black_or_white) flag4=1; } //judge D_L_R_U_si if(y_temp1<width-5&&x_temp1>=5) { if(arrMapShow[x_temp1-1][y_temp1+1]==-1&&arrMapShow[x_temp1-2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1-4][y_temp1+4]==black_or_white&&arrMapShow[x_temp1-1][y_temp1+5]==3-black_or_white) flag6=1; else if(arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1+2]==-1&&arrMapShow[x_temp1-3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1-4][y_temp1+4]==black_or_white&&arrMapShow[x_temp1-1][y_temp1+5]==3-black_or_white) flag6=1; } if(y_temp1<width-4&&x_temp1>=4&&y_temp1>=1&&x_temp1<width-1) { if(arrMapShow[x_temp1+1][y_temp1-1]==-1&&arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1-4][y_temp1+4]==3-black_or_white) flag6=1; else if(arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1+2]==-1&&arrMapShow[x_temp1-3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1-4][y_temp1+4]==3-black_or_white) flag6=1; else if(arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-1][y_temp1+1]==-1&&arrMapShow[x_temp1-2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1-4][y_temp1+4]==3-black_or_white) flag6=1; } if(y_temp1<width-3&&x_temp1>=3&&y_temp1>=2&&x_temp1<width-2) { if(arrMapShow[x_temp1+1][y_temp1-1]==-1&&arrMapShow[x_temp1+2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1+3]==3-black_or_white) flag6=1; else if(arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1-2]==-1&&arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1+3]==3-black_or_white) flag6=1; else if(arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1-1][y_temp1+1]==-1&&arrMapShow[x_temp1-2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1+3]==3-black_or_white) flag6=1; } if(y_temp1<width-2&&x_temp1>=2&&y_temp1>=3&&x_temp1<width-3) { if(arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1-2]==-1&&arrMapShow[x_temp1+3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1+2]==3-black_or_white) flag6=1; else if(arrMapShow[x_temp1+1][y_temp1-1]==-1&&arrMapShow[x_temp1+2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1+2]==3-black_or_white) flag6=1; } if(y_temp1>=5&&x_temp1<width-5) { if(arrMapShow[x_temp1+1][y_temp1-1]==-1&&arrMapShow[x_temp1+2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1+4][y_temp1-4]==black_or_white&&arrMapShow[x_temp1+5][y_temp1-1]==3-black_or_white) flag6=1; else if(arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1-2]==-1&&arrMapShow[x_temp1+3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1+4][y_temp1-4]==black_or_white&&arrMapShow[x_temp1+5][y_temp1-1]==3-black_or_white) flag6=1; } if(y_temp1>=4&&x_temp1<width-4&&y_temp1<width-1&&x_temp1>=1) { if(arrMapShow[x_temp1-1][y_temp1+1]==-1&&arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1+4][y_temp1-4]==3-black_or_white) flag6=1; else if(arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1-2]==-1&&arrMapShow[x_temp1+3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1+4][y_temp1-4]==3-black_or_white) flag6=1; else if(arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+1][y_temp1-1]==-1&&arrMapShow[x_temp1+2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1+4][y_temp1-4]==3-black_or_white) flag6=1; } if(y_temp1>=3&&x_temp1<width-3&&y_temp1<width-2&&x_temp1>=2) { if(arrMapShow[x_temp1-1][y_temp1+1]==-1&&arrMapShow[x_temp1-2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1-3]==3-black_or_white) flag6=1; else if(arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1+2]==-1&&arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1-3]==3-black_or_white) flag6=1; else if(arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1+1][y_temp1-1]==-1&&arrMapShow[x_temp1+2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1-3]==3-black_or_white) flag6=1; } if(y_temp1>=2&&x_temp1<width-2&&y_temp1<width-3&&x_temp1>=3) { if(arrMapShow[x_temp1-1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1+2]==-1&&arrMapShow[x_temp1-3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1-2]==3-black_or_white) flag6=1; else if(arrMapShow[x_temp1-1][y_temp1+1]==-1&&arrMapShow[x_temp1-2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1+1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1-2]==3-black_or_white) flag6=1; } //judge L_U_R_D_si if(y_temp1<width-5&&x_temp1<width-5) { if(arrMapShow[x_temp1+1][y_temp1+1]==-1&&arrMapShow[x_temp1+2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1+4][y_temp1+4]==black_or_white&&arrMapShow[x_temp1+5][y_temp1+5]==3-black_or_white) flag8=1; else if(arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1+2]==-1&&arrMapShow[x_temp1+3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1+4][y_temp1+4]==black_or_white&&arrMapShow[x_temp1+5][y_temp1+5]==3-black_or_white) flag8=1; } if(y_temp1<width-4&&x_temp1<width-4&&y_temp1>=1&&x_temp1>=1) { if(arrMapShow[x_temp1-1][y_temp1-1]==-1&&arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1+4][y_temp1+4]==3-black_or_white) flag8=1; else if(arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1+2]==-1&&arrMapShow[x_temp1+3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1+4][y_temp1+4]==3-black_or_white) flag8=1; else if(arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1+1][y_temp1+1]==-1&&arrMapShow[x_temp1+2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1+4][y_temp1+4]==3-black_or_white) flag8=1; } if(y_temp1<width-3&&x_temp1<width-3&&y_temp1>=2&&x_temp1>=2) { if(arrMapShow[x_temp1-1][y_temp1-1]==-1&&arrMapShow[x_temp1-2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1+3]==3-black_or_white) flag8=1; else if(arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1-2]==-1&&arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1+3]==3-black_or_white) flag8=1; else if(arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1+1][y_temp1+1]==-1&&arrMapShow[x_temp1+2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1+3]==3-black_or_white) flag8=1; } if(y_temp1<width-2&&x_temp1<width-2&&y_temp1>=3&&x_temp1>=3) { if(arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1-2]==-1&&arrMapShow[x_temp1-3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1+2]==3-black_or_white) flag8=1; else if(arrMapShow[x_temp1-1][y_temp1-1]==-1&&arrMapShow[x_temp1-2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1+2]==3-black_or_white) flag8=1; } if(y_temp1>=5&&x_temp1>=5) { if(arrMapShow[x_temp1-1][y_temp1-1]==-1&&arrMapShow[x_temp1-2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1-4][y_temp1-4]==black_or_white&&arrMapShow[x_temp1-1][y_temp1-1]==3-black_or_white) flag8=1; else if(arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1-2]==-1&&arrMapShow[x_temp1-3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1-4][y_temp1-4]==black_or_white&&arrMapShow[x_temp1-1][y_temp1-1]==3-black_or_white) flag8=1; } if(y_temp1>=4&&x_temp1>=4&&y_temp1<width-1&&x_temp1<width-1) { if(arrMapShow[x_temp1+1][y_temp1+1]==-1&&arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1-4][y_temp1-4]==3-black_or_white) flag8=1; else if(arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1-2]==-1&&arrMapShow[x_temp1-3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1-4][y_temp1-4]==3-black_or_white) flag8=1; else if(arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1-1][y_temp1-1]==-1&&arrMapShow[x_temp1-2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1-3]==black_or_white&&arrMapShow[x_temp1-4][y_temp1-4]==3-black_or_white) flag8=1; } if(y_temp1>=3&&x_temp1>=3&&y_temp1<width-2&&x_temp1<width-2) { if(arrMapShow[x_temp1+1][y_temp1+1]==-1&&arrMapShow[x_temp1+2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1-3]==3-black_or_white) flag8=1; else if(arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1+2]==-1&&arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1-3]==3-black_or_white) flag8=1; else if(arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1-1][y_temp1-1]==-1&&arrMapShow[x_temp1-2][y_temp1-2]==black_or_white&&arrMapShow[x_temp1-3][y_temp1-3]==3-black_or_white) flag8=1; } if(y_temp1>=2&&x_temp1>=2&&y_temp1<width-3&&x_temp1<width-3) { if(arrMapShow[x_temp1+1][y_temp1+1]==black_or_white&&arrMapShow[x_temp1+2][y_temp1+2]==-1&&arrMapShow[x_temp1+3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1-2]==3-black_or_white) flag8=1; else if(arrMapShow[x_temp1+1][y_temp1+1]==-1&&arrMapShow[x_temp1+2][y_temp1+2]==black_or_white&&arrMapShow[x_temp1+3][y_temp1+3]==black_or_white&&arrMapShow[x_temp1-1][y_temp1-1]==black_or_white&&arrMapShow[x_temp1-2][y_temp1-2]==3-black_or_white) flag8=1; } if(flag2+flag4+flag6+flag8>=2) return true; return false; } //判斷死二類型 boolean si_er(int x,int y,int black_or_white) { int num=0,i; int x_temp=x,y_temp=y; int x_temp1=x_temp,y_temp1=y_temp; //judge left_up for(i=1;i<3;i++) { x_temp1-=1; y_temp1+=1; if(x_temp1<0||y_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else break; } if(x_temp1==0||y_temp1==width-1||x_temp==width-2||y_temp==1) return false; else if(x_temp1>=1&&x_temp<=width-3&&y_temp>=2&&y_temp1<=width-2) if(num==2&&arrMapShow[x_temp1-1][y_temp1+1]==3-black_or_white&&arrMapShow[x_temp+1][y_temp-1]==-1&&arrMapShow[x_temp+2][y_temp-2]==-1) return true; //judge right_down num=0; x_temp=x;y_temp=y; x_temp1=x_temp;y_temp1=y_temp; for(i=1;i<3;i++) { x_temp1+=1; y_temp1-=1; if(x_temp1>=width||y_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else break; } if(x_temp1==width-1||y_temp1==0||x_temp==1||y_temp==width-2) return false; else if(x_temp>=2&&x_temp1<=width-2&&y_temp1>=1&&y_temp<=width-3) if(num==2&&arrMapShow[x_temp1+1][y_temp1-1]==3-black_or_white&&arrMapShow[x_temp-1][y_temp+1]==-1&&arrMapShow[x_temp-2][y_temp+2]==-1) return true; //judge left_down num=0; x_temp=x;y_temp=y; x_temp1=x_temp;y_temp1=y_temp; for(i=1;i<3;i++) { x_temp1-=1; y_temp1-=1; if(x_temp1<0||y_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else break; } if(x_temp1==0||y_temp1==0||x_temp==width-2||y_temp==width-2) return false; else if(x_temp1>=1&&x_temp<=width-3&&y_temp1>=1&&y_temp<=width-4) if(num==2&&arrMapShow[x_temp1-1][y_temp1-1]==3-black_or_white&&arrMapShow[x_temp+1][y_temp+1]==-1&&arrMapShow[x_temp+2][y_temp+2]==-1) return true; //judge right_up num=0; x_temp=x;y_temp=y; x_temp1=x_temp;y_temp1=y_temp; for(i=1;i<3;i++) { x_temp1+=1; y_temp1+=1; if(x_temp1>=width||y_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else break; } if(x_temp1==width-1||y_temp1==width-1||x_temp==1||y_temp==1) return false; else if(x_temp>=2&&x_temp1<=width-2&&y_temp>=2&&y_temp1<=width-2) if(num==2&&arrMapShow[x_temp1+1][y_temp1+1]==3-black_or_white&&arrMapShow[x_temp-1][y_temp-1]==-1&&arrMapShow[x_temp-2][y_temp-2]==-1) return true; //judge right num=0; x_temp=x;y_temp=y; x_temp1=x_temp;y_temp1=y_temp; for(i=1;i<3;i++) { x_temp1+=1; if(x_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else break; } if(x_temp==1||x_temp1==width-1) return false; else if(x_temp>=2&&x_temp1<=width-2) if(num==2&&arrMapShow[x_temp1+1][y_temp1]==3-black_or_white&&arrMapShow[x_temp-1][y_temp]==-1&&arrMapShow[x_temp-2][y_temp]==-1) return true; //judeg left num=0; x_temp=x;y_temp=y; x_temp1=x_temp;y_temp1=y_temp; for(i=1;i<3;i++) { x_temp1-=1; if(x_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else break; } if(x_temp1==0||x_temp==width-2) return false; else if(x_temp1>=1&&x_temp<=width-3) if(num==2&&arrMapShow[x_temp1-1][y_temp1]==3-black_or_white&&arrMapShow[x_temp+1][y_temp]==-1&&arrMapShow[x_temp+2][y_temp]==-1) return true; //judge up num=0; x_temp=x;y_temp=y; x_temp1=x_temp;y_temp1=y_temp; for(i=1;i<3;i++) { y_temp1+=1; if(y_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else break; } if(y_temp==1||y_temp1==width-1) return false; else if(y_temp>=2&&y_temp1<=width-2) if(num==2&&arrMapShow[x_temp1][y_temp1+1]==3-black_or_white&&arrMapShow[x_temp][y_temp-1]==-1&&arrMapShow[x_temp][y_temp-2]==-1) return true; //judge down num=0; x_temp=x;y_temp=y; x_temp1=x_temp;y_temp1=y_temp; for(i=1;i<3;i++) { y_temp1-=1; if(y_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else break; } if(y_temp1==1||y_temp==width-1) return false; else if(y_temp1>=2&&y_temp<=width-2) if(num==2&&arrMapShow[x_temp1][y_temp1-1]==3-black_or_white&&arrMapShow[x_temp][y_temp+1]==-1&&arrMapShow[x_temp][y_temp+2]==-1) return true; return false; } //判斷活二類型 boolean huo_er(int x,int y,int black_or_white) { int num=0,i; int x_temp=x,y_temp=y; int x_temp1=x_temp,y_temp1=y_temp; //judge left_up for(i=1;i<3;i++) { x_temp1-=1; y_temp1+=1; if(x_temp1<0||y_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else break; } if(x_temp1==0||y_temp1==width-1||x_temp1==width-1||y_temp==0) return false; else if(x_temp1>=1&&x_temp<=width-2&&y_temp>=1&&y_temp1<=width-2) if(num==2&&arrMapShow[x_temp1-1][y_temp1+1]==-1&&arrMapShow[x_temp+1][y_temp-1]==-1) return true; //judge right_down num=0; x_temp=x;y_temp=y; x_temp1=x_temp;y_temp1=y_temp; for(i=1;i<3;i++) { x_temp1+=1; y_temp1-=1; if(x_temp1>=width||y_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else break; } if(x_temp1==width-1||y_temp1==0||x_temp==0||y_temp1==width-1) return false; else if(x_temp>=1&&x_temp1<=width-2&&y_temp1>=1&&y_temp<=width-2) if(num==2&&arrMapShow[x_temp1+1][y_temp1-1]==-1&&arrMapShow[x_temp-1][y_temp+1]==-1) return true; //judge left_down num=0; x_temp=x;y_temp=y; x_temp1=x_temp;y_temp1=y_temp; for(i=1;i<3;i++) { x_temp1-=1; y_temp1-=1; if(x_temp1<0||y_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else break; } if(x_temp1==0||y_temp1==0||x_temp1==width-1||y_temp1==width-1) return false; else if(x_temp1>=1&&x_temp<=width-2&&y_temp1>=1&&y_temp<=width-2) if(num==2&&arrMapShow[x_temp1-1][y_temp1-1]==-1&&arrMapShow[x_temp+1][y_temp+1]==-1) return true; //judge right_up num=0; x_temp=x;y_temp=y; x_temp1=x_temp;y_temp1=y_temp; for(i=1;i<3;i++) { x_temp1+=1; y_temp1+=1; if(x_temp1>=width||y_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else break; } if(x_temp1==width-1||y_temp1==width-1||x_temp==0||y_temp==0) return false; else if(x_temp>=1&&x_temp1<=width-2&&y_temp>=1&&y_temp1<=width-2) if(num==2&&arrMapShow[x_temp1+1][y_temp1+1]==-1&&arrMapShow[x_temp-1][y_temp-1]==-1) return true; //judge right num=0; x_temp=x;y_temp=y; x_temp1=x_temp;y_temp1=y_temp; for(i=1;i<3;i++) { x_temp1+=1; if(x_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else break; } if(x_temp==0||x_temp1==width-1) return false; else if(x_temp>=1&&x_temp1<=width-2) if(num==2&&arrMapShow[x_temp1+1][y_temp1]==-1&&arrMapShow[x_temp-1][y_temp]==-1) return true; //judeg left num=0; x_temp=x;y_temp=y; x_temp1=x_temp;y_temp1=y_temp; for(i=1;i<3;i++) { x_temp1-=1; if(x_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else break; } if(x_temp1==0||x_temp==width-1) return false; else if(x_temp1>=1&&x_temp<=width-2) if(num==2&&arrMapShow[x_temp1-1][y_temp1]==-1&&arrMapShow[x_temp+1][y_temp]==-1) return true; //judge up num=0; x_temp=x;y_temp=y; x_temp1=x_temp;y_temp1=y_temp; for(i=1;i<3;i++) { y_temp1+=1; if(y_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else break; } if(y_temp==0||y_temp1==width-1) return false; else if(y_temp>=1&&y_temp1<=width-2) if(num==2&&arrMapShow[x_temp1][y_temp1+1]==-1&&arrMapShow[x_temp][y_temp-1]==-1) return true; //judge down num=0; x_temp=x;y_temp=y; x_temp1=x_temp;y_temp1=y_temp; for(i=1;i<3;i++) { y_temp1-=1; if(y_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else break; } if(y_temp1==0||y_temp==width-1) return false; else if(y_temp1>=1&&y_temp<=width-2) if(num==2&&arrMapShow[x_temp1][y_temp1-1]==-1&&arrMapShow[x_temp][y_temp+1]==-1) return true; return false; } //判斷斜十字二類型 boolean xie_zi_er(int x,int y,int black_or_white) { int num1=0,i,num2=0; int x_temp=x,y_temp=y; int x_temp1=x_temp,y_temp1=y_temp; for(i=1;i<3;i++) { x_temp1+=1; y_temp1-=1; if(x_temp1>=width||y_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num1++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num1--; else break; } x_temp1=x_temp; y_temp1=y_temp; for(i=1;i<3;i++) { y_temp1-=1; x_temp1-=1; if(y_temp1<0||x_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num2++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num2--; else break; } if(num1==1&&num2==1) return true; num1=0;num2=0; x_temp=x;y_temp=y; x_temp1=x_temp;y_temp1=y_temp; for(i=1;i<3;i++) { x_temp1-=1; y_temp1+=1; if(x_temp1<0||y_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num1++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num1--; else break; } x_temp1=x_temp; y_temp1=y_temp; for(i=1;i<3;i++) { y_temp1-=1; x_temp1-=1; if(y_temp1<0||x_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num2++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num2--; else break; } if(num1==1&&num2==1) return true; num1=0;num2=0; x_temp=x;y_temp=y; x_temp1=x_temp;y_temp1=y_temp; for(i=1;i<3;i++) { x_temp1+=1; y_temp1-=1; if(x_temp1>=width||y_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num1++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num1--; else break; } x_temp1=x_temp; y_temp1=y_temp; for(i=1;i<3;i++) { y_temp1+=1; x_temp1+=1; if(y_temp1>=width||x_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num2++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num2--; else break; } if(num1==1&&num2==1) return true; num1=0;num2=0; x_temp=x;y_temp=y; x_temp1=x_temp;y_temp1=y_temp; for(i=1;i<3;i++) { x_temp1-=1; y_temp1+=1; if(x_temp1<0||y_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num1++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num1--; else break; } x_temp1=x_temp; y_temp1=y_temp; for(i=1;i<3;i++) { y_temp1+=1; x_temp1+=1; if(y_temp1>=width||x_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num2++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num2--; else break; } if(num1==1&&num2==1) return true; return false; } //判斷十字二類型 boolean shi_zi_er(int x,int y,int black_or_white) { int num1=0,i,num2=0; int x_temp=x,y_temp=y; int x_temp1=x_temp,y_temp1=y_temp; //judge right for(i=1;i<3;i++) { x_temp1+=1; if(x_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num1++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num1--; else break; } //judeg down x_temp1=x_temp; for(i=1;i<3;i++) { y_temp1-=1; if(y_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num2++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num2--; else break; } if(num1==1&&num2==1) return true; //judge right num1=0;num2=0; x_temp=x;y_temp=y; x_temp1=x_temp;y_temp1=y_temp; for(i=1;i<3;i++) { x_temp1+=1; if(x_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num1++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num1--; else break; } //judge up x_temp1=x_temp; for(i=1;i<3;i++) { y_temp1+=1; if(y_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num2++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num2--; else break; } if(num1==1&&num2==1) return true; //judge left num1=0;num2=0; x_temp=x;y_temp=y; x_temp1=x_temp;y_temp1=y_temp; for(i=1;i<3;i++) { x_temp1-=1; if(x_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num1++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num1--; else break; } //judge down x_temp1=x_temp; for(i=1;i<3;i++) { y_temp1-=1; if(y_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num2++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num2--; else break; } if(num1==1&&num2==1) return true; //judge left num1=0;num2=0; x_temp=x;y_temp=y; x_temp1=x_temp;y_temp1=y_temp; for(i=1;i<3;i++) { x_temp1-=1; if(x_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num1++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num1--; else break; } //judge up x_temp1=x_temp; for(i=1;i<3;i++) { y_temp1+=1; if(y_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num2++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num2--; else break; } if(num1==1&&num2==1) return true; return false; } //判斷活斷二類型 boolean huo_duan_er(int x,int y,int black_or_white) { int x_temp,y_temp; x_temp=x; y_temp=y; //judge left_right if(x_temp>=2&&x_temp<=width-3) if(arrMapShow[x_temp-1][y_temp]==black_or_white&&arrMapShow[x_temp-2][y_temp]==-1&&arrMapShow[x_temp+1][y_temp]==black_or_white&&arrMapShow[x_temp+2][y_temp]==-1) return true; if(x_temp>=2&&x_temp<=width-4) if(arrMapShow[x_temp-1][y_temp]==black_or_white&&arrMapShow[x_temp-2][y_temp]==-1&&arrMapShow[x_temp+1][y_temp]==-1&&arrMapShow[x_temp+2][y_temp]==black_or_white&&arrMapShow[x_temp+3][y_temp]==-1) return true; if(x_temp>=3&&x_temp<=width-3) if(arrMapShow[x_temp-1][y_temp]==-1&&arrMapShow[x_temp-2][y_temp]==black_or_white&&arrMapShow[x_temp-3][y_temp]==-1&&arrMapShow[x_temp+1][y_temp]==black_or_white&&arrMapShow[x_temp+2][y_temp]==-1) return true; //judge up_down if(y_temp>=2&&y_temp<=width-3) if(arrMapShow[x_temp][y_temp-1]==black_or_white&&arrMapShow[x_temp][y_temp-2]==-1&&arrMapShow[x_temp][y_temp+1]==black_or_white&&arrMapShow[x_temp][y_temp+2]==-1) return true; if(y_temp>=2&&y_temp<=width-4) if(arrMapShow[x_temp][y_temp-1]==black_or_white&&arrMapShow[x_temp][y_temp-2]==-1&&arrMapShow[x_temp][y_temp+1]==-1&&arrMapShow[x_temp][y_temp+2]==black_or_white&&arrMapShow[x_temp][y_temp+3]==-1) return true; if(y_temp>=3&&y_temp<=width-3) if(arrMapShow[x_temp][y_temp-1]==-1&&arrMapShow[x_temp][y_temp-2]==black_or_white&&arrMapShow[x_temp][y_temp-3]==-1&&arrMapShow[x_temp][y_temp+1]==black_or_white&&arrMapShow[x_temp][y_temp+2]==-1) return true; //judge LU_RD if(y_temp>=2&&y_temp<=width-3&&x_temp>=2&&x_temp<=width-3) if(arrMapShow[x_temp-1][y_temp-1]==black_or_white&&arrMapShow[x_temp-2][y_temp-2]==-1&&arrMapShow[x_temp+1][y_temp+1]==black_or_white&&arrMapShow[x_temp+2][y_temp+2]==-1) return true; if(y_temp>=2&&y_temp<=width-4&&x_temp>=2&&x_temp<=width-4) if(arrMapShow[x_temp-1][y_temp-1]==black_or_white&&arrMapShow[x_temp-2][y_temp-2]==-1&&arrMapShow[x_temp+1][y_temp+1]==-1&&arrMapShow[x_temp+2][y_temp+2]==black_or_white&&arrMapShow[x_temp+3][y_temp+3]==-1) return true; if(y_temp>=3&&y_temp<=width-3&&x_temp>=3&&x_temp<=width-3) if(arrMapShow[x_temp-1][y_temp-1]==-1&&arrMapShow[x_temp-2][y_temp-2]==black_or_white&&arrMapShow[x_temp-3][y_temp-3]==-1&&arrMapShow[x_temp+1][y_temp+1]==black_or_white&&arrMapShow[x_temp+2][y_temp+2]==-1) return true; //judge LD_RU if(y_temp>=2&&y_temp<=width-3&&x_temp>=2&&x_temp<=width-3) if(arrMapShow[x_temp-1][y_temp+1]==black_or_white&&arrMapShow[x_temp-2][y_temp+2]==-1&&arrMapShow[x_temp+1][y_temp-1]==black_or_white&&arrMapShow[x_temp+2][y_temp-2]==-1) return true; if(y_temp>=2&&y_temp<=width-4&&x_temp>=2&&x_temp<=width-4) if(arrMapShow[x_temp-1][y_temp+1]==black_or_white&&arrMapShow[x_temp-2][y_temp+2]==-1&&arrMapShow[x_temp+1][y_temp-1]==-1&&arrMapShow[x_temp+2][y_temp-2]==black_or_white&&arrMapShow[x_temp+3][y_temp-3]==-1) return true; if(y_temp>=3&&y_temp<=width-3&&x_temp>=3&&x_temp<=width-3) if(arrMapShow[x_temp-1][y_temp+1]==-1&&arrMapShow[x_temp-2][y_temp+2]==black_or_white&&arrMapShow[x_temp-3][y_temp+3]==-1&&arrMapShow[x_temp+1][y_temp-1]==black_or_white&&arrMapShow[x_temp+2][y_temp-2]==-1) return true; return false; } //判斷活連三類型 boolean huo_lian_san(int x,int y,int black_or_white) { int num=0,i; int x_temp=x,y_temp=y; int x_temp1=x_temp,y_temp1=y_temp; //judge right for(i=1;i<4;i++) { x_temp1+=1; if(x_temp1>=width) break; if(this.arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else if(this.arrMapShow[x_temp1][y_temp1]==3-black_or_white) num--; else break; } if(num==3) { if(x_temp1<this.width-1&&x_temp>=1) if(this.arrMapShow[x_temp1+1][y_temp1]==-1&&this.arrMapShow[x_temp-1][y_temp]==-1) return true; } //judge left x_temp1=x_temp; num=0; for(i=1;i<4;i++) { x_temp1-=1; if(x_temp1<0) break; if(this.arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else if(this.arrMapShow[x_temp1][y_temp1]==3-black_or_white) num--; else break; } if(num==3) { if(x_temp1>=1&&x_temp<this.width-1) if(this.arrMapShow[x_temp1-1][y_temp1]==-1&&this.arrMapShow[x_temp+1][y_temp]==-1) return true; } //judge up num=0; x_temp1=x_temp; y_temp1=y_temp; num=0; for(i=1;i<4;i++) { y_temp1-=1; if(y_temp1<0) break; if(this.arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else if(this.arrMapShow[x_temp1][y_temp1]==3-black_or_white) num--; else break; } if(num==3) { if(y_temp1>=1&&y_temp<this.width-1) if(this.arrMapShow[x_temp1][y_temp1-1]==-1&&this.arrMapShow[x_temp][y_temp+1]==-1) return true; } //judge down y_temp1=y_temp; num=0; for(i=1;i<4;i++) { y_temp1+=1; if(y_temp1>=width) break; if(this.arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else if(this.arrMapShow[x_temp1][y_temp1]==3-black_or_white) num--; else break; } if(num==3) { if(y_temp>=1&&y_temp1<this.width-1) if(this.arrMapShow[x_temp1][y_temp1+1]==-1&&this.arrMapShow[x_temp][y_temp-1]==-1) return true; } //judge left_up x_temp1=x_temp; y_temp1=y_temp; num=0; for(i=1;i<4;i++) { x_temp1-=1; y_temp1-=1; if(y_temp1<0 || x_temp1<0) break; if(this.arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else if(this.arrMapShow[x_temp1][y_temp1]==3-black_or_white) num--; else break; } if(num==3) { if(x_temp1>=1&&y_temp1>=1&&x_temp<this.width-1&&y_temp<this.width-1) if(this.arrMapShow[x_temp1-1][y_temp1-1]==-1&&this.arrMapShow[x_temp+1][y_temp+1]==-1) return true; } //judge right_down x_temp1=x_temp; y_temp1=y_temp; num=0; for(i=1;i<4;i++) { x_temp1+=1; y_temp1+=1; if(y_temp1>=width || x_temp1>=width) break; if(this.arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else if(this.arrMapShow[x_temp1][y_temp1]==3-black_or_white) num--; else break; } if(num==3) { if(x_temp>=1&&y_temp>=1&&x_temp1<this.width-1&&y_temp1<this.width-1) if(this.arrMapShow[x_temp1+1][y_temp1+1]==-1&&this.arrMapShow[x_temp-1][y_temp-1]==-1) return true; } //judge right_up x_temp1=x_temp; y_temp1=y_temp; num=0; for(i=1;i<4;i++) { x_temp1+=1; y_temp1-=1; if(y_temp1<0 || x_temp1>=width) break; if(this.arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else if(this.arrMapShow[x_temp1][y_temp1]==3-black_or_white) num--; else break; } if(num==3) { if(x_temp>=1&&y_temp1>=1&&x_temp1<this.width-1&&y_temp<this.width-1) if(this.arrMapShow[x_temp1+1][y_temp1-1]==-1&&this.arrMapShow[x_temp-1][y_temp+1]==-1) return true; } //judge left_down x_temp1=x_temp; y_temp1=y_temp; num=0; for(i=1;i<4;i++) { x_temp1-=1; y_temp1+=1; if(y_temp1>=width || x_temp1<0) break; if(this.arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else if(this.arrMapShow[x_temp1][y_temp1]==3-black_or_white) num--; else break; } if(num==3) { if(x_temp1>=1&&y_temp>=1&&x_temp<this.width-1&&y_temp1<this.width-1) if(this.arrMapShow[x_temp1-1][y_temp1+1]==-1&&this.arrMapShow[x_temp+1][y_temp-1]==-1) return true; } return false; } //判斷連三類型 boolean si_lian_san(int x,int y,int black_or_white) { int num=0,i; int x_temp=x,y_temp=y; int x_temp1=x_temp,y_temp1=y_temp; //judge right for(i=1;i<4;i++) { x_temp1+=1; if(x_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num--; else break; } if(x_temp1<=width-2&&x_temp>=1) if(num==3) { if(arrMapShow[x_temp1+1][y_temp1]==3-black_or_white&&arrMapShow[x_temp-1][y_temp]==3-black_or_white) return false; else if(arrMapShow[x_temp1+1][y_temp1]==3-black_or_white&&arrMapShow[x_temp-1][y_temp]==-1) { if(black_or_white==2) return true; else return false; } else return true; } //judge left x_temp1=x_temp; num=0; for(i=1;i<4;i++) { x_temp1-=1; if(x_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num--; else break; } if(x_temp1>=1&&x_temp<=width-2) if(num==3) { if(arrMapShow[x_temp1-1][y_temp1]==3-black_or_white&&arrMapShow[x_temp+1][y_temp]==3-black_or_white) return false; else if(arrMapShow[x_temp1-1][y_temp1]==3-black_or_white&&arrMapShow[x_temp+1][y_temp]==-1) { if(black_or_white==2) return true; else return false; } else return true; } //judge up num=0; x_temp1=x_temp; y_temp1=y_temp; num=0; for(i=1;i<4;i++) { y_temp1-=1; if(y_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num--; else break; } if(y_temp1>=1&&y_temp<=width-2) if(num==3) { if(arrMapShow[x_temp1][y_temp1-1]==3-black_or_white&&arrMapShow[x_temp][y_temp+1]==3-black_or_white) return false; else if(arrMapShow[x_temp1][y_temp1-1]==3-black_or_white&&arrMapShow[x_temp][y_temp+1]==-1) { if(black_or_white==2) return true; else return false; } else return true; } //judge down y_temp1=y_temp; num=0; for(i=1;i<4;i++) { y_temp1+=1; if(y_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num--; else break; } if(y_temp1<=width-2&&y_temp>=1) if(num==3) { if(arrMapShow[x_temp1][y_temp1+1]==3-black_or_white&&arrMapShow[x_temp][y_temp-1]==3-black_or_white) return false; else if(arrMapShow[x_temp1][y_temp1+1]==3-black_or_white&&arrMapShow[x_temp][y_temp-1]==-1) { if(black_or_white==2) return true; else return false; } else return true; } //judge left_up x_temp1=x_temp; y_temp1=y_temp; num=0; for(i=1;i<4;i++) { x_temp1-=1; y_temp1-=1; if(y_temp1<0 || x_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num--; else break; } if(x_temp1>=1&&y_temp1>=1&&y_temp<=width-2&&x_temp<=width-2) if(num==3) { if(arrMapShow[x_temp1-1][y_temp1-1]==3-black_or_white&&arrMapShow[x_temp+1][y_temp+1]==3-black_or_white) return false; else if(arrMapShow[x_temp1-1][y_temp1-1]==3-black_or_white&&arrMapShow[x_temp+1][y_temp+1]==-1) { if(black_or_white==2) return true; else return false; } else return true; } //judge right_down x_temp1=x_temp; y_temp1=y_temp; num=0; for(i=1;i<4;i++) { x_temp1+=1; y_temp1+=1; if(y_temp1>=width || x_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num--; else break; } if(x_temp>=1&&y_temp>=1&&y_temp1<=width-2&&x_temp1<=width-2) if(num==3) { if(arrMapShow[x_temp1+1][y_temp1+1]==3-black_or_white&&arrMapShow[x_temp-1][y_temp-1]==3-black_or_white) return false; else if(arrMapShow[x_temp1+1][y_temp1+1]==3-black_or_white&&arrMapShow[x_temp-1][y_temp-1]==-1) { if(black_or_white==2) return true; else return false; } else return true; } //judge right_up x_temp1=x_temp; y_temp1=y_temp; num=0; for(i=1;i<4;i++) { x_temp1+=1; y_temp1-=1; if(y_temp1<0 || x_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num--; else break; } if(x_temp>=1&&y_temp1>=1&&y_temp<=width-2&&x_temp1<=width-2) if(num==3) { if(arrMapShow[x_temp1+1][y_temp1-1]==3-black_or_white&&arrMapShow[x_temp-1][y_temp+1]==3-black_or_white) return false; else if(arrMapShow[x_temp1+1][y_temp1-1]==3-black_or_white&&arrMapShow[x_temp-1][y_temp+1]==-1) { if(black_or_white==2) return true; else return false; } else return true; } //judge left_down x_temp1=x_temp; y_temp1=y_temp; num=0; for(i=1;i<4;i++) { x_temp1-=1; y_temp1+=1; if(y_temp1>=width || x_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num--; else break; } if(x_temp1>=1&&y_temp>=1&&y_temp1<=width-2&&x_temp<=width-2) if(num==3) { if(arrMapShow[x_temp1-1][y_temp1+1]==3-black_or_white&&arrMapShow[x_temp+1][y_temp-1]==3-black_or_white) return false; else if(arrMapShow[x_temp1-1][y_temp1+1]==3-black_or_white&&arrMapShow[x_temp+1][y_temp-1]==-1) { if(black_or_white==2) return true; else return false; } else return true; } return false; } boolean duan_lian_san(int x,int y,int black_or_white) { int num1=0,num2=0,i; int x_temp=x,y_temp=y; int x_temp1=x_temp,y_temp1=y_temp; //judge right for(i=1;i<4;i++) { x_temp1+=1; if(x_temp1>=width-1) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num1++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white&&x_temp1-x_temp!=3) { num1--; break; } else break; } x_temp1=x_temp; for(i=1;i<4;i++) { x_temp1-=1; if(x_temp1<=0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num2++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white&&x_temp-x_temp1!=3) { num2--; break; } else break; } if(num1!=3&&num2!=3&&num1+num2>2) return true; //judge up x_temp1=x_temp; y_temp1=y_temp; num1=0;num2=0; for(i=1;i<4;i++) { y_temp1-=1; if(y_temp1<=0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num1++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white&&y_temp-y_temp1!=3) { num1--; break; } else break; } //judge down y_temp1=y_temp; for(i=1;i<4;i++) { y_temp1+=1; if(y_temp1>=width-1) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num2++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white&&y_temp1-y_temp!=3) { num2--; break; } else break; } if(num1!=3&&num2!=3&&num1+num2>2) return true; //judge left_up x_temp1=x_temp; y_temp1=y_temp; num1=0;num2=0; for(i=1;i<4;i++) { x_temp1-=1; y_temp1-=1; if(y_temp1<=0 || x_temp1<=0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num1++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white&&x_temp-x_temp1!=3) { num1--; break; } else break; } //judge right_down x_temp1=x_temp; y_temp1=y_temp; for(i=1;i<4;i++) { x_temp1+=1; y_temp1+=1; if(y_temp1>=width-1 || x_temp1>=width-1) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num2++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white&&x_temp1-x_temp!=3) { num2--; break; } else break; } if(num1!=3&&num2!=3&&num1+num2>2) return true; //judge right_up x_temp1=x_temp; y_temp1=y_temp; num1=0;num2=0; for(i=1;i<4;i++) { x_temp1+=1; y_temp1-=1; if(y_temp1<=0 || x_temp1>=width-1) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num1++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white&&x_temp1-x_temp!=3) { num1--; break; } else break; } //judge left_down x_temp1=x_temp; y_temp1=y_temp; for(i=1;i<4;i++) { x_temp1-=1; y_temp1+=1; if(y_temp1>=width-1 || x_temp1<=0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num2++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white&&x_temp-x_temp1!=3) { num2--; break; } else break; } if(num1!=3&&num2!=3&&num1+num2>2) return true; return false; } boolean lian_si(int x,int y,int black_or_white) { int num1=0,max_num,max_temp=0,num2=0,i; int x_temp=x,y_temp=y; int x_temp1=x_temp,y_temp1=y_temp; //judge right for(i=1;i<5;i++) { x_temp1+=1; if(x_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num1++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num1--; else break; } if(num1==4) return true; //judge left x_temp1=x_temp; for(i=1;i<5;i++) { x_temp1-=1; if(x_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num2++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num2--; else break; } max_temp=num1+num2; //judge up x_temp1=x_temp; y_temp1=y_temp; num1=0; num2=0; for(i=1;i<5;i++) { y_temp1-=1; if(y_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num1++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num1--; else break; } if(num1==4) return true; //judge down y_temp1=y_temp; for(i=1;i<5;i++) { y_temp1+=1; if(y_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num2++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num2--; else break; } if(num2==4) return true; if(num1+num2>max_temp) max_temp=num1+num2; //judge left_up x_temp1=x_temp; y_temp1=y_temp; num1=0; num2=0; for(i=1;i<5;i++) { x_temp1-=1; y_temp1-=1; if(y_temp1<0 || x_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num1++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num1--; else break; } if(num1==4) return true; //judge right_down x_temp1=x_temp; y_temp1=y_temp; for(i=1;i<5;i++) { x_temp1+=1; y_temp1+=1; if(y_temp1>=width || x_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num2++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num2--; else break; } if(num2==4) return true; if(num1+num2>max_temp) max_temp=num1+num2; //judge right_up x_temp1=x_temp; y_temp1=y_temp; num1=0; num2=0; for(i=1;i<5;i++) { x_temp1+=1; y_temp1-=1; if(y_temp1<0 || x_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num1++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num1--; else break; } if(num1==4) return true; //judge left_down x_temp1=x_temp; y_temp1=y_temp; for(i=1;i<5;i++) { x_temp1-=1; y_temp1+=1; if(y_temp1>=width || x_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num2++; else if(arrMapShow[x_temp1][y_temp1]==3-black_or_white) num2--; else break; } if(num2==4) return true; if(num1+num2>max_temp) max_temp=num1+num2; max_num=max_temp; if(max_num>3) return true; return false; } //判斷連斷四類型 boolean lian_duan_si(int x,int y,int black_or_white) { int x_temp=x,y_temp=y; //judeg left if(x_temp<=width-5&&x_temp>=0) if(arrMapShow[x_temp+1][y_temp]==-1&&arrMapShow[x_temp+2][y_temp]==black_or_white&&arrMapShow[x_temp+3][y_temp]==black_or_white&&arrMapShow[x_temp+4][y_temp]==black_or_white) return true; //judge right if(x_temp<=width-5&&x_temp>=4) if(arrMapShow[x_temp-1][y_temp]==-1&&arrMapShow[x_temp-2][y_temp]==black_or_white&&arrMapShow[x_temp-3][y_temp]==black_or_white&&arrMapShow[x_temp-4][y_temp]==black_or_white) return true; //judeg up if(y_temp<=width-5&&y_temp>=0) if(arrMapShow[x_temp][y_temp+1]==-1&&arrMapShow[x_temp][y_temp+2]==black_or_white&&arrMapShow[x_temp][y_temp+3]==black_or_white&&arrMapShow[x_temp][y_temp+4]==black_or_white) return true; //judge down if(y_temp<=width-5&&y_temp>=4) if(arrMapShow[x_temp][y_temp-1]==-1&&arrMapShow[x_temp][y_temp-2]==black_or_white&&arrMapShow[x_temp][y_temp-3]==black_or_white&&arrMapShow[x_temp][y_temp-4]==black_or_white) return true; //judge U_L if(x_temp<=width-5&&x_temp>=0&&y_temp<=width-5&&y_temp>=0) if(arrMapShow[x_temp+1][y_temp+1]==-1&&arrMapShow[x_temp+2][y_temp+2]==black_or_white&&arrMapShow[x_temp+3][y_temp+3]==black_or_white&&arrMapShow[x_temp+4][y_temp+4]==black_or_white) return true; //judge D_L if(x_temp<=width-5&&x_temp>=0&&y_temp<=width-5&&y_temp>=4) if(arrMapShow[x_temp+1][y_temp-1]==-1&&arrMapShow[x_temp+2][y_temp-2]==black_or_white&&arrMapShow[x_temp+3][y_temp-3]==black_or_white&&arrMapShow[x_temp+4][y_temp-4]==black_or_white) return true; //judge U_R if(x_temp<=width-5&&x_temp>=4&&y_temp<=width-5&&y_temp>=0) if(arrMapShow[x_temp-1][y_temp+1]==-1&&arrMapShow[x_temp-2][y_temp+2]==black_or_white&&arrMapShow[x_temp-3][y_temp+3]==black_or_white&&arrMapShow[x_temp-4][y_temp+4]==black_or_white) return true; //judge D_R if(x_temp<=width-5&&x_temp>=4&&y_temp<=width-5&&y_temp>=4) if(arrMapShow[x_temp-1][y_temp-1]==-1&&arrMapShow[x_temp-2][y_temp-2]==black_or_white&&arrMapShow[x_temp-3][y_temp-3]==black_or_white&&arrMapShow[x_temp-4][y_temp-4]==black_or_white) return true; return false; } boolean duan_lian_si(int x,int y,int black_or_white) { int num1=0,max_temp=0,num2=0,i; int x_temp=x,y_temp=y; int x_temp1=x_temp,y_temp1=y_temp; //judge right for(i=1;i<4;i++) { x_temp1+=1; if(x_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num1++; else break; } //judge left x_temp1=x_temp; for(i=1;i<4;i++) { x_temp1-=1; if(x_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num2++; else break; } max_temp=num1+num2; if(max_temp>=4) return true; //judge up x_temp1=x_temp; y_temp1=y_temp; num1=0; num2=0; for(i=1;i<4;i++) { y_temp1-=1; if(y_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num1++; else break; } //judge down y_temp1=y_temp; for(i=1;i<4;i++) { y_temp1+=1; if(y_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num2++; else break; } max_temp=num1+num2; if(max_temp>=4) return true; //judge left_up x_temp1=x_temp; y_temp1=y_temp; num1=0; num2=0; for(i=1;i<4;i++) { x_temp1-=1; y_temp1-=1; if(y_temp1<0 || x_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num1++; else break; } //judge right_down x_temp1=x_temp; y_temp1=y_temp; for(i=1;i<4;i++) { x_temp1+=1; y_temp1+=1; if(y_temp1>=width || x_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num2++; else break; } max_temp=num1+num2; if(max_temp>=4) return true; //judge right_up x_temp1=x_temp; y_temp1=y_temp; num1=0; num2=0; for(i=1;i<4;i++) { x_temp1+=1; y_temp1-=1; if(y_temp1<0 || x_temp1>=width) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num1++; else break; } //judge left_down x_temp1=x_temp; y_temp1=y_temp; for(i=1;i<4;i++) { x_temp1-=1; y_temp1+=1; if(y_temp1>=width || x_temp1<0) break; if(arrMapShow[x_temp1][y_temp1]==black_or_white) num2++; else break; } max_temp=num1+num2; if(max_temp>=4) return true; return false; } boolean zhouwei3(int x,int y,int black_or_white) { int x_temp=x,y_temp=y,num1=0,num2=0; if(x_temp>=1) { if(arrMapShow[x_temp-1][y_temp]==black_or_white) num1++; else if(arrMapShow[x_temp-1][y_temp]==3-black_or_white) num2++; } if(x_temp<width-1) { if(arrMapShow[x_temp+1][y_temp]==black_or_white) num1++; else if(arrMapShow[x_temp+1][y_temp]==3-black_or_white) num2++; } if(y_temp>=1) { if(arrMapShow[x_temp][y_temp-1]==black_or_white) num1++; else if(arrMapShow[x_temp][y_temp-1]==3-black_or_white) num2++; } if(y_temp<width-1) { if(arrMapShow[x_temp][y_temp+1]==black_or_white) num1++; else if(arrMapShow[x_temp][y_temp+1]==3-black_or_white) num2++; } if(x_temp>=1&&y_temp>=1) { if(arrMapShow[x_temp-1][y_temp-1]==black_or_white) num1++; else if(arrMapShow[x_temp-1][y_temp-1]==3-black_or_white) num2++; } if(x_temp<width-1&&y_temp>=1) { if(arrMapShow[x_temp+1][y_temp-1]==black_or_white) num1++; else if(arrMapShow[x_temp+1][y_temp-1]==3-black_or_white) num2++; } if(x_temp>=1&&y_temp<width-1) { if(arrMapShow[x_temp-1][y_temp+1]==black_or_white) num1++; else if(arrMapShow[x_temp-1][y_temp+1]==3-black_or_white) num2++; } if(x_temp<width-1&&y_temp<width-1) { if(arrMapShow[x_temp+1][y_temp+1]==black_or_white) num1++; else if(arrMapShow[x_temp][y_temp+1]==3-black_or_white) num2++; } if(num2-num1>=3) return true; return false; } boolean zhouwei2(int x,int y,int black_or_white) { int x_temp=x,y_temp=y,num1=0,num2=0; if(x_temp>=1) { if(arrMapShow[x_temp-1][y_temp]==black_or_white) num1++; else if(arrMapShow[x_temp-1][y_temp]==3-black_or_white) num2++; } if(x_temp<width-1) { if(arrMapShow[x_temp+1][y_temp]==black_or_white) num1++; else if(arrMapShow[x_temp+1][y_temp]==3-black_or_white) num2++; } if(y_temp>=1) { if(arrMapShow[x_temp][y_temp-1]==black_or_white) num1++; else if(arrMapShow[x_temp][y_temp-1]==3-black_or_white) num2++; } if(y_temp<width-1) { if(arrMapShow[x_temp][y_temp+1]==black_or_white) num1++; else if(arrMapShow[x_temp][y_temp+1]==3-black_or_white) num2++; } if(x_temp>=1&&y_temp>=1) { if(arrMapShow[x_temp-1][y_temp-1]==black_or_white) num1++; else if(arrMapShow[x_temp-1][y_temp-1]==3-black_or_white) num2++; } if(x_temp<width-1&&y_temp>=1) { if(arrMapShow[x_temp+1][y_temp-1]==black_or_white) num1++; else if(arrMapShow[x_temp+1][y_temp-1]==3-black_or_white) num2++; } if(x_temp>=1&&y_temp<width-1) { if(arrMapShow[x_temp-1][y_temp+1]==black_or_white) num1++; else if(arrMapShow[x_temp-1][y_temp+1]==3-black_or_white) num2++; } if(x_temp<width-1&&y_temp<width-1) { if(arrMapShow[x_temp+1][y_temp+1]==black_or_white) num1++; else if(arrMapShow[x_temp][y_temp+1]==3-black_or_white) num2++; } if(num2-num1>=2) return true; return false; } boolean zhouwei1(int x,int y,int black_or_white) { int x_temp=x,y_temp=y,num1=0,num2=0; if(x_temp>=1) { if(arrMapShow[x_temp-1][y_temp]==black_or_white) num1++; else if(arrMapShow[x_temp-1][y_temp]==3-black_or_white) num2++; } if(x_temp<width-1) { if(arrMapShow[x_temp+1][y_temp]==black_or_white) num1++; else if(arrMapShow[x_temp+1][y_temp]==3-black_or_white) num2++; } if(y_temp>=1) { if(arrMapShow[x_temp][y_temp-1]==black_or_white) num1++; else if(arrMapShow[x_temp][y_temp-1]==3-black_or_white) num2++; } if(y_temp<width-1) { if(arrMapShow[x_temp][y_temp+1]==black_or_white) num1++; else if(arrMapShow[x_temp][y_temp+1]==3-black_or_white) num2++; } if(x_temp>=1&&y_temp>=1) { if(arrMapShow[x_temp-1][y_temp-1]==black_or_white) num1++; else if(arrMapShow[x_temp-1][y_temp-1]==3-black_or_white) num2++; } if(x_temp<width-1&&y_temp>=1) { if(arrMapShow[x_temp+1][y_temp-1]==black_or_white) num1++; else if(arrMapShow[x_temp+1][y_temp-1]==3-black_or_white) num2++; } if(x_temp>=1&&y_temp<width-1) { if(arrMapShow[x_temp-1][y_temp+1]==black_or_white) num1++; else if(arrMapShow[x_temp-1][y_temp+1]==3-black_or_white) num2++; } if(x_temp<width-1&&y_temp<width-1) { if(arrMapShow[x_temp+1][y_temp+1]==black_or_white) num1++; else if(arrMapShow[x_temp][y_temp+1]==3-black_or_white) num2++; } if(num2-num1>=1) return true; return false; } //判斷勝負 public boolean judgeSuccess(int x,int y,boolean isodd){ int num1=1,num2=1; int arrvalue; int x_temp=x,y_temp=y; if(isodd) arrvalue=2; else arrvalue=1; int x_temp1=x_temp,y_temp1=y_temp; //判斷右邊 for(int i=1;i<6;i++){ x_temp1+=1; if(x_temp1>this.width) break; if(this.arrMapShow[x_temp1][y_temp1]==arrvalue) num1++; else break; } if(num1==5) return true; //判斷左邊 x_temp1=x_temp; for(int i=1;i<6;i++){ x_temp1-=1; if(x_temp1<0) break; if(this.arrMapShow[x_temp1][y_temp1]==arrvalue) num2++; else break; } if(num2==5) return true; if((num1+num2)>=6) return true; //判斷上方 x_temp1=x_temp; y_temp1=y_temp; num1=1; num2=1; for(int i=1;i<6;i++){ y_temp1-=1; if(y_temp1<0) break; if(this.arrMapShow[x_temp1][y_temp1]==arrvalue) num1++; else break; } if(num1==5) return true; //判斷下方 y_temp1=y_temp; for(int i=1;i<6;i++){ y_temp1+=1; if(y_temp1>this.width) break; if(this.arrMapShow[x_temp1][y_temp1]==arrvalue) num2++; else break; } if(num2==5) return true; if((num1+num2)>=6) return true; //判斷左上 x_temp1=x_temp; y_temp1=y_temp; num1=1; num2=1; for(int i=1;i<6;i++){ x_temp1-=1; y_temp1-=1; if(y_temp1<0 || x_temp1<0) break; if(this.arrMapShow[x_temp1][y_temp1]==arrvalue) num1++; else break; } if(num1==5) return true; //判斷右下 x_temp1=x_temp; y_temp1=y_temp; for(int i=1;i<6;i++){ x_temp1+=1; y_temp1+=1; if(y_temp1>this.width || x_temp1>this.width) break; if(this.arrMapShow[x_temp1][y_temp1]==arrvalue) num2++; else break; } if(num2==5) return true; if((num1+num2)>=6) return true; //判斷右上 x_temp1=x_temp; y_temp1=y_temp; num1=1; num2=1; for(int i=1;i<6;i++){ x_temp1+=1; y_temp1-=1; if(y_temp1<0 || x_temp1>this.width) break; if(this.arrMapShow[x_temp1][y_temp1]==arrvalue) num1++; else break; } if(num1==5) return true; //判斷左下 x_temp1=x_temp; y_temp1=y_temp; for(int i=1;i<6;i++){ x_temp1-=1; y_temp1+=1; if(y_temp1>this.width || x_temp1<0) break; if(this.arrMapShow[x_temp1][y_temp1]==arrvalue) num2++; else break; } if(num2==5) return true; if((num1+num2)>=6) return true; return false; } //黑方獲勝後的提示 public void blackSuccess(JPanel jp) { JOptionPane.showMessageDialog(jp,"黑方獲勝!","win", JOptionPane.INFORMATION_MESSAGE); } //白方獲勝後的提示 public void whiteSuccess(JPanel jp) { JOptionPane.showMessageDialog(jp,"白方獲勝!","win", JOptionPane.INFORMATION_MESSAGE); } //贏棋後的提示 public void showSuccess(JPanel jp) { JOptionPane.showMessageDialog(jp,"你贏了,好厲害!","win", JOptionPane.INFORMATION_MESSAGE); cf.setFocusable(false); } //輸棋後的提示 public void showDefeat(JPanel jp) { JOptionPane.showMessageDialog(jp,"你輸了,請重新開始!","lost", JOptionPane.INFORMATION_MESSAGE); cf.setFocusable(false); } } /* *類MainPanel主要完成如下功能: *1、構建一個面板,在該面板上畫上棋盤; *2、處理在該棋盤上的鼠標事件(如鼠標左鍵點擊、鼠標右鍵點擊、鼠標拖動等) **/ class MainPanel extends JPanel implements MouseListener,MouseMotionListener{ /** * */ private static final long serialVersionUID = 1L; private int width,height;//棋盤的寬度和高度 private ChessModel cm; //根據棋盤模式設定面板的大小 MainPanel(final ChessModel mm){ cm=mm; width=cm.getWidth(); height=cm.getWidth(); addMouseListener(this); } //根據棋盤模式設定棋盤的寬度和高度 public void setModel(final ChessModel mm){ cm = mm; width = cm.getWidth(); height = cm.getWidth(); } //根據座標計算出棋盤方格棋子的信息(如白子還是黑子), //然後調用draw方法在棋盤上畫出相應的棋子 public void paintComponent(final Graphics g){ super.paintComponent(g); for(int j = 0; j <=height; j++){ for(int i = 0; i <=width; i++){ final int v = cm.getarrMapShow()[i][j]; draw(g, i, j, v); } } } //根據提供的棋子信息(顏色、座標)畫棋子 public void draw(final Graphics g, final int i, final int j, final int v){ final int x = 30 * i+30; final int y = 30 * j+30; //畫棋盤 if(i!=width && j!=height){ g.setColor(Color.gray); g.drawRect(x,y,30,30); g.setColor(Color.black); g.fillRect(width*15+27, height*15+27, 7, 7);//畫中間標誌點 g.fillRect(width*7+19, height*7+19, 7, 7); //畫左上角標誌點 g.fillRect(width*23+35, height*23+35, 7, 7); g.fillRect(width*23+35, height*7+19, 7, 7); g.fillRect(width*7+19, height*23+35, 7, 7); } //畫黑色棋子 if(v == 1 ){ g.setColor(Color.gray); g.drawOval(x-11,y-11,22,22); g.setColor(Color.black); g.fillOval(x-11,y-11,22,22); } //畫白色棋子 if(v == 2 ){ g.setColor(Color.gray); g.drawOval(x-11,y-11,22,22); g.setColor(Color.white); g.fillOval(x-11,y-11,22,22); } if(v ==3){ g.setColor(Color.cyan); g.drawOval(x-11,y-11,22,22); } } //響應鼠標的點擊事件,根據鼠標的點擊來下棋, //根據下棋判斷勝負等 public void mousePressed(final MouseEvent evt){ final int x = (evt.getX()-10) / 30; final int y = (evt.getY()-10) / 30; int flag=1; System.out.println(x+" "+y); if (evt.getModifiers()==MouseEvent.BUTTON1_MASK) { for(int m=0;m<=cm.getWidth();m++) { for(int n=0;n<=cm.getWidth();n++) { ChessFrame.qipan[m][n]=cm.arrMapShow[m][n]; } } if(cm.arrMapShow[x][y]==-1) { cm.play(x,y); System.out.println(cm.getisOdd()+" "+cm.getarrMapShow()[x][y]); repaint(); //判斷是否爲人機對弈 if(ChessFrame.iscomputer&&!cm.getisExist()) { if(cm.judgeSuccess(x,y,false)==true) { JPanel jp=new JPanel(); cm.showSuccess(jp); flag=0; } repaint(); if(flag==1) cm.computerDo(0); } else if(!ChessFrame.iscomputer&&!cm.getisExist()) { if(cm.judgeSuccess(x,y,false)==true) { JPanel jp=new JPanel(); cm.blackSuccess(jp); } else if(cm.judgeSuccess(x,y,true)==true) { JPanel jp=new JPanel(); cm.whiteSuccess(jp); } repaint(); } } } } public void mouseClicked(final MouseEvent evt){} public void mouseReleased(final MouseEvent evt){} public void mouseEntered(final MouseEvent mouseevt){} public void mouseExited(final MouseEvent mouseevent){} public void mouseDragged(final MouseEvent evt){} //響應鼠標的拖動事件 public void mouseMoved(final MouseEvent moveevt){ // final int x = (moveevt.getX()-10) / 20; // final int y = (moveevt.getY()-10) / 20; // cm.readyplay(x,y); // repaint(); } } class ChessWindowEvent extends WindowAdapter{ public void windowClosing(WindowEvent e){ System.exit(0); } ChessWindowEvent(){} }
一、前言 上一篇文章講使用ffmpeg函數接口去獲取本地攝像頭信息,這種方式只能從ffmpeg5版本開始才具備,那ffmpeg3/4只能乾瞪眼?那肯定不行的,必須要想辦法打通這個功能,查閱信息發現可以執行命令 ffmpeg -f dshow
## spring security https://github.com/jitwxs/blog-sample/tree/master
OAuth(開放授權)是一種開放標準,用於允許用戶在不暴露其憑據(如用戶名和密碼)的情況下,讓第三方應用程序訪問其資源(如用戶的照片、視頻、聯繫人列表等)。OAuth 主要用於授權,而不是身份驗證。 背景 OAuth,全稱爲Open Aut
這篇博文包括 Onehouse 首席執行官 Vinoth Chandar 於 2022 年 3 月在奧斯汀數據委員會發表的重要演講的後半部分。本文是第 2 部分,比較了架構的功能和性價比特徵。最後,它描述了一個面向未來的、湖倉一體的架構。
前言 在這個快速發展的技術世界中,時常會有一些重要的知識點、信息或細節被忽略或遺漏。《C#/.NET/.NET Core拾遺補漏》專欄我們將探討一些可能被忽略或遺漏的重要知識點、信息或細節,以幫助大家更全面地瞭解這些技術棧的特性和發展
本週刊由 Python貓 出品,精心篩選國內外的 250+ 信息源,爲你挑選最值得分享的文章、教程、開源項目、軟件工具、播客和視頻、熱門話題等內容。願景:幫助所有讀者精進 Python 技術,並增長職業和副業的收入。 本期週刊分享了 12
# encoding: utf-8 # 版權所有 2024 塗聚文有限公司 # 許可信息查看: # 描述: # Author : geovindu,Geovin Du 塗聚文. # IDE : PyCharm 202
定期運行 OPTIMIZE TABLE 和 ANALYZE TABLE 命令,以確保表的統計信息是最新的,索引也得到了優化。 OPTIMIZE TABLE wp_posts; ANALYZE TABLE wp_posts; OPTIMIZ
支持高吞吐數據攝入、變更追蹤、高效分析的流批數據湖 基於LSM提升寫入速度並降低寫入消耗;基於有序的SortRun裁剪大部分數據以提升查詢性能;支持多種merge引擎實現高性能流表打寬 基於Flink&Paimon實現,提供數據一致性管理能
3060 (Pytorch 2) 4090 (Pytorch 2) 3060 (Pytorch 1) name: basechannels: - nvidia/label/cuda-11.8.0 - defaultsdep
1 !apt list --installed 2 Listing... Done 3 accountsservice/now 0.6.55-0ubuntu12~20.04.5 amd64 [installed,upgr
https://blog.csdn.net/zhuizhufanxin123/article/details/103982940
Metasploit(MSF)使用詳解—以kali系統環境下永恆之藍(ms17_010)爲例 https://blog.csdn.net/weoptions/article/details/133039825 https://blog.cs
Why do you need VirtIO driver? It's useful when you use Linux/Windows VMs in PVE. Usually when you attach a network to t
涓涓細流,終匯大海。 在 "Shell 小技能" 一文中,講到了 Shell 組合 linux 命令的實用小技能。每一條 linux 命令,都是一個小工具。 Shell 可以將很多小工具組合成更強大的實用工具。 本文主要梳理程序員常用