服务器之家

服务器之家 > 正文

java基于swing实现的五子棋游戏代码

时间:2019-12-04 12:41     来源/作者:shichen2014

本文实例讲述了java基于swing实现的五子棋游戏代码。分享给大家供大家参考。

主要功能代码如下:

 

复制代码代码如下:


import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Main extends JFrame implements ActionListener{
        private static final long serialVersionUID = 1L;
        JButton[][] point=new JButton[40][40];
        int[][] state=new int[40][40];
        int[][] value=new int[40][40];
        int[] place=new int[2];
        public Main(){
                this.setTitle("五子棋");
                this.setBounds(100,10,1000,1000);
                this.setLayout(new GridLayout(30,30));
                int i,j;
                for(i=0;i<=39;i++){
                        for(j=0;j<=39;j++){
                                state[i][j]=0;
                                value[i][j]=0;
                        }
                }
                for(i=5;i<=34;i++){
                        for (j=5;j<=34;j++){
                                point[i][j]=new JButton("");
                                this.add(point[i][j]);
                                point[i][j].addActionListener(this);
                        }
                }
                this.setVisible(true);
        }
        public void actionPerformed(ActionEvent e)
    {
            int i,j;
            for(i=5;i<=34;i++){
                    for(j=5;j<=34;j++){
                            if(e.getSource()==point[i][j]){
                                    point[i][j].setBackground(Color.RED);
                                    state[i][j]=1;
                                    point[i][j].setEnabled(false);
                                    value[i][j]=0;
                            }
                    }
            }
            for(i=5;i<=34;i++){
                    for(j=5;j<=34;j++){
                            value[i][j]=value(i,j);
                            if(((state[i][j]==1)&&(state[i][j+1]==1)&&(state[i][j+2]==1)&&(state[i][j+3]==1)&&(state[i][j+4]==1))||
                                           ((state[i][j]==1)&&(state[i+1][j]==1)&&(state[i+2][j]==1)&&(state[i+3][j]==1)&&(state[i+4][j]==1))||
                                           ((state[i][j]==1)&&(state[i-1][j+1]==1)&&(state[i-2][j+2]==1)&&(state[i-3][j+3]==1)&&(state[i-4][j+4]==1))||
                                           ((state[i][j]==1)&&(state[i+1][j+1]==1)&&(state[i+2][j+2]==1)&&(state[i+3][j+3]==1)&&(state[i+4][j+4]==1))){
                                    JOptionPane.showMessageDialog(null,"你太厉害了吧,我打不过你");
                            }

 

                    }
            }
            place=largestValue(value);
            point[place[0]][place[1]].setBackground(Color.blue);
            state[place[0]][place[1]]=2;
            value[place[0]][place[1]]=0;
                    for(i=5;i<=34;i++){
                            for(j=5;j<=34;j++){
                                    if(((state[i][j]==2)&&(state[i][j+1]==2)&&(state[i][j+2]==2)&&(state[i][j+3]==2)&&(state[i][j+4]==2))||
                                           ((state[i][j]==2)&&(state[i+1][j]==2)&&(state[i+2][j]==2)&&(state[i+3][j]==2)&&(state[i+4][j]==2))||
                                           ((state[i][j]==2)&&(state[i-1][j+1]==2)&&(state[i-2][j+2]==2)&&(state[i-3][j+3]==2)&&(state[i-4][j+4]==2))||
                                           ((state[i][j]==2)&&(state[i+1][j+1]==2)&&(state[i+2][j+2]==2)&&(state[i+3][j+3]==2)&&(state[i+4][j+4]==2))){
                                            JOptionPane.showMessageDialog(null,"还是没我厉害吧");
                                    }
                            }
                    }


    }

    public static void main(String[] args)throws NullPointerException{
            new Main();
    }
    public int value(int i,int j){

            if(((state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==1)&&(state[i][j+3]==1)&&(state[i][j+4]==1)&&(state[i][j+5]==0))||
                           ((state[i][j]==0)&&(state[i][j-1]==1)&&(state[i][j-2]==1)&&(state[i][j-3]==1)&&(state[i][j-4]==1)&&(state[i][j-5]==0))||
                           ((state[i][j]==0)&&(state[i-1][j]==1)&&(state[i-2][j]==1)&&(state[i-3][j]==1)&&(state[i-4][j]==1)&&(state[i-5][j]==0))||
                           ((state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==1)&&(state[i+3][j]==1)&&(state[i+4][j]==1)&&(state[i+5][j]==0))||
                           ((state[i][j]==0)&&(state[i+1][j+1]==1)&&(state[i+2][j+2]==1)&&(state[i+3][j+3]==1)&&(state[i+4][j+4]==1)&&(state[i+5][j+5]==0))||           //空红红红红空型
                           ((state[i][j]==0)&&(state[i-1][j+1]==1)&&(state[i-2][j+2]==1)&&(state[i-3][j+3]==1)&&(state[i-4][j+4]==1)&&(state[i-5][j+5]==0))||
                           ((state[i][j]==0)&&(state[i+1][j-1]==1)&&(state[i+2][j-2]==1)&&(state[i+3][j-3]==1)&&(state[i+4][j-4]==1)&&(state[i+5][j-5]==0))||
                           ((state[i][j]==0)&&(state[i-1][j-1]==1)&&(state[i-2][j-2]==1)&&(state[i-3][j-3]==1)&&(state[i-4][j-4]==1)&&(state[i-5][j-5]==0))){
                           value[i][j]=8;
                           return value[i][j];
                }
                else if(((state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==2)&&(state[i][j+3]==2)&&(state[i][j+4]==2)&&(state[i][j+5]==0))||
                                ((state[i][j]==0)&&(state[i][j-1]==2)&&(state[i][j-2]==2)&&(state[i][j-3]==2)&&(state[i][j-4]==2)&&(state[i][j-5]==0))||
                                ((state[i][j]==0)&&(state[i-1][j]==2)&&(state[i-2][j]==2)&&(state[i-3][j]==2)&&(state[i-4][j]==2)&&(state[i-5][j]==0))||                   //空红红红红空型
                                ((state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==2)&&(state[i+3][j]==2)&&(state[i+4][j]==2)&&(state[i+5][j]==0))||
                                ((state[i][j]==0)&&(state[i+1][j+1]==2)&&(state[i+2][j+2]==2)&&(state[i+3][j+3]==2)&&(state[i+4][j+4]==2)&&(state[i+5][j+5]==0))||
                                ((state[i][j]==0)&&(state[i-1][j+1]==2)&&(state[i-2][j+2]==2)&&(state[i-3][j+3]==2)&&(state[i-4][j+4]==2)&&(state[i-5][j+5]==0))||
                                ((state[i][j]==0)&&(state[i+1][j-1]==2)&&(state[i+2][j-2]==2)&&(state[i+3][j-3]==2)&&(state[i+4][j-4]==2)&&(state[i+5][j-5]==0))||
                                ((state[i][j]==0)&&(state[i-1][j-1]==2)&&(state[i-2][j-2]==2)&&(state[i-3][j-3]==2)&&(state[i-4][j-4]==2)&&(state[i-5][j-5]==0))){
                                value[i][j]=7;
                                return value[i][j];
                }
                else if(((state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==1)&&(state[i][j+3]==1)&&(state[i][j+4]==0))||
                                ((state[i][j]==0)&&(state[i][j-1]==1)&&(state[i][j-2]==1)&&(state[i][j-3]==1)&&(state[i][j-4]==0))||
                                ((state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==1)&&(state[i+3][j]==1)&&(state[i+4][j]==0))||
                                ((state[i][j]==0)&&(state[i-1][j]==1)&&(state[i-2][j]==1)&&(state[i-3][j]==1)&&(state[i-4][j]==0))||                            //空红红红空型
                                ((state[i][j]==0)&&(state[i+1][j+1]==1)&&(state[i+2][j+2]==1)&&(state[i+3][j+3]==1)&&(state[i+4][j+4]==0))||
                                ((state[i][j]==0)&&(state[i+1][j-1]==1)&&(state[i+2][j-2]==1)&&(state[i+3][j-3]==1)&&(state[i+4][j-4]==0))||
                                ((state[i][j]==0)&&(state[i-1][j+1]==1)&&(state[i-2][j+2]==1)&&(state[i-3][j+3]==1)&&(state[i-4][j+4]==0))||
                                ((state[i][j]==0)&&(state[i-1][j-1]==1)&&(state[i-2][j-2]==1)&&(state[i-3][j-3]==1)&&(state[i-4][j-4]==0))||

                                ((state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==0)&&(state[i][j+3]==1)&&(state[i][j+4]==1)&&(state[i][j+5]==0))||
                                ((state[i][j]==0)&&(state[i][j-1]==1)&&(state[i][j-2]==0)&&(state[i][j-3]==1)&&(state[i][j-4]==1)&&(state[i][j-5]==0))||
                                ((state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==0)&&(state[i+3][j]==1)&&(state[i+4][j]==1)&&(state[i+5][j]==0))||
                                ((state[i][j]==0)&&(state[i-1][j]==1)&&(state[i-2][j]==0)&&(state[i-3][j]==1)&&(state[i-4][j]==1)&&(state[i-5][j]==0))||                               //空红空红红空
                                ((state[i][j]==0)&&(state[i+1][j+1]==1)&&(state[i+2][j+2]==0)&&(state[i+3][j+3]==1)&&(state[i+4][j+4]==1)&&(state[i+5][j+5]==0))||
                                ((state[i][j]==0)&&(state[i+1][j-1]==1)&&(state[i+2][j-2]==0)&&(state[i+3][j-3]==1)&&(state[i+4][j-4]==1)&&(state[i+5][j-5]==0))||
                                ((state[i][j]==0)&&(state[i-1][j+1]==1)&&(state[i-2][j+2]==0)&&(state[i-3][j+3]==1)&&(state[i-4][j+4]==1)&&(state[i-5][j+5]==0))||
                                ((state[i][j]==0)&&(state[i-1][j-1]==1)&&(state[i-2][j-2]==0)&&(state[i-3][j-3]==1)&&(state[i-4][j-4]==1)&&(state[i-5][j-5]==0))||

                                ((state[i][j-2]==1)&&(state[i][j-1]==1)&&(state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==1))||
                                ((state[i-2][j]==1)&&(state[i-1][j]==1)&&(state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==1))||
                                ((state[i+2][j-2]==1)&&(state[i+1][j-1]==1)&&(state[i][j]==0)&&(state[i-1][j+1]==1)&&(state[i-2][j+2]==1))||
                                ((state[i-2][j+2]==1)&&(state[i-1][j+1]==1)&&(state[i][j]==0)&&(state[i+1][j-1]==1)&&(state[i+2][j-2]==1))||                            //红红空红红型

                                ((state[i][j-1]==1)&&(state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==1)&&(state[i][j+3]==1))||
                                ((state[i-1][j]==1)&&(state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==1)&&(state[i+3][j]==1))||
                                ((state[i][j-3]==1)&&(state[i][j-2]==1)&&(state[i][j-1]==1)&&(state[i][j]==0)&&(state[i][j+1]==1))||
                                ((state[i-3][j]==1)&&(state[i-2][j]==1)&&(state[i-1][j]==1)&&(state[i][j]==0)&&(state[i+1][j]==1))||                            //红空红红红型
                                ((state[i-1][j-1]==1)&&(state[i][j]==0)&&(state[i+1][j+1]==1)&&(state[i+2][j+2]==1)&&(state[i+3][j+3]==1))||
                                ((state[i-3][j-3]==1)&&(state[i-2][j-2]==1)&&(state[i-1][j-1]==1)&&(state[i][j]==0)&&(state[i+1][j+1]==1))||
                                ((state[i-1][j+1]==1)&&(state[i][j]==0)&&(state[i+1][j-1]==1)&&(state[i+2][j-2]==1)&&(state[i+3][j-3]==1))||
                                ((state[i+1][j-1]==1)&&(state[i][j]==0)&&(state[i-1][j+1]==1)&&(state[i-2][j+2]==1)&&(state[i-3][j+3]==1))||

                                ((state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==1)&&(state[i][j+3]==1)&&(state[i][j+4]==1)&&(state[i][j+5]==2))||
                                ((state[i][j]==0)&&(state[i][j-1]==1)&&(state[i][j-2]==1)&&(state[i][j-3]==1)&&(state[i][j-4]==1)&&(state[i][j-5]==2))||
                                ((state[i][j]==0)&&(state[i-1][j]==1)&&(state[i-2][j]==1)&&(state[i-3][j]==1)&&(state[i-4][j]==1)&&(state[i-5][j]==2))||                   //空红红红红蓝型
                                ((state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==1)&&(state[i+3][j]==1)&&(state[i+4][j]==1)&&(state[i+5][j]==2))||
                                ((state[i][j]==0)&&(state[i+1][j+1]==1)&&(state[i+2][j+2]==1)&&(state[i+3][j+3]==1)&&(state[i+4][j+4]==1)&&(state[i+5][j+5]==2))||
                                ((state[i][j]==0)&&(state[i-1][j+1]==1)&&(state[i-2][j+2]==1)&&(state[i-3][j+3]==1)&&(state[i-4][j+4]==1)&&(state[i-5][j+5]==2))||
                                ((state[i][j]==0)&&(state[i+1][j-1]==1)&&(state[i+2][j-2]==1)&&(state[i+3][j-3]==1)&&(state[i+4][j-4]==1)&&(state[i+5][j-5]==2))||
                                ((state[i][j]==0)&&(state[i-1][j-1]==1)&&(state[i-2][j-2]==1)&&(state[i-3][j-3]==1)&&(state[i-4][j-4]==1)&&(state[i-5][j-5]==2))||

                                ((state[i][j-1]==1)&&(state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==1)&&(state[i][j+3]==1)&&(state[i][j+4]==2))||
                                ((state[i-1][j]==1)&&(state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==1)&&(state[i+3][j]==1)&&(state[i+4][j]==2))||
                                ((state[i][j-4]==2)&&(state[i][j-3]==1)&&(state[i][j-2]==1)&&(state[i][j-1]==1)&&(state[i][j]==0)&&(state[i][j+1]==1))||
                                ((state[i][j-4]==2)&&(state[i-3][j]==1)&&(state[i-2][j]==1)&&(state[i-1][j]==1)&&(state[i][j]==0)&&(state[i+1][j]==1))||                            //红空红红红蓝
                                ((state[i-1][j-1]==1)&&(state[i][j]==0)&&(state[i+1][j+1]==1)&&(state[i+2][j+2]==1)&&(state[i+3][j+3]==1)&&(state[i+4][j+4]==2))||
                                ((state[i-4][j-4]==2)&&(state[i-3][j-3]==1)&&(state[i-2][j-2]==1)&&(state[i-1][j-1]==1)&&(state[i][j]==0)&&(state[i+1][j+1]==1))||
                                ((state[i-1][j+1]==1)&&(state[i][j]==0)&&(state[i+1][j-1]==1)&&(state[i+2][j-2]==1)&&(state[i+3][j-3]==1)&&(state[i+4][j-4]==2))||
                                ((state[i+1][j-1]==1)&&(state[i][j]==0)&&(state[i-1][j+1]==1)&&(state[i-2][j+2]==1)&&(state[i-3][j+3]==1)&&(state[i-4][j+4]==2))||

                                ((state[i][j-2]==2)&&(state[i][j-1]==1)&&(state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==1)&&(state[i][j+3]==1))||
                                ((state[i-2][j]==2)&&(state[i-1][j]==1)&&(state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==1)&&(state[i+3][j]==1))||
                                ((state[i][j-3]==1)&&(state[i][j-2]==1)&&(state[i][j-1]==1)&&(state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==2))||
                                ((state[i-3][j]==1)&&(state[i-2][j]==1)&&(state[i-1][j]==1)&&(state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==2))||                            //红红红空红蓝型
                                ((state[i-2][j-2]==2)&&(state[i-1][j-1]==1)&&(state[i][j]==0)&&(state[i+1][j+1]==1)&&(state[i+2][j+2]==1)&&(state[i+3][j+3]==1))||
                                ((state[i-3][j-3]==1)&&(state[i-2][j-2]==1)&&(state[i-1][j-1]==1)&&(state[i][j]==0)&&(state[i+1][j+1]==1)&&(state[i+2][j+2]==2))||
                                ((state[i-2][j+2]==2)&&(state[i-1][j+1]==1)&&(state[i][j]==0)&&(state[i+1][j-1]==1)&&(state[i+2][j-2]==1)&&(state[i+3][j-3]==1))||
                                ((state[i+2][j-2]==2)&&(state[i+1][j-1]==1)&&(state[i][j]==0)&&(state[i-1][j+1]==1)&&(state[i-2][j+2]==1)&&(state[i-3][j+3]==1))||

                                ((state[i][j-3]==2)&&(state[i][j-2]==1)&&(state[i][j-1]==1)&&(state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==1))||
                                ((state[i-3][j]==2)&&(state[i-2][j]==1)&&(state[i-1][j]==1)&&(state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==1))||
                                ((state[i+3][j-3]==2)&&(state[i+2][j-2]==1)&&(state[i+1][j-1]==1)&&(state[i][j]==0)&&(state[i-1][j+1]==1)&&(state[i-2][j+2]==1))||
                                ((state[i-3][j+3]==2)&&(state[i-2][j+2]==1)&&(state[i-1][j+1]==1)&&(state[i][j]==0)&&(state[i+1][j-1]==1)&&(state[i+2][j-2]==1))||
                                ((state[i][j-2]==1)&&(state[i][j-1]==1)&&(state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==1)&&(state[i][j+3]==2))||                            //红红空红红蓝型
                                ((state[i-2][j]==1)&&(state[i-1][j]==1)&&(state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==1)&&(state[i+3][j]==2))||
                                ((state[i-3][j-3]==2)&&(state[i-2][j-2]==1)&&(state[i-1][j-1]==1)&&(state[i][j]==0)&&(state[i+1][j+1]==1)&&(state[i+2][j+2]==1))||
                                ((state[i+3][j+3]==2)&&(state[i+2][j+2]==1)&&(state[i+1][j+1]==1)&&(state[i][j]==0)&&(state[i-1][j-1]==1)&&(state[i-2][j-2]==1))||

                                ((state[i][j-1]==2)&&(state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==1)&&(state[i][j+3]==1)&&(state[i][j+4]==1))||
                                   ((state[i-1][j]==2)&&(state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==1)&&(state[i+3][j]==1)&&(state[i+4][j]==1))||
                                   ((state[i-1][j-1]==2)&&(state[i][j]==0)&&(state[i+1][j+1]==1)&&(state[i+2][j+2]==1)&&(state[i+3][j+3]==1)&&(state[i+4][j+4]==1))||
                                   ((state[i+1][j+1]==2)&&(state[i][j]==0)&&(state[i-1][j-1]==1)&&(state[i-2][j-2]==1)&&(state[i-3][j-3]==1)&&(state[i-4][j-4]==1))||
                                   ((state[i][j+1]==2)&&(state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==1)&&(state[i][j+3]==1)&&(state[i][j+4]==1))||           //红红红红空蓝型
                                   ((state[i+1][j]==2)&&(state[i][j]==0)&&(state[i-1][j]==1)&&(state[i-2][j]==1)&&(state[i-3][j]==1)&&(state[i-4][j]==1))||
                                   ((state[i-1][j+1]==2)&&(state[i][j]==0)&&(state[i+1][j-1]==1)&&(state[i+2][j-2]==1)&&(state[i+3][j-3]==1)&&(state[i+4][j-4]==1))||
                                   ((state[i+1][j-1]==2)&&(state[i][j]==0)&&(state[i-1][j+1]==1)&&(state[i-2][j+2]==1)&&(state[i-3][j+3]==1)&&(state[i-4][j+4]==1))){
                                   value[i][j]=6;
                                   return value[i][j];
                 }
                else if(((state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==2)&&(state[i][j+3]==2)&&(state[i][j+4]==0))||
                                ((state[i][j]==0)&&(state[i][j-1]==2)&&(state[i][j-2]==2)&&(state[i][j-3]==2)&&(state[i][j-4]==0))||
                                ((state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==2)&&(state[i+3][j]==2)&&(state[i+4][j]==0))||
                                ((state[i][j]==0)&&(state[i-1][j]==2)&&(state[i-2][j]==2)&&(state[i-3][j]==2)&&(state[i-4][j]==0))||
                                ((state[i][j]==0)&&(state[i+1][j+1]==2)&&(state[i+2][j+2]==2)&&(state[i+3][j+3]==2)&&(state[i+4][j+4]==0))||
                                ((state[i][j]==0)&&(state[i+1][j-1]==2)&&(state[i+2][j-2]==2)&&(state[i+3][j-3]==2)&&(state[i+4][j-4]==0))||
                                ((state[i][j]==0)&&(state[i-1][j+1]==2)&&(state[i-2][j+2]==2)&&(state[i-3][j+3]==2)&&(state[i-4][j+4]==0))||
                                ((state[i][j]==0)&&(state[i-1][j-1]==2)&&(state[i-2][j-2]==2)&&(state[i-3][j-3]==2)&&(state[i-4][j-4]==0))||

                                ((state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==0)&&(state[i][j+3]==2)&&(state[i][j+4]==2)&&(state[i][j+5]==0))||
                                ((state[i][j]==0)&&(state[i][j-1]==2)&&(state[i][j-2]==0)&&(state[i][j-3]==2)&&(state[i][j-4]==2)&&(state[i][j-5]==0))||
                                ((state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==0)&&(state[i+3][j]==2)&&(state[i+4][j]==2)&&(state[i+5][j]==0))||
                                ((state[i][j]==0)&&(state[i-1][j]==2)&&(state[i-2][j]==0)&&(state[i-3][j]==2)&&(state[i-4][j]==2)&&(state[i-5][j]==0))||
                                ((state[i][j]==0)&&(state[i+1][j+1]==2)&&(state[i+2][j+2]==0)&&(state[i+3][j+3]==2)&&(state[i+4][j+4]==2)&&(state[i+5][j+5]==0))||
                                ((state[i][j]==0)&&(state[i+1][j-1]==2)&&(state[i+2][j-2]==0)&&(state[i+3][j-3]==2)&&(state[i+4][j-4]==2)&&(state[i+5][j-5]==0))||
                                ((state[i][j]==0)&&(state[i-1][j+1]==2)&&(state[i-2][j+2]==0)&&(state[i-3][j+3]==2)&&(state[i-4][j+4]==2)&&(state[i-5][j+5]==0))||
                                ((state[i][j]==0)&&(state[i-1][j-1]==2)&&(state[i-2][j-2]==0)&&(state[i-3][j-3]==2)&&(state[i-4][j-4]==2)&&(state[i-5][j-5]==0))||

                                ((state[i][j-2]==2)&&(state[i][j-1]==2)&&(state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==2))||
                                ((state[i-2][j]==2)&&(state[i-1][j]==2)&&(state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==2))||
                                ((state[i+2][j-2]==2)&&(state[i+1][j-1]==2)&&(state[i][j]==0)&&(state[i-1][j+1]==2)&&(state[i-2][j+2]==2))||
                                ((state[i-2][j+2]==2)&&(state[i-1][j+1]==2)&&(state[i][j]==0)&&(state[i+1][j-1]==2)&&(state[i+2][j-2]==2))||

                                ((state[i][j-1]==2)&&(state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==2)&&(state[i][j+3]==2))||
                                ((state[i-1][j]==2)&&(state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==2)&&(state[i+3][j]==2))||
                                ((state[i][j-3]==2)&&(state[i][j-2]==2)&&(state[i][j-1]==2)&&(state[i][j]==0)&&(state[i][j+1]==2))||
                                ((state[i-3][j]==2)&&(state[i-2][j]==2)&&(state[i-1][j]==2)&&(state[i][j]==0)&&(state[i+1][j]==2))||
                                ((state[i-1][j-1]==2)&&(state[i][j]==0)&&(state[i+1][j+1]==2)&&(state[i+2][j+2]==2)&&(state[i+3][j+3]==2))||
                                ((state[i-3][j-3]==2)&&(state[i-2][j-2]==2)&&(state[i-1][j-1]==2)&&(state[i][j]==0)&&(state[i+1][j+1]==2))||
                                ((state[i-1][j+1]==2)&&(state[i][j]==0)&&(state[i+1][j-1]==2)&&(state[i+2][j-2]==2)&&(state[i+3][j-3]==2))||
                                ((state[i+1][j-1]==2)&&(state[i][j]==0)&&(state[i-1][j+1]==2)&&(state[i-2][j+2]==2)&&(state[i-3][j+3]==2))||

                                ((state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==2)&&(state[i][j+3]==2)&&(state[i][j+4]==2)&&(state[i][j+5]==1))||
                                ((state[i][j]==0)&&(state[i][j-1]==2)&&(state[i][j-2]==2)&&(state[i][j-3]==2)&&(state[i][j-4]==2)&&(state[i][j-5]==1))||
                                ((state[i][j]==0)&&(state[i-1][j]==2)&&(state[i-2][j]==2)&&(state[i-3][j]==2)&&(state[i-4][j]==2)&&(state[i-5][j]==1))||
                                ((state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==2)&&(state[i+3][j]==2)&&(state[i+4][j]==2)&&(state[i+5][j]==1))||
                                ((state[i][j]==0)&&(state[i+1][j+1]==2)&&(state[i+2][j+2]==2)&&(state[i+3][j+3]==2)&&(state[i+4][j+4]==2)&&(state[i+5][j+5]==1))||
                                ((state[i][j]==0)&&(state[i-1][j+1]==2)&&(state[i-2][j+2]==2)&&(state[i-3][j+3]==2)&&(state[i-4][j+4]==2)&&(state[i-5][j+5]==1))||
                                ((state[i][j]==0)&&(state[i+1][j-1]==2)&&(state[i+2][j-2]==2)&&(state[i+3][j-3]==2)&&(state[i+4][j-4]==2)&&(state[i+5][j-5]==1))||
                                ((state[i][j]==0)&&(state[i-1][j-1]==2)&&(state[i-2][j-2]==2)&&(state[i-3][j-3]==2)&&(state[i-4][j-4]==2)&&(state[i-5][j-5]==1))||

                                ((state[i][j-1]==2)&&(state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==2)&&(state[i][j+3]==2)&&(state[i][j+4]==1))||
                                ((state[i-1][j]==2)&&(state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==2)&&(state[i+3][j]==2)&&(state[i+4][j]==1))||
                                ((state[i][j-4]==1)&&(state[i][j-3]==2)&&(state[i][j-2]==2)&&(state[i][j-1]==2)&&(state[i][j]==0)&&(state[i][j+1]==2))||
                                ((state[i][j-4]==1)&&(state[i-3][j]==2)&&(state[i-2][j]==2)&&(state[i-1][j]==2)&&(state[i][j]==0)&&(state[i+1][j]==2))||
                                ((state[i-1][j-1]==2)&&(state[i][j]==0)&&(state[i+1][j+1]==2)&&(state[i+2][j+2]==2)&&(state[i+3][j+3]==2)&&(state[i+4][j+4]==1))||
                                ((state[i-4][j-4]==1)&&(state[i-3][j-3]==2)&&(state[i-2][j-2]==2)&&(state[i-1][j-1]==2)&&(state[i][j]==0)&&(state[i+1][j+1]==2))||
                                ((state[i-1][j+1]==2)&&(state[i][j]==0)&&(state[i+1][j-1]==2)&&(state[i+2][j-2]==2)&&(state[i+3][j-3]==2)&&(state[i+4][j-4]==1))||
                                ((state[i+1][j-1]==2)&&(state[i][j]==0)&&(state[i-1][j+1]==2)&&(state[i-2][j+2]==2)&&(state[i-3][j+3]==2)&&(state[i-4][j+4]==1))||

                                ((state[i][j-2]==1)&&(state[i][j-1]==2)&&(state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==2)&&(state[i][j+3]==2))||
                                ((state[i-2][j]==1)&&(state[i-1][j]==2)&&(state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==2)&&(state[i+3][j]==2))||
                                ((state[i][j-3]==2)&&(state[i][j-2]==2)&&(state[i][j-1]==2)&&(state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==1))||
                                ((state[i-3][j]==2)&&(state[i-2][j]==2)&&(state[i-1][j]==2)&&(state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==1))||
                                ((state[i-2][j-2]==1)&&(state[i-1][j-1]==2)&&(state[i][j]==0)&&(state[i+1][j+1]==2)&&(state[i+2][j+2]==2)&&(state[i+3][j+3]==2))||
                                ((state[i-3][j-3]==2)&&(state[i-2][j-2]==2)&&(state[i-1][j-1]==2)&&(state[i][j]==0)&&(state[i+1][j+1]==2)&&(state[i+2][j+2]==1))||
                                ((state[i-2][j+2]==1)&&(state[i-1][j+1]==2)&&(state[i][j]==0)&&(state[i+1][j-1]==2)&&(state[i+2][j-2]==2)&&(state[i+3][j-3]==2))||
                                ((state[i+2][j-2]==1)&&(state[i+1][j-1]==2)&&(state[i][j]==0)&&(state[i-1][j+1]==2)&&(state[i-2][j+2]==2)&&(state[i-3][j+3]==2))||

                                ((state[i][j-3]==1)&&(state[i][j-2]==2)&&(state[i][j-1]==2)&&(state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==2))||
                                ((state[i-3][j]==1)&&(state[i-2][j]==2)&&(state[i-1][j]==2)&&(state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==2))||
                                ((state[i+3][j-3]==1)&&(state[i+2][j-2]==2)&&(state[i+1][j-1]==2)&&(state[i][j]==0)&&(state[i-1][j+1]==2)&&(state[i-2][j+2]==2))||
                                ((state[i-3][j+3]==1)&&(state[i-2][j+2]==2)&&(state[i-1][j+1]==2)&&(state[i][j]==0)&&(state[i+1][j-1]==2)&&(state[i+2][j-2]==2))||
                                ((state[i][j-2]==2)&&(state[i][j-1]==2)&&(state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==2)&&(state[i][j+3]==1))||
                                ((state[i-2][j]==2)&&(state[i-1][j]==2)&&(state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==2)&&(state[i+3][j]==1))||
                                ((state[i-3][j-3]==1)&&(state[i-2][j-2]==2)&&(state[i-1][j-1]==2)&&(state[i][j]==0)&&(state[i+1][j+1]==2)&&(state[i+2][j+2]==2))||
                                ((state[i+3][j+3]==1)&&(state[i+2][j+2]==2)&&(state[i+1][j+1]==2)&&(state[i][j]==0)&&(state[i-1][j-1]==2)&&(state[i-2][j-2]==2))||

                                ((state[i][j-1]==1)&&(state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==2)&&(state[i][j+3]==2)&&(state[i][j+4]==2))||
                                   ((state[i-1][j]==1)&&(state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==2)&&(state[i+3][j]==2)&&(state[i+4][j]==2))||
                                   ((state[i-1][j-1]==1)&&(state[i][j]==0)&&(state[i+1][j+1]==2)&&(state[i+2][j+2]==2)&&(state[i+3][j+3]==2)&&(state[i+4][j+4]==2))||
                                   ((state[i+1][j+1]==1)&&(state[i][j]==0)&&(state[i-1][j-1]==2)&&(state[i-2][j-2]==2)&&(state[i-3][j-3]==2)&&(state[i-4][j-4]==2))||
                                   ((state[i][j+1]==1)&&(state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==2)&&(state[i][j+3]==2)&&(state[i][j+4]==2))||
                                   ((state[i+1][j]==1)&&(state[i][j]==0)&&(state[i-1][j]==2)&&(state[i-2][j]==2)&&(state[i-3][j]==2)&&(state[i-4][j]==2))||
                                   ((state[i-1][j+1]==1)&&(state[i][j]==0)&&(state[i+1][j-1]==2)&&(state[i+2][j-2]==2)&&(state[i+3][j-3]==2)&&(state[i+4][j-4]==2))||
                                   ((state[i+1][j-1]==1)&&(state[i][j]==0)&&(state[i-1][j+1]==2)&&(state[i-2][j+2]==2)&&(state[i-3][j+3]==2)&&(state[i-4][j+4]==2))){
                                   value[i][j]=5;
                                   return value[i][j];
                 }
                 else if(((state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==1)&&(state[i][j+3]==0))||
                                 ((state[i][j]==0)&&(state[i][j-1]==1)&&(state[i][j-2]==1)&&(state[i][j-3]==0))||
                                 ((state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==1)&&(state[i+3][j]==0))||
                                 ((state[i][j]==0)&&(state[i-1][j]==1)&&(state[i-2][j]==1)&&(state[i-3][j]==0))||                            //空红红空型
                                 ((state[i][j]==0)&&(state[i+1][j+1]==1)&&(state[i+2][j+2]==1)&&(state[i+3][j+3]==0))||
                                 ((state[i][j]==0)&&(state[i+1][j-1]==1)&&(state[i+2][j-2]==1)&&(state[i+3][j-3]==0))||
                                 ((state[i][j]==0)&&(state[i-1][j+1]==1)&&(state[i-2][j+2]==1)&&(state[i-3][j+3]==0))||
                                 ((state[i][j]==0)&&(state[i-1][j-1]==1)&&(state[i-2][j-2]==1)&&(state[i-3][j-3]==0))||

                                 ((state[i-2][j]==0)&&(state[i-1][j]==1)&&(state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==0))||
                                 ((state[i][j-2]==0)&&(state[i][j-1]==1)&&(state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==0))||                          //空红空红空型
                                 ((state[i-2][j+2]==0)&&(state[i-1][j+1]==1)&&(state[i][j]==0)&&(state[i+1][j-1]==1)&&(state[i+2][j-2]==0))||
                                 ((state[i-2][j-2]==0)&&(state[i-1][j-1]==1)&&(state[i][j]==0)&&(state[i+1][j+1]==1)&&(state[i+2][j+2]==0))||

                                 ((state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==1)&&(state[i][j+3]==1)&&(state[i][j+4]==2))||
                                 ((state[i][j]==0)&&(state[i][j-1]==1)&&(state[i][j-2]==1)&&(state[i][j-3]==1)&&(state[i][j-4]==2))||
                                 ((state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==1)&&(state[i+3][j]==1)&&(state[i+4][j]==2))||
                                 ((state[i][j]==0)&&(state[i-1][j]==1)&&(state[i-2][j]==1)&&(state[i-3][j]==1)&&(state[i-4][j]==2))||                            //空红红红蓝型
                                 ((state[i][j]==0)&&(state[i+1][j+1]==1)&&(state[i+2][j+2]==1)&&(state[i+3][j+3]==1)&&(state[i+4][j+4]==2))||
                                 ((state[i][j]==0)&&(state[i+1][j-1]==1)&&(state[i+2][j-2]==1)&&(state[i+3][j-3]==1)&&(state[i+4][j-4]==2))||
                                 ((state[i][j]==0)&&(state[i-1][j+1]==1)&&(state[i-2][j+2]==1)&&(state[i-3][j+3]==1)&&(state[i-4][j+4]==2))||
                                 ((state[i][j]==0)&&(state[i-1][j-1]==1)&&(state[i-2][j-2]==1)&&(state[i-3][j-3]==1)&&(state[i-4][j-4]==2))||

                                 ((state[i][j-1]==1)&&(state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==1)&&(state[i][j+3]==2))||
                                 ((state[i-1][j]==1)&&(state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==1)&&(state[i+3][j]==2))||
                                 ((state[i][j-3]==2)&&(state[i][j-2]==1)&&(state[i][j-1]==1)&&(state[i][j]==0)&&(state[i][j+1]==1))||
                                 ((state[i-3][j]==2)&&(state[i-2][j]==1)&&(state[i-1][j]==1)&&(state[i][j]==0)&&(state[i+1][j]==1))||                            //红空红红蓝型
                                 ((state[i-1][j-1]==1)&&(state[i][j]==0)&&(state[i+1][j+1]==1)&&(state[i+2][j+2]==1)&&(state[i+3][j+3]==2))||
                                 ((state[i-3][j-3]==2)&&(state[i-2][j-2]==1)&&(state[i-1][j-1]==1)&&(state[i][j]==0)&&(state[i+1][j+1]==1))||
                                 ((state[i-1][j+1]==1)&&(state[i][j]==0)&&(state[i+1][j-1]==1)&&(state[i+2][j-2]==1)&&(state[i+3][j-3]==2))||
                                 ((state[i+1][j-1]==1)&&(state[i][j]==0)&&(state[i-1][j+1]==1)&&(state[i-2][j+2]==1)&&(state[i-3][j+3]==2))||

                                 ((state[i][j-2]==1)&&(state[i][j-1]==1)&&(state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==2))||
                                 ((state[i-2][j]==1)&&(state[i-1][j]==1)&&(state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==2))||
                                 ((state[i+2][j-2]==1)&&(state[i+1][j-1]==1)&&(state[i][j]==0)&&(state[i-1][j+1]==1)&&(state[i-2][j+2]==2))||
                                 ((state[i-2][j+2]==1)&&(state[i-1][j+1]==1)&&(state[i][j]==0)&&(state[i+1][j-1]==1)&&(state[i+2][j-2]==2))||                            //红红空红蓝型
                                 ((state[i][j+2]==1)&&(state[i][j+1]==1)&&(state[i][j]==0)&&(state[i][j-1]==1)&&(state[i][j-2]==2))||
                                 ((state[i+2][j]==1)&&(state[i+1][j]==1)&&(state[i][j]==0)&&(state[i-1][j]==1)&&(state[i-2][j]==2))||
                                 ((state[i-2][j+2]==1)&&(state[i-1][j+1]==1)&&(state[i][j]==0)&&(state[i+1][j-1]==1)&&(state[i+2][j-2]==2))||
                                 ((state[i+2][j-2]==1)&&(state[i+1][j-1]==1)&&(state[i][j]==0)&&(state[i-1][j+1]==1)&&(state[i-2][j+2]==2))){
                                 value[i][j]=4;
                                 return value[i][j];
                }
                else if(((state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==2)&&(state[i][j+3]==0))||
                                 ((state[i][j]==0)&&(state[i][j-1]==2)&&(state[i][j-2]==2)&&(state[i][j-3]==0))||
                                 ((state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==2)&&(state[i+3][j]==0))||
                                 ((state[i][j]==0)&&(state[i-1][j]==2)&&(state[i-2][j]==2)&&(state[i-3][j]==0))||
                                 ((state[i][j]==0)&&(state[i+1][j+1]==2)&&(state[i+2][j+2]==2)&&(state[i+3][j+3]==0))||
                                 ((state[i][j]==0)&&(state[i+1][j-1]==2)&&(state[i+2][j-2]==2)&&(state[i+3][j-3]==0))||
                                 ((state[i][j]==0)&&(state[i-1][j+1]==2)&&(state[i-2][j+2]==2)&&(state[i-3][j+3]==0))||
                                 ((state[i][j]==0)&&(state[i-1][j-1]==2)&&(state[i-2][j-2]==2)&&(state[i-3][j-3]==0))||

                                 ((state[i-2][j]==0)&&(state[i-1][j]==2)&&(state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==0))||
                                 ((state[i][j-2]==0)&&(state[i][j-1]==2)&&(state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==0))||
                                 ((state[i-2][j+2]==0)&&(state[i-1][j+1]==2)&&(state[i][j]==0)&&(state[i+1][j-1]==2)&&(state[i+2][j-2]==0))||
                                 ((state[i-2][j-2]==0)&&(state[i-1][j-1]==2)&&(state[i][j]==0)&&(state[i+1][j+1]==2)&&(state[i+2][j+2]==0))||

                                 ((state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==2)&&(state[i][j+3]==2)&&(state[i][j+4]==1))||
                                 ((state[i][j]==0)&&(state[i][j-1]==2)&&(state[i][j-2]==2)&&(state[i][j-3]==2)&&(state[i][j-4]==1))||
                                 ((state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==2)&&(state[i+3][j]==2)&&(state[i+4][j]==1))||
                                 ((state[i][j]==0)&&(state[i-1][j]==2)&&(state[i-2][j]==2)&&(state[i-3][j]==2)&&(state[i-4][j]==1))||
                                 ((state[i][j]==0)&&(state[i+1][j+1]==2)&&(state[i+2][j+2]==2)&&(state[i+3][j+3]==2)&&(state[i+4][j+4]==1))||
                                 ((state[i][j]==0)&&(state[i+1][j-1]==2)&&(state[i+2][j-2]==2)&&(state[i+3][j-3]==2)&&(state[i+4][j-4]==1))||
                                 ((state[i][j]==0)&&(state[i-1][j+1]==2)&&(state[i-2][j+2]==2)&&(state[i-3][j+3]==2)&&(state[i-4][j+4]==1))||
                                 ((state[i][j]==0)&&(state[i-1][j-1]==2)&&(state[i-2][j-2]==2)&&(state[i-3][j-3]==2)&&(state[i-4][j-4]==1))||

                                 ((state[i][j-1]==2)&&(state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==2)&&(state[i][j+3]==1))||
                                 ((state[i-1][j]==2)&&(state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==2)&&(state[i+3][j]==1))||
                                 ((state[i][j-3]==1)&&(state[i][j-2]==2)&&(state[i][j-1]==2)&&(state[i][j]==0)&&(state[i][j+1]==2))||
                                 ((state[i-3][j]==1)&&(state[i-2][j]==2)&&(state[i-1][j]==2)&&(state[i][j]==0)&&(state[i+1][j]==2))||
                                 ((state[i-1][j-1]==2)&&(state[i][j]==0)&&(state[i+1][j+1]==2)&&(state[i+2][j+2]==2)&&(state[i+3][j+3]==1))||
                                 ((state[i-3][j-3]==1)&&(state[i-2][j-2]==2)&&(state[i-1][j-1]==2)&&(state[i][j]==0)&&(state[i+1][j+1]==2))||
                                 ((state[i-1][j+1]==2)&&(state[i][j]==0)&&(state[i+1][j-1]==2)&&(state[i+2][j-2]==2)&&(state[i+3][j-3]==1))||
                                 ((state[i+1][j-1]==2)&&(state[i][j]==0)&&(state[i-1][j+1]==2)&&(state[i-2][j+2]==2)&&(state[i-3][j+3]==1))||

                                 ((state[i][j-2]==2)&&(state[i][j-1]==2)&&(state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==1))||
                                 ((state[i-2][j]==2)&&(state[i-1][j]==2)&&(state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==1))||
                                 ((state[i+2][j-2]==2)&&(state[i+1][j-1]==2)&&(state[i][j]==0)&&(state[i-1][j+1]==2)&&(state[i-2][j+2]==1))||
                                 ((state[i-2][j+2]==2)&&(state[i-1][j+1]==2)&&(state[i][j]==0)&&(state[i+1][j-1]==2)&&(state[i+2][j-2]==1))||
                                 ((state[i][j+2]==2)&&(state[i][j+1]==2)&&(state[i][j]==0)&&(state[i][j-1]==2)&&(state[i][j-2]==1))||
                                 ((state[i+2][j]==2)&&(state[i+1][j]==2)&&(state[i][j]==0)&&(state[i-1][j]==2)&&(state[i-2][j]==1))||
                                 ((state[i-2][j+2]==2)&&(state[i-1][j+1]==2)&&(state[i][j]==0)&&(state[i+1][j-1]==2)&&(state[i+2][j-2]==1))||
                                 ((state[i+2][j-2]==2)&&(state[i+1][j-1]==2)&&(state[i][j]==0)&&(state[i-1][j+1]==2)&&(state[i-2][j+2]==1))){
                                 value[i][j]=3;
                                 return value[i][j];
                }
                else if(((state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==0))||
                                ((state[i][j]==0)&&(state[i][j-1]==1)&&(state[i][j-2]==0))||
                                ((state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==0))||
                                ((state[i][j]==0)&&(state[i-1][j]==1)&&(state[i-2][j]==0))||                               //空红空
                                ((state[i][j]==0)&&(state[i+1][j+1]==1)&&(state[i+2][j+2]==0))||
                                ((state[i][j]==0)&&(state[i+1][j-1]==1)&&(state[i+2][j-2]==0))||
                                ((state[i][j]==0)&&(state[i-1][j+1]==1)&&(state[i-2][j+2]==0))||
                                ((state[i][j]==0)&&(state[i-1][j-1]==1)&&(state[i-2][j-2]==0))||

                        ((state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==1)&&(state[i][j+3]==2))||
                                ((state[i][j]==0)&&(state[i][j-1]==1)&&(state[i][j-2]==1)&&(state[i][j-3]==2))||
                                ((state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==1)&&(state[i+3][j]==2))||
                                ((state[i][j]==0)&&(state[i-1][j]==1)&&(state[i-2][j]==1)&&(state[i-3][j]==2))||                            //空红红蓝型
                                ((state[i][j]==0)&&(state[i+1][j+1]==1)&&(state[i+2][j+2]==1)&&(state[i+3][j+3]==2))||
                                ((state[i][j]==0)&&(state[i+1][j-1]==1)&&(state[i+2][j-2]==1)&&(state[i+3][j-3]==2))||
                                ((state[i][j]==0)&&(state[i-1][j+1]==1)&&(state[i-2][j+2]==1)&&(state[i-3][j+3]==2))||
                                ((state[i][j]==0)&&(state[i-1][j-1]==1)&&(state[i-2][j-2]==1)&&(state[i-3][j-3]==2))){
                                value[i][j]=2;
                                return value[i][j];
                }
                else if(((state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==0))||
                                ((state[i][j]==0)&&(state[i][j-1]==2)&&(state[i][j-2]==0))||
                                ((state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==0))||
                                ((state[i][j]==0)&&(state[i-1][j]==2)&&(state[i-2][j]==0))||
                                ((state[i][j]==0)&&(state[i+1][j+1]==2)&&(state[i+2][j+2]==0))||
                                ((state[i][j]==0)&&(state[i+1][j-1]==2)&&(state[i+2][j-2]==0))||
                                ((state[i][j]==0)&&(state[i-1][j+1]==2)&&(state[i-2][j+2]==0))||
                                ((state[i][j]==0)&&(state[i-1][j-1]==2)&&(state[i-2][j-2]==0))||

                        ((state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==2)&&(state[i][j+3]==1))||
                                ((state[i][j]==0)&&(state[i][j-1]==2)&&(state[i][j-2]==2)&&(state[i][j-3]==1))||
                                ((state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==2)&&(state[i+3][j]==1))||
                                ((state[i][j]==0)&&(state[i-1][j]==2)&&(state[i-2][j]==2)&&(state[i-3][j]==1))||
                                ((state[i][j]==0)&&(state[i+1][j+1]==2)&&(state[i+2][j+2]==2)&&(state[i+3][j+3]==1))||
                                ((state[i][j]==0)&&(state[i+1][j-1]==2)&&(state[i+2][j-2]==2)&&(state[i+3][j-3]==1))||
                                ((state[i][j]==0)&&(state[i-1][j+1]==2)&&(state[i-2][j+2]==2)&&(state[i-3][j+3]==1))||
                                ((state[i][j]==0)&&(state[i-1][j-1]==2)&&(state[i-2][j-2]==2)&&(state[i-3][j-3]==1))){
                                value[i][j]=1;
                                return value[i][j];
                }
                else{
                        value[i][j]=0;
                        return value[i][j];
                }


    }
    public int[] largestValue(int[][] value){
            int max,i,j,l,k;
            l=0;k=0;
            max=0;
            for(i=5;i<34;i++){
                    for(j=5;j<34;j++){
                            if(max<value[i][j]){
                                    max=value[i][j];
                                    place[0]=i;
                                    place[1]=j;
                            }
                    }
            }
            return place;
    }

}

 

运行结果如下图所示:

java基于swing实现的五子棋游戏代码

java基于swing实现的五子棋游戏代码

希望本文所述对大家的Java程序设计有所帮助。

标签:

相关文章

热门资讯

玄元剑仙肉身有什么用 玄元剑仙肉身境界等级划分
玄元剑仙肉身有什么用 玄元剑仙肉身境界等级划分 2019-06-21
男生常说24816是什么意思?女生说13579是什么意思?
男生常说24816是什么意思?女生说13579是什么意思? 2019-09-17
配置IIS网站web服务器的安全策略配置解决方案
配置IIS网站web服务器的安全策略配置解决方案 2019-05-23
Nginx服务器究竟是怎么执行PHP项目
Nginx服务器究竟是怎么执行PHP项目 2019-05-24
华为nova5pro和p30pro哪个好 华为nova5pro和华为p30pro对比详情
华为nova5pro和p30pro哪个好 华为nova5pro和华为p30pro对比详情 2019-06-22
返回顶部