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

📄 five.java

📁 五子棋的源码。自己刚写的。算法还不错。不过意铺待改进。
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                if(j + 3 <= boarder && j - 1 >= 0)
                {
                    line = (new StringBuilder()).append(flag[i][j - 1]).append("X").append(flag[i][j + 1]).append(flag[i][j + 2]).append(flag[i][j + 3]).toString();
                    isEqual(i, j, line);
                }
                if(j - 2 >= 0 && j + 2 <= boarder)
                {
                    line = (new StringBuilder()).append(flag[i][j - 2]).append(flag[i][j - 1]).append("X").append(flag[i][j + 1]).append(flag[i][j + 2]).toString();
                    isEqual(i, j, line);
                }
                if(i + 3 <= boarder && i - 1 >= 0)
                {
                    line = (new StringBuilder()).append(flag[i - 1][j]).append("X").append(flag[i + 1][j]).append(flag[i + 2][j]).append(flag[i + 3][j]).toString();
                    isEqual(i, j, line);
                }
                if(i - 2 >= 0 && i + 2 <= boarder)
                {
                    line = (new StringBuilder()).append(flag[i - 2][j]).append(flag[i - 1][j]).append("X").append(flag[i + 1][j]).append(flag[i + 2][j]).toString();
                    isEqual(i, j, line);
                }
                if(i - 3 >= 0 && i + 1 <= boarder)
                {
                    line = (new StringBuilder()).append(flag[i + 1][j]).append("X").append(flag[i - 1][j]).append(flag[i - 2][j]).append(flag[i - 3][j]).toString();
                    isEqual(i, j, line);
                }
                if(i + 2 <= boarder && i - 2 >= 0)
                {
                    line = (new StringBuilder()).append(flag[i + 2][j]).append(flag[i + 1][j]).append("X").append(flag[i - 1][j]).append(flag[i - 2][j]).toString();
                    isEqual(i, j, line);
                }
                if(j - 3 >= 0 && j + 1 <= boarder)
                {
                    line = (new StringBuilder()).append(flag[i][j + 1]).append("X").append(flag[i][j - 1]).append(flag[i][j - 2]).append(flag[i][j - 3]).toString();
                    isEqual(i, j, line);
                }
                if(j + 2 <= boarder && j - 2 >= 0)
                {
                    line = (new StringBuilder()).append(flag[i][j + 2]).append(flag[i][j + 1]).append("X").append(flag[i][j - 1]).append(flag[i][j - 2]).toString();
                    isEqual(i, j, line);
                }
                if(i - 3 >= 0 && j + 3 <= boarder && i + 1 <= boarder && j - 1 >= 0)
                {
                    line = (new StringBuilder()).append(flag[i + 1][j - 1]).append("X").append(flag[i - 1][j + 1]).append(flag[i - 2][j + 2]).append(flag[i - 3][j + 3]).toString();
                    isEqual(i, j, line);
                }
                if(i + 2 <= boarder && j - 2 >= 0 && i - 2 >= 0 && j + 2 <= boarder)
                {
                    line = (new StringBuilder()).append(flag[i + 2][j - 2]).append(flag[i + 1][j - 1]).append("X").append(flag[i - 1][j + 1]).append(flag[i - 2][j + 2]).toString();
                    isEqual(i, j, line);
                }
                if(i - 3 >= 0 && j - 3 >= 0 && i + 1 <= boarder && j + 1 <= boarder)
                {
                    line = (new StringBuilder()).append(flag[i + 1][j + 1]).append("X").append(flag[i - 1][j - 1]).append(flag[i - 2][j - 2]).append(flag[i - 3][j - 3]).toString();
                    isEqual(i, j, line);
                }
                if(i + 2 <= boarder && j + 2 <= boarder && i - 2 >= 0 && j - 2 >= 0)
                {
                    line = (new StringBuilder()).append(flag[i + 2][j + 2]).append(flag[i + 1][j + 1]).append("X").append(flag[i - 1][j - 1]).append(flag[i - 2][j - 2]).toString();
                    isEqual(i, j, line);
                }
                if(i + 3 <= boarder && j + 3 <= boarder && i - 1 >= 0 && j - 1 >= 0)
                {
                    line = (new StringBuilder()).append(flag[i - 1][j - 1]).append("X").append(flag[i + 1][j + 1]).append(flag[i + 2][j + 2]).append(flag[i + 3][j + 3]).toString();
                    isEqual(i, j, line);
                }
                if(i - 2 >= 0 && j - 2 >= 0 && i + 2 <= boarder && j + 2 <= boarder)
                {
                    line = (new StringBuilder()).append(flag[i - 2][j - 2]).append(flag[i - 1][j - 1]).append("X").append(flag[i + 1][j + 1]).append(flag[i + 2][j + 2]).toString();
                    isEqual(i, j, line);
                }
                if(i + 3 <= boarder && j - 3 >= 0 && i - 1 >= 0 && j + 1 <= boarder)
                {
                    line = (new StringBuilder()).append(flag[i - 1][j + 1]).append("X").append(flag[i + 1][j - 1]).append(flag[i + 2][j - 2]).append(flag[i + 3][j - 3]).toString();
                    isEqual(i, j, line);
                }
                if(i - 2 >= 0 && j + 2 <= boarder && i + 2 <= boarder && j - 2 >= 0)
                {
                    line = (new StringBuilder()).append(flag[i - 2][j + 2]).append(flag[i - 1][j + 1]).append("X").append(flag[i + 1][j - 1]).append(flag[i + 2][j - 2]).toString();
                    isEqual(i, j, line);
                }
                if(j + 2 <= boarder && j - 1 >= 0)
                {
                    line = (new StringBuilder()).append(flag[i][j - 1]).append("X").append(flag[i][j + 1]).append(flag[i][j + 2]).toString();
                    isEqual(i, j, line);
                }
                if(i + 2 <= boarder && i - 1 >= 0)
                {
                    line = (new StringBuilder()).append(flag[i - 1][j]).append("X").append(flag[i + 1][j]).append(flag[i + 2][j]).toString();
                    isEqual(i, j, line);
                }
                if(i - 2 >= 0 && i + 1 <= boarder)
                {
                    line = (new StringBuilder()).append(flag[i + 1][j]).append("X").append(flag[i - 1][j]).append(flag[i - 2][j]).toString();
                    isEqual(i, j, line);
                }
                if(j - 2 >= 0 && j + 1 <= boarder)
                {
                    line = (new StringBuilder()).append(flag[i][j + 1]).append("X").append(flag[i][j - 1]).append(flag[i][j - 2]).toString();
                    isEqual(i, j, line);
                }
                if(i - 2 >= 0 && j + 2 <= boarder && i + 1 <= boarder && j - 1 >= 0)
                {
                    line = (new StringBuilder()).append(flag[i + 1][j - 1]).append("X").append(flag[i - 1][j + 1]).append(flag[i - 2][j + 2]).toString();
                    isEqual(i, j, line);
                }
                if(i - 2 >= 0 && j - 2 >= 0 && i + 1 <= boarder && j + 1 <= boarder)
                {
                    line = (new StringBuilder()).append(flag[i + 1][j + 1]).append("X").append(flag[i - 1][j - 1]).append(flag[i - 2][j - 2]).toString();
                    isEqual(i, j, line);
                }
                if(i + 2 <= boarder && j + 2 <= boarder && i - 1 >= 0 && j - 1 >= 0)
                {
                    line = (new StringBuilder()).append(flag[i - 1][j - 1]).append("X").append(flag[i + 1][j + 1]).append(flag[i + 2][j + 2]).toString();
                    isEqual(i, j, line);
                }
                if(i + 2 <= boarder && j - 2 >= 0 && i - 1 >= 0 && j + 1 <= boarder)
                {
                    line = (new StringBuilder()).append(flag[i - 1][j + 1]).append("X").append(flag[i + 1][j - 1]).append(flag[i + 2][j - 2]).toString();
                    isEqual(i, j, line);
                }
            }

        }

        if(!turn)
            Attack();
    }

    public void isEqual(int i, int j, String s)
    {
        if(s.equals("X2222"))
            powerC[i][j] += 2000;
        if(s.equals("2X222"))
            powerC[i][j] += 2000;
        if(s.equals("22X22"))
            powerC[i][j] += 2000;
        if(s.equals("X1111"))
            powerP[i][j] += 2000;
        if(s.equals("1X111"))
            powerP[i][j] += 2000;
        if(s.equals("11X11"))
            powerP[i][j] += 2000;
        if(s.equals("0X2220"))
            powerC[i][j] += 500;
        if(s.equals("02X220"))
            powerC[i][j] += 500;
        if(s.equals("0X1110"))
            powerP[i][j] += 500;
        if(s.equals("01X110"))
            powerP[i][j] += 500;
        if(s.equals("0X2221"))
        {
            powerC[i][j] += 530;
            comboC[i][j] += 10;
        }
        if(s.equals("X02221"))
        {
            powerC[i][j] += 529;
            comboC[i][j] += 10;
        }
        if(s.equals("02X221"))
        {
            powerC[i][j] += 530;
            comboC[i][j] += 10;
        }
        if(s.equals("20X221"))
        {
            powerC[i][j] += 529;
            comboC[i][j] += 10;
        }
        if(s.equals("20X220"))
        {
            powerC[i][j] += 529;
            comboC[i][j] += 10;
        }
        if(s.equals("2X0221"))
        {
            powerC[i][j] += 529;
            comboC[i][j] += 10;
        }
        if(s.equals("2X0220"))
        {
            powerC[i][j] += 529;
            comboC[i][j] += 10;
        }
        if(s.equals("2X202"))
        {
            powerC[i][j] += 529;
            comboC[i][j] += 3;
        }
        if(s.equals("12X220"))
        {
            powerC[i][j] += 530;
            comboC[i][j] += 10;
        }
        if(s.equals("0X1112"))
        {
            powerP[i][j] += 29;
            comboP[i][j] += 10;
        }
        if(s.equals("X01112"))
        {
            powerP[i][j] += 29;
            comboP[i][j] += 10;
        }
        if(s.equals("01X112"))
        {
            powerP[i][j] += 29;
            comboP[i][j] += 10;
        }
        if(s.equals("10X112"))
        {
            powerP[i][j] += 29;
            comboP[i][j] += 10;
        }
        if(s.equals("10X110"))
        {
            powerP[i][j] += 29;
            comboP[i][j] += 10;
        }
        if(s.equals("1X101"))
        {
            powerP[i][j] += 29;
            comboP[i][j] += 3;
        }
        if(s.equals("1X0112"))
        {
            powerP[i][j] += 29;
            comboP[i][j] += 10;
        }
        if(s.equals("1X0110"))
        {
            powerP[i][j] += 29;
            comboP[i][j] += 10;
        }
        if(s.equals("21X110"))
        {
            powerP[i][j] += 29;
            comboP[i][j] += 10;
        }
        if(s.equals("0X220"))
        {
            powerC[i][j] += 9;
            comboC[i][j]++;
        }
        if(s.equals("0X0220"))
        {
            powerC[i][j] += 9;
            comboC[i][j]++;
        }
        if(s.equals("02X20"))
        {
            powerC[i][j] += 9;
            comboC[i][j]++;
        }
        if(s.equals("0X2020"))
        {
            powerC[i][j] += 8;
            comboC[i][j]++;
        }
        if(s.equals("02X020"))
        {
            powerC[i][j] += 8;
            comboC[i][j]++;
        }
        if(s.equals("0X110"))
            comboP[i][j]++;
        if(s.equals("0X0110"))
            comboP[i][j]++;
        if(s.equals("01X10"))
            comboP[i][j]++;
        if(s.equals("0X1010"))
            comboP[i][j]++;
        if(s.equals("01X010"))
            comboP[i][j]++;
        if(s.equals("0X20"))
            powerC[i][j] += 2;
    }

    public void Attack()
    {
        for(int i = 0; i < length; i++)
        {
            for(int k = 0; k < length; k++)
            {
                if(comboP[i][k] > 10)
                    powerP[i][k] += 500;
                if(comboP[i][k] >= 2 && comboP[i][k] < 10)
                    powerP[i][k] += 50;
                if(comboC[i][k] > 10)
                    powerC[i][k] += 500;
                if(comboC[i][k] >= 2 && comboC[i][k] < 10)
                    powerC[i][k] += 50;
            }

        }

        int j = -1;
        int l = 0;
        int i1 = 0;
        for(int j1 = 0; j1 < length; j1++)
        {
            for(int l1 = 0; l1 < length; l1++)
                if(powerC[j1][l1] + powerP[j1][l1] > j)
                {
                    j = powerC[j1][l1] + powerP[j1][l1];
                    l = j1;
                    i1 = l1;
                }

        }

        if(j > 0 && flag[l][i1] == "0")
            setMark(l, i1);
        for(int k1 = 0; k1 < length; k1++)
        {
            for(int i2 = 0; i2 < length; i2++)

⌨️ 快捷键说明

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