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

本文实例讲述了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程序设计有所帮助。

时间: 2024-10-28 04:40:54

java基于swing实现的五子棋游戏代码_java的相关文章

Java基于swing实现的弹球游戏代码_java

本文实例讲述了Java基于swing实现的弹球游戏代码.分享给大家供大家参考. 主要功能代码如下: 复制代码 代码如下: package Game; import java.awt.Graphics; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.Random;

java实现的简单猜数字游戏代码_java

本文实例讲述了java实现的简单猜数字游戏代码.分享给大家供大家参考. 具体代码如下: 复制代码 代码如下: import java.util.InputMismatchException; import java.util.Scanner; public class Main {         public static void main(String[] args) {                 // 产生一个随机数                 int number = (in

Java基于Swing实现的打猎射击游戏代码_java

本文实例讲述了Java基于Swing实现的打猎射击游戏代码.分享给大家供大家参考. 具体实现代码如下: 复制代码 代码如下: package Game; import java.awt.Graphics; import java.awt.Image; import javax.swing.JPanel; public class BackgroundPanel extends JPanel {         private static final long serialVersionUID

java基于swing实现的连连看代码_java

本文实例讲述了java基于swing实现连连看代码.分享给大家供大家参考. 主要功能代码如下: 复制代码 代码如下: package llkan; import javax.swing.*; import java.awt.*; import java.awt.event.*; /**  * 连连看游戏  * @author Administrator  *2014年10月17日  */ public class MainGame implements ActionListener {     

基于C语言实现五子棋游戏完整实例代码_C 语言

本文实例讲述了基于C语言实现五子棋游戏的方法,代码备有比较完整的注释,可以帮助读者更好的加以理解. 五子棋游戏代码如下: /* * 使用键盘的上下左右键移动棋盘,空格键表示下棋,ESC键退出程序 */ #include <stdio.h> #include <stdlib.h> #include <bios.h> #include <graphics.h> #include<malloc.h> /* * 对应键盘键的十六进制数字 */ #defi

游戏开发-用vb.net编写五子棋游戏代码详解

问题描述 用vb.net编写五子棋游戏代码详解 vb.net初学者,求五子棋游戏编写步骤详解代码解释还有ai算法的构建 解决方案 http://download.csdn.net/detail/winter_ling/2469095http://download.csdn.net/detail/jinsenianhua2012/4286183http://download.csdn.net/detail/qwciyuan/3362601 解决方案二: 五子棋的核心算法 五子棋是一种受大众广泛喜爱

java编写的简单移动方块小游戏代码_java

本文实例讲述了java编写的简单移动方块小游戏代码.分享给大家供大家参考,具体如下: 运行效果截图如下: 第一次用java编写图形化的界面,还是有些青涩..以后继续努力!!具体代码如下: //Little Box Game by AlexYui //Game.java By 1093710210@ HIT import javax.swing.*; import java.awt.event.*; import java.awt.geom.*; import java.awt.*; import

基于AJAX的在线五子棋游戏

这是我们本学期一门课程--软件工程实践(全程模拟软件开发的过程,关需求分析就做了一个月,后面还有概要设计.详细设计.编码测试.验收等)--的作业,旨在开发一款校园内部使用的基于B/S模式的在线棋牌类游戏对弈平台.目标是能开发出一套框架,其他同学能在这个框架的基础上轻松地开发出自己的游戏. 现在已经开始编码几天,实现得还很粗糙,做了一个简单的"五子棋游戏"来做示范. 系统前台是纯HTML+JavaScript,后台用J2EE.我现在没有服务器,无法将其发布到网络上,等到课程结束,我会将系

java基于Socket做一个简单下载器_java

本文实例为大家分享了java基于Socket制作下载器的过程,及相关代码,供大家参考,具体内容如下 1.首先要建立一个服务器用来处理信息并给客户端传输文件(电脑)  我是用电脑开了一个WIFI,手机连上后使用scoket传输的  SERVERIP要根据自己实际情况更改.端口也可以随便更改0~65535,尽量选大一点  import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.Bu