Java小程序,都是我个人的一些练习代码,

//java小程序1
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;


@SuppressWarnings("serial")
public class TestCalendar extends JFrame implements ItemListener{
private JComboBox list1;
private JComboBox list2;
private JComboBox list3;
private String []yearStr = new String[100];
private String []monthStr = {"1","2","3","4","5","6","7","8","9","10","11","12"};
private String []dayStr = new String[31];
private int index1;
private int index2;
private int index3;


public TestCalendar(){
for(int i = 0 ; i < 100 ; i ++){
yearStr[i] = String.valueOf(i+2000);
}
for(int i = 0 ; i < 31 ; i ++){
dayStr[i] = String.valueOf(i+1);
}
JPanel panel = new JPanel();
list1 = new JComboBox(yearStr);
list1.addItemListener(this);
panel.add(list1);
list2 = new JComboBox(monthStr);
list2.addItemListener(this);
panel.add(list2);
list3 = new JComboBox(dayStr);
panel.add(list3);
this.add(panel);
initJFrame();
}


private void initJFrame() {
this.setLocation(400,400);
this.pack();
this.setResizable(false);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
}

@Override
public void itemStateChanged(ItemEvent arg0) {
index1 = list1.getSelectedIndex();
index2 = list2.getSelectedIndex();
if(Integer.parseInt(monthStr[index2]) == 1 || Integer.parseInt(monthStr[index2]) == 3
|| Integer.parseInt(monthStr[index2]) == 5 || Integer.parseInt(monthStr[index2]) == 7
|| Integer.parseInt(monthStr[index2]) == 8 || Integer.parseInt(monthStr[index2]) == 10
|| Integer.parseInt(monthStr[index2]) == 12){
index3 = 31;
}else if(Integer.parseInt(monthStr[index2]) == 4 || Integer.parseInt(monthStr[index2]) == 6
|| Integer.parseInt(monthStr[index2]) == 9 || Integer.parseInt(monthStr[index2]) == 11
){
index3 = 30;
}else{
if(Integer.parseInt(yearStr[index1]) % 4 == 0 &&Integer.parseInt(yearStr[index1]) % 100 != 0
|| Integer.parseInt(yearStr[index1]) % 400 == 0){
index3 = 29;
}else{
index3 = 28;
}
}
list3.removeAllItems();
for(int i = 0 ; i < index3 ;i ++){
list3.addItem(dayStr[i]);
}
}
public static void main(String[] args) {

new TestCalendar();
}
}

public class CommonCard extends CreditCard{
private final int creditcardnum=0;//把普通用户的信用度设置为0
static CommonCard cd=new CommonCard();
static CreditCard cd1=new CreditCard();
public static void bankManager(){//控制英航管理员登录
System.out.println("请输入口令(123456):");
String m=sc.next();
if(m.equals("123456")){
while(true){
System.out.println("输入1查询所有用户信息");
System.out.println("输入2查询某个用户信息");
System.out.println("输入3退出");
int w=sc.nextInt();
switch(w){
ca

se 1:cd.selectAll();
case 2:cd.selectA();
case 3:System.exit(0);
}
}
}
}
public void manage(){//定义用户取款存款界面
System.out.println("取款输入1");
System.out.println("存款输入2");
System.out.println("修改密码输入3");
System.out.println("输入4返回");
int w=sc.nextInt();
switch(w){
case 1:cd1.takeMoney();manage();break;
case 2:cd1.setMoney();manage();break;
case 3:cd1.changePassworld();manage();break;
case 4:return;
}
}
public static void main(String[] args) {//用户登录界面
while(true){
System.out.println("注册普通用户输入1");
System.out.println("注册信用卡输入2");
System.out.println("普通用户登录请输入3");
System.out.println("信用卡用户登录请输入4");
System.out.println("退出请输入5");
System.out.println("用户管理员登录输入6");
int w=sc.nextInt();
switch(w){
case 1:cd.register();break;
case 2:cd1.register();cd1.setcreditcardnum();break;
case 3://cd.putin(0);
if(cd.putin(0)){cd.manage();}break;
case 4://cd1.putin(0);
if(cd1.putin(1)){cd.manage();}break;
case 5:System.exit(0);
case 6:bankManager();
}
}
}
}
import java.util.*;

public class CreditCard {
public static String[] username1 = new String[100];// 定义数组保存用户名
public static String[] paswsword1 = new String[100];// 保存用户密码
public static int a = 0;// 判断数否可以注册,没注册一个a+=2,a=6不能继续注册;
public static int m = 0;
public double balance;// 定义用户余额
public String username;// 定义用户名
public String password;// 定义用户密码
public String id;// 定义用户身份证号码
public String email;// 定义用户email
public int creditcardnum;// 定义用户信用卡数目
public static Scanner sc = new Scanner(System.in);
public void push(String[] b, String c) {// 把c放到数组b里面,a不能被2整除,a——,能被2整除a++
if (m <= username.length()&&b.equals(username1)) {
b[m] = c;
m++;
}
if (a <= username.length()&&b.equals(paswsword1)) {
b[a] = c;
a++;
}
}

public void selectAll() {// 查询所有用户信息,没有用户输出没有用户

for (int i = 0; i <= username1.length - 1; i++) {
System.out.println("用户名:" + username1[i]);
System.out.println("密码:" + paswsword1[i]);
if(username1[i]==null){
if(i==0){
System.out.println("没有用户注册");
}
return;
}
}
}

public void selectA() {// 查找某一个用户信息
System.out.println("请输入要查找的用户名");
String next = sc.next();
for (int i = 0; i <= username1.length; i++) {
if (username1[i].equals(next)) {
System.out.println("用户名:" + username1[i]);
System.out.println("密码:" + paswsword1[i]);
re

turn;
} else {
if (i == username1.length) {
System.out.println("没有该用户");
}
}
}
}

protected int setcreditcardnum() {// 随机产生信用卡号码
Random ran = new Random();
creditcardnum = ran.nextInt(100);
System.out.println("您随机产生的信用度为:" + creditcardnum);
return creditcardnum;
}

public void takeMoney() {// 取款函数,信用卡用户可以透资,普通用户信用度被定义为0,而且不可改变
System.out.println("请输入取款金额");
double TAKE = sc.nextDouble();
if (TAKE <= this.balance + this.creditcardnum) {
this.balance -= TAKE;
System.out.println("取款成功");
System.out.println("余额"+this.balance);
} else {
System.out.println("余额不足");
}
}

public void setMoney() {// 存款函数
System.out.println("请输入存款金额");
double TAKE = sc.nextDouble();
this.balance += TAKE;
System.out.println("存款成功" + balance);
}

public void register() {// 注册,同时把注册的信息打到数组里面;可以判定用户是否存在,存在就不存储了
System.out.println("请输入用户名");
String x = sc.next();
for (int i = 0; i <= username1.length - 1; i++) {
if (x.equals(username1[i])) {
System.out.println("该用户名存在,请重新输入");
return;
}
}
https://www.360docs.net/doc/bd7213109.html,ername = x;
push(username1, username);
System.out.println("请输入密码");
this.password = sc.next();
push(paswsword1, password);
System.out.println("请输入邮箱");
this.email = sc.next();
System.out.println("请输入身份证号码");
this.id = sc.next();
System.out.println("注册成功"+"您的余额为0");
}
public boolean putin(int b) {// 登录信息,做个扫描字符串,判断是否可以登录,如果可以登录返回true,不能则返回false;
boolean c=false;
String username2="x";
String password2="x";
if (b == 0) {
System.out.println("请输入用户名");
username2 = sc.next();
System.out.println("请输入密码");
password2 = sc.next();}
for (int i = 0; i <= username1.length - 1; i++) {
if (username2.equals(String.valueOf(username1[i]))
&& password2.equals(String.valueOf(paswsword1[i]))) {
System.out.println("登录成功");
c=true;
}
}
if(!c){
System.out.println("密码或者用户名不正确");
}
return c;
}

public boolean changePassworld() {// 修改密码
System.out.println("请再次输入用户名");
String username3 = sc.next();
System.out.println("请再次输入密码");
String password3 = sc.next();
System.out.println("请输入新密码");
String password0 = sc.next();
System.out.println("请再次输入新密码");
String password2 = sc.next();
if (password0.equals(password2)) {
for (int i = 0; i <= username1.length - 1; i++) {
if (username3.equals(username1[i])) {
S

ystem.out.println("修改密码成功");
paswsword1[i]=password0;
}
}
System.out.println("修改密码成功");
return true;
}
return false;
}
}

package homework;
import java.util.Scanner;


public class Arrays {
public static void main(String[] args){
int[]a=new int[]{0,1,2,3,5,6,7};

int[][]r={{1,2,3},{2,3,4},{3,45,3}};
int[]b=copy(a);
System.out.println("数组的遍历");
bianLi(r);
int[]e=copyOf(a);
sort(a);
sortNi(a);
search(a);
}
//将前一个数组的内容拷贝给后一个数组
public static int[] copy(int[] a){

System.out.println("数组的复制");
int b[]=new int[a.length];
for(int i=0;ib[i]=a[i];
System.out.println(b[i]);
}
return b;
}

public static void bianLi(int[][]r){

for(int[] b:r){
for(int i: b){
System.out.print(b);
}
System.out.println();
}
}
public static int[] copyOf(int[]a){
System.out.println("数组的指定位复制");
int n=4;
int[]d=new int[n];
for(int j=0;jd[j]=a[j];
}
System.out.println(d);
return d;
}
public static void search(int[]a){
Scanner sc = new Scanner(System.in);
System.out.println("数组的查找,请输入要查找的数");
int f=sc.nextInt();
for(int i=0;iif(a[i]==f){
System.out.println("第一次出现的位置是第"+(i+1)+"个位置");
}
if(i==a.length-1&&a[i]!=f){
System.out.println("没有该数");
}
}
}
public static void sort(int[] a){
System.out.println("数组的排序,逆序:");


for(int i=0;ifor(int j=1;jif(a[j-1]int temp = a[j];
a[j] = a[j-1];
a[j-1] = temp;

}
}

}
for(int b:a){
System.out.print(b);
System.out.println();

}
}
public static void sortNi(int[] a){
System.out.println("数组的排序,正序:");
for(int i=0;ifor(int j=1;jif(a[j-1]>a[j]){//把a[j-1]和a[j]互换位置;
int temp = a[j];
a[j] = a[j-1];
a[j-1] = temp;
}
}

}
for(int b:a){
System.out.print(b);
System.out.println();

}
}
public static void bian(int[] a){
for(int i=0;iSystem.out.println( a[i] + ",");
}
}
}

import java.util.Scanner;

public class Chunquan {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("亲,请输入这个圈子的总人数:");
int n = sc.nextInt();
System.out.println("亲,请输入您想让第几个人出圈:");
int m = sc.nextInt();
int f1 = 0;
int f2 = 0;
int b=0;
int[] a

= new int[n];
for (int i = 0; i < n; i++) {
a[i] = 1;
}

for (int k = 0; k <= n + 2; k++) {
if (k == n - 1) {
b++;
if (b == m*n) {
k = n + 2;
}
}
if (k == n+1) {
k = 0;
}
if (k f1 = f2 + a[k];// 1,1,2,2,3,3
f2 = f1;
if (f2 % m == 0) {
if(a[k]!=0){
System.out.println("第"+(k+1)+"个人出圈");
a[k]=0;
}

}
}
}
}

}
import java.util.Scanner;


//可以从控制太接收一个person对象吗,那样就可以判断输入两个人的信息是否可以结婚,当然也可以勉强实现,感觉有点别扭,空指针异常。。。。。。
//有个容器可以查找出可以和输入者结婚的人
//不懂得如何把一个String类型的东西转换为一个类
public class Jiehun {

public static void main(String[] args) {
System.out.println("输入1,查询内存中的结婚对象");
System.out.println("输入2,查看某两个人是否可以结婚");
Scanner sc=new Scanner(System.in);//在前面申明了scanner类,这是创建对象,后面是scanner类的一个构造函数
int a1=sc.nextInt();
switch(a1){

case 1:

Person Hellon = new Person("Hellon", 23, "女");
// TODO Auto-generated method stub
Person a = new Person("王手艺", 56, "男", Hellon);
Person b = new Person("吴鹏", 25, "男", null);
Person c = new Person("比尔", 12, "男", a);
Person d = new Person("Lucy", 16, "女", null);
Person e = new Person("杨幂", 22, "女", null);
int pd = 0;
int dp=0;
pd = a.marry(a, b, 1);
if (pd == 1) {
System.out.println(https://www.360docs.net/doc/bd7213109.html,+"和"+https://www.360docs.net/doc/bd7213109.html,+"不能结婚的原因是:");
}
a.marry(a, b, 0);
System.out.println("");
pd = a.marry(b, c, 1);
if (pd == 1) {
System.out.println(https://www.360docs.net/doc/bd7213109.html,+"和"+https://www.360docs.net/doc/bd7213109.html,+"不能结婚的原因是:");
}
a.marry(b, c, 0);
System.out.println("");
pd = a.marry(c, d, 1);
if (pd == 1) {
System.out.println(https://www.360docs.net/doc/bd7213109.html,+"和"+https://www.360docs.net/doc/bd7213109.html,+"不能结婚的原因是:");
}
a.marry(c, d, 0);
System.out.println("");
pd = a.marry(b, e, 1);
if (pd == 1) {
System.out.println(https://www.360docs.net/doc/bd7213109.html,+"和"+https://www.360docs.net/doc/bd7213109.html,+"不能结婚的原因是:");
}
a.marry(b, e, 0);
break;
case 2:
System.out.println("请依次输入您的姓名,年龄,性别,配偶名字(没有请输入null)");
String name1=sc.next();
int age1=sc.nextInt();
String gender1=sc.next();
String partner1=null;
partner1=sc.next();
System.out.println("请依次输入您对象姓名,年龄,性别,配偶名字(没有请输入null)");
String name2=sc.next();
int age2=sc.nextInt();
String gender2=sc.next();
String partner2=null;
partner2=sc.next();
Person e3=new Person(name1,age1,gender1,null);
Person e4=new Person(name2,age2,gender2,null);
if(partner1.equals(name2)||name1.equals(partner2)){
System.out.println("你们已经结过婚了。");
return;
}

if(part

ner1.equals("null")&&partner2.equals("null")){
dp = e3.marry(e3, e4, 1);
if (dp == 1) {
System.out.println(https://www.360docs.net/doc/bd7213109.html,+"和"+https://www.360docs.net/doc/bd7213109.html,+"不能结婚的原因是:");
}
e3.marry(e3, e4, 0);
System.out.println("");
}

if(!partner1.equals("null")||!partner2.equals("null")){
System.out.println("你们中间有人有配偶了,不能结婚");
}

}
}
}
import java.util.Scanner;

public class Person {
public String name;// 定义姓名
int age;// 年龄
String gender;// 性别
Person partner = null;// 配偶

public String getName() {
return name;
}

public void setName(String name) {
https://www.360docs.net/doc/bd7213109.html, = name;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public String getGender() {
return gender;
}

public void setGender(String gender) {
this.gender = gender;
}

public Person getPartner() {
return partner;
}

public void setPartner(Person partner) {
this.partner = partner;
}

public Person(String name, int age, String gender) {
https://www.360docs.net/doc/bd7213109.html, = name;
this.age = age;
this.gender = gender;

}

public Person(String name, int age, String gender, Person partner) {
https://www.360docs.net/doc/bd7213109.html, = name;
this.age = age;
this.gender = gender;
this.partner = partner;
}

public static int marry(Person p, Person q, int l) {// 如果有返回值可以控制只输出一个不能结婚的原因,l控制是不是应该输出东西
int m = 0;// 判断是否可以结婚
int n = 1;// 返回值
if (p.gender.equals(q.gender)) {
m = 2;
if (l == 0) {
System.out
.println("您好," + https://www.360docs.net/doc/bd7213109.html, + "和" + https://www.360docs.net/doc/bd7213109.html, + "的性别相同,不能结婚");
}
}
if (q.age < 24 && q.gender.equals("男")) {
m = 2;
if (l == 0) {
System.out.println(https://www.360docs.net/doc/bd7213109.html, + "没有达到法定结婚年龄");
}

}
if (p.age < 24 && p.gender.equals("男")) {
m = 2;
if (l == 0) {
System.out.println(https://www.360docs.net/doc/bd7213109.html, + "没有达到法定结婚年龄");
}
}
if (q.age < 22 && q.gender.equals("女")) {
m = 2;
if (l == 0) {
System.out.println(https://www.360docs.net/doc/bd7213109.html, + "没有达到法定结婚年龄");
}
}
if (p.age < 22 && p.gender.equals("女")) {
m = 2;
if (l == 0) {
System.out.println(https://www.360docs.net/doc/bd7213109.html, + "没有达到法定结婚年龄");
}
}
if (p.partner != null) {
m = 2;
if (l == 0) {
System.out.println(https://www.360docs.net/doc/bd7213109.html, + "有配偶,不可以结婚");
}
}
if (q.partner != null) {
m = 2;
if (l == 0) {
System.out.println(https://www.360docs.net/doc/bd7213109.html, + "有配偶,不可以结婚");
}
}
if (m == 0) {
n = 2;
if (l == 0) {
System.out.println("恭喜" + https://www.360docs.net/doc/bd7213109.html, + https://www.360docs.net/doc/bd7213109.html, + "可以结婚");
}
}
return n;
}

}

import java.applet.Applet;
import java.awt.*;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event

.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
public abstract class Qi extends Applet implements ActionListener, MouseListener,
MouseMotionListener, ItemListener{
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseDragged(MouseEvent e) {}
public void mouseMoved(MouseEvent e) {}
public void paint(Graphics g) {//画线
g.setColor(Color.gray);
g.fill3DRect(0, 0, 360, 360, true);
g.setColor(Color.black);
for (int i = 1; i < 10; i++) {
g.drawLine(30, 30 * i, 270, 30 * i);}//列
for(int j=1;j<10;j++){
g.drawLine(30 * j, 30, 30 * j, 150);
}
for(int j=1;j<10;j++){
g.drawLine(30 * j, 180, 30 * j, 300);
}
g.drawLine(30, 150, 30 ,180);
g.drawLine(270, 150, 270, 180);
g.drawLine(120, 30, 180, 90);
g.drawLine(180, 30, 120, 90);
g.drawLine(120, 300, 180, 240);
g.drawLine(180, 300,120 ,240);
//Font ju = new Font("Courier", Font.BOLD, 22);
//g.setFont(ju);
// g.drawString("车", 22, 40);

// 显示圆形
Font fsib30 = new Font("宋体",Font.ITALIC+Font.BOLD,25);
String name = fsib30.getFontName();
g.setFont(fsib30);
g.drawString("楚河 汉界",50,175);
for(int i=0;i<9;i++){
for(int m=0;m<10;m++){
g.setColor(Color.white);
g.drawOval(19+i*30,20, 25, 25);
g.drawOval(19+i*30,285, 25, 25);
g.setColor(Color.red);
Font j = new Font("Courier", Font.BOLD, 22);
g.setFont(j);
if(m==3&&i%2==0){
g.setColor(Color.black);
g.setColor(Color.white);
g.drawOval(19+i*30,20+30*m, 25, 25);
g.drawOval(19+i*30,285-30*m, 25, 25);
g.setColor(Color.red);
g.drawString("兵", 22+i*30, 40+30*m);
g.setColor(Color.black);
g.drawString("卒", 22+30*i, 305-30*m);
}
if(i==1&&m==2){
g.setColor(Color.black);
g.setColor(Color.white);
g.drawOval(19+i*30,20+30*m, 25, 25);
g.drawOval(19+i*30,285-30*m, 25, 25);
g.setColor(Color.red);
g.drawString("炮", 22+i*30, 40+30*m);
g.setColor(Color.black);
g.drawString("炮", 22+30*i, 305-30*m);
}
if(i==7&&m==2){
g.setColor(Color.black);
g.setColor(Color.white);
g.drawOval(19+7*30,20+30*m, 25, 25);
g.drawOval(19+7*30,285-30*m, 25, 25);
g.setColor(Color.red);
g.drawString("炮", 22+7*30, 40+30*m);
g.setColor(Color.black);
g.drawString("炮", 22+7*30, 305-30*m);
}
if(i==0||i==8){
g.drawString("车", 22+i*30, 40);
g.setColor(Color.black);
g.drawString("车", 22+30*i, 305);}
if(i==1||i==7){
g.drawString("马", 22+i*30, 40);
g.setColor(Color.black);
g.drawString("马", 22+30*i, 305);}
if(i==2||i==6){
g.drawString("象", 22+i*30, 40);
g.setColor(Color.black);
g.drawString("象", 22+30*i, 305);}
if(i==3||i

==5){
g.drawString("士", 22+i*30, 40);
g.setColor(Color.black);
g.drawString("士", 22+30*i, 305);}
if(i==4){
g.drawString("帅", 22+i*30, 40);
g.setColor(Color.black);
g.drawString("将", 22+30*i, 305);}
}
}// 前两个是圆形坐标,后两个是园的上下直径
//Font ju = new Font("Courier", Font.BOLD, 20);
//g.setFont(ju);
// g.setColor(Color.black);
// g.drawOval(21, 20, 25, 25); // 前两个是圆形坐标,后两个是园的上下直径
//g.setColor(Color.red);
//g.drawString("车", 25, 40);
//String name = ju.getFontName();
}

public void itemStateChanged(ItemEvent e) {
// TODO Auto-generated method stub

}
public static void main(String[] args){
paint(Graphics g);
}
static class mouseHandler extends MouseAdapter{
public void mousePressed(MouseEvent e) {
int x=e.getX();
int y=e.getY();
if(x<10||x>290||y<10||y>320){
return ;
}
if(x%30<15){
x+=30;
x=x/30;
}
if(y%30<15){
y+=30;
y=y/30;
}
Font f = new Font("",Font.ITALIC+Font.BOLD,25);
String name = f.getFontName();
if(name!=null){
System.out.println(name);
}
}
}
}

import java.util.Scanner;

public class Wuziqi {
// 数组a负责保存棋盘,而且是23行23咧,但是控制台打印的是15行15列的矩阵,因为for循环扫描不到一些边缘数据
static int[][] a = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0 }, };
static int hei = 0;// 控制让电脑只能在一个地方下子,如果hei=0表示电脑未下子,hei=2表示电脑已经下子,不能再下

public static void or(int q) {// 接受人输入进来的坐标,经过控制可以打印出来的数组进行操作
Scanner sc = new Scanner(System.in);
System.out.println("请输入0到14的坐标");
int x1 = sc.nextInt();
int x2 = sc.nextInt();
if (x1 < 0 || x1 >= 15 || x2 < 0 || x2 >= 15) {
System.out.println("输入坐标超出范围请重新输入:");// 超出范围
or(q);
}
if (x1 >= 0 && x1 < 15 && x2 >= 0 && x2 < 15) {
{
if (a[x1 + 4][x2 + 4] != 0) {// 该点有棋子
System.out.println("该坐标有子,请重新输入");
or(q);
} else {
a[x1 + 4][x2 + 4] = q;

}
}
}
}

public static void ko(int p, int q, int m) {
for (int i = 0; i < 23; i++) {
for (int j = 0; j < 23; j++) {
if (i >= 4 && i < 19 && j >= 4 && j < 19) {
int c = 0;
int b = 0;
if (i < 19) {
if (a[i][j] == p) {
c++;
}
if (a[i][j + 1] == p) {
c++;
}
if (a[i][j + 2] == p) {
c++;
}
if (a[i][j + 3] == p) {
c++;
}

if (a[i][j + 4] == p) {
c++;
}
if (a[i][j] == q) {
c = 0;
}
if (a[i][j + 1] == q) {
c = 0;
}
if (a[i][j + 2] == q) {
c = 0;
}
if (a[i][j + 3] == q) {
c = 0;
}
if (a[i][j + 4] == q) {
c = 0;
}
if (c == m) {
if (a[i][j] == 0 && hei == 0) {
a[i][j] = q;
hei = 2;
c = 0;
}
if (a[i][j + 1] == 0 && hei == 0) {
a[i][j + 1] = q;
c = 0;
hei = 2;
}
if (a[i][j + 2] == 0 && hei == 0) {
a[i][j + 2] = q;
hei = 2;
c = 0;
}
if (a[i][j + 3] == 0 && hei == 0) {
a[i][j + 3] = q;
c = 0;
hei = 2;
}
if (a[i][j + 4] == 0 && hei == 0) {
a[i][j + 4] = q;
c = 0;
hei = 2;
}
}
}
}
}
}

for (int i = 0; i < 23; i++) {
for (int j = 0; j < 23; j++) {
if (i >= 4 && i < 19 && j >= 4 && j < 19) {
int c = 0;
int b = 0;
if (i < 19) {
if (a[i][j] == p) {
c++;
}
if (a[i + 1][j] == p) {
c++;
}
if (a[i + 2][j] == p) {
c++;
}
if (a[i + 3][j] == p) {
c++;
}

if (a[i + 4][j] == p) {
c++;
}
}
if (a[i][j] ==

q) {
c = 0;
}
if (a[i + 1][j] == q) {
c = 0;
}
if (a[i + 2][j] == q) {
c = 0;
}
if (a[i + 3][j] == q) {
c = 0;
}
if (a[i + 4][j] == q) {
c = 0;
}
if (c == m) {
if (a[i][j] == 0 && hei == 0) {
a[i][j] = q;
c = 0;
hei = 2;
}
if (a[i + 1][j] == 0 && hei == 0) {
a[i + 1][j] = q;
c = 0;
hei = 2;
}
if (a[i + 2][j] == 0 && hei == 0) {
a[i + 2][j] = q;
c = 0;
hei = 2;
}
if (a[i + 3][j] == 0 && hei == 0) {
a[i + 3][j] = q;
c = 0;
hei = 2;
}
if (a[i + 4][j] == 0 && hei == 0) {
a[i + 4][j] = q;
c = 0;
hei = 2;
}
}
}

}
}
for (int i = 0; i < 23; i++) {
for (int j = 0; j < 23; j++) {
if (i >= 4 && i < 19 && j >= 4 && j < 19) {
int c = 0;
int b = 0;
if (i < 19 && j < 19) {
if (a[i][j] == p) {
c++;
}
if (a[i + 1][j + 1] == p) {
c++;
}
if (a[i + 2][j + 2] == p) {
c++;
}
if (a[i + 3][j + 3] == p) {
c++;
}
if (a[i + 4][j + 4] == p) {
c++;
}
if (a[i][j] == q) {
c = 0;
}
if (a[i + 1][j + 1] == q) {
c = 0;
}
if (a[i + 2][j + 2] == q) {
c = 0;
}
if (a[i + 3][j + 3] == q) {
c = 0;
}

if (a[i + 4][j + 4] == q) {
c = 0;
}
if (c == m) {
if (a[i][j] == 0 && hei == 0) {
a[i][j] = q;
c = 0;
hei = 2;
}
if (a[i + 1][j + 1] == 0 && hei == 0) {
a[i + 1][j + 1] = q;
c = 0;
hei = 2;
}
if (a[i + 2][j + 2] == 0 && hei == 0) {
a[i + 2][j + 2] = q;
c = 0;
hei = 2;
}
if (a[i + 3][j + 3] == 0 && hei == 0) {
a[i + 3][j + 3] = q;
c = 0;
hei = 2;
}
if (a[i + 4][j + 4] == 0 && hei == 0) {
a[i + 4][j + 4] = q;
hei = 2;
c = 0;
}
}
}
}
}

}
for (int i = 0; i < 23; i++) {
for (int j = 0; j < 23; j++) {
if (i >= 4 && i < 19 && j >= 4 && j < 19) {
int c = 0;
int b = 0;
if (i < 19) {
if (a[i][j] == p) {
c++;
}
if (a[i + 1][j - 1] == p) {
c++;
}
if (a[i + 2][j - 2] == p) {
c++;
}
if (a[i + 3][j - 3] == p) {
c++;
}

if (a[i + 4][j - 4] == p) {
c++;
}
if (a[i][j] == q) {
c = 0;
}
if (a[i + 1][j - 1] == q) {
c = 0;
}
if (a[i + 2][j - 2] == q) {
c = 0;
}
if (a[i + 3][j - 3] == q) {
c = 0;
}
if (a[i + 4][j - 4] == q) {
c = 0;
}
if (c == m) {
if (a[i][j] =

= 0 && hei == 0) {
a[i][j] = q;
c = 0;
hei = 2;
}
if (a[i + 1][j - 1] == 0 && hei == 0) {
a[i + 1][j - 1] = q;
c = 0;
hei = 2;
}
if (a[i + 2][j - 2] == 0 && hei == 0) {
a[i + 2][j - 2] = q;
c = 0;
hei = 2;
}
if (a[i + 3][j - 3] == 0 && hei == 0) {
a[i + 3][j - 3] = q;
c = 0;
hei = 2;
}
if (a[i + 4][j - 4] == 0 && hei == 0) {
a[i + 4][j - 4] = q;
c = 0;
hei = 2;
}
}
}
}

}

}
}
// 判断输赢
public static int judge(int m, int a[][], String n) {// 判断输赢,写的复杂了可以省掉一半该函数
for (int i = 0; i < 23; i++) {// 一行成五个
for (int j = 0; j < 23; j++) {
if (i < 19) {
if (a[i][j] == m && a[i + 1][j] == m && a[i + 2][j] == m
&& a[i + 3][j] == m && a[i + 4][j] == m) {
System.out.println(n + "下载的最后一个坐标是" + i + " " + j);
System.out.println(n + "子获胜,继续努力");
return m;

}
}
}
}
for (int i = 0; i < 23; i++) {// 一行5个
for (int j = 0; j < 23; j++) {
if (i >= 4) {
if (a[i][j] == m && a[i - 1][j] == m && a[i - 2][j] == m
&& a[i - 3][j] == m && a[i - 4][j] == m) {
System.out.println(n + "下载的最后一个坐标是" + i + " " + j);
System.out.println(n + "子获胜,继续努力");
return m;
}
}
}
}
for (int i = 0; i < 23; i++) {// 一列5个
for (int j = 0; j < 23; j++) {
if (j >= 4) {
if (a[i][j] == m && a[i][j + 1] == m && a[i][j + 2] == m
&& a[i][j + 3] == m && a[i][j + 4] == m) {
System.out.println(n + "下载的最后一个坐标是" + i + " " + j);
System.out.println(n + "子获胜,继续努力");
return m;
}
}
}
}
for (int i = 0; i < 23; i++) {// 一列五个
for (int j = 0; j < 23; j++) {
if (i < 19 && i >= 4 && j < 19 && j >= 4) {
if (a[i][j] == m && a[i][j - 1] == m && a[i][j - 2] == m
&& a[i][j - 3] == m && a[i][j - 4] == m) {
System.out.println(n + "下载的最后一个坐标是" + i + " " + j);
System.out.println(n + "子获胜,继续努力");
return m;
}
}
}
}
for (int i = 0; i < 23; i++) {// 右斜五个
for (int j = 4; j < 23; j++) {
if (i < 19 && i >= 4 && j < 19 && j >= 4) {
if (a[i][j] == m && a[i + 1][j + 1] == m
&& a[i + 2][j + 2] == m && a[i + 3][j + 3] == m
&& a[i + 4][j + 4] == m) {
System.out.println(n + "下载的最后一个坐标是" + i + " " + j);
System.out.println(n + "获胜");
return m;
}
}
}
}
for (int i = 0; i < 23; i++) {// 右斜五个
for (int j = 4; j < 23; j++) {
if (i < 19 && i >= 4 && j < 19 && j >= 4) {
if (a[i][j] == m && a[i - 1][j - 1] == m

&& a[i - 2][j - 2] == m && a[i - 3][j - 3] == m
&& a[i - 4][j - 4] == m) {
System.out.println(n + "下载的最后一个坐标是" + i + " " + j);
System.out.println(n + "获胜,");
return m;
}
}
}
}
for (int i = 0; i < 23; i++) {// 左斜五个
for (int j = 0; j < 23; j++) {
if (i < 19 && i >= 4 && j < 19 && j >= 4) {

if (a[i][j] == m && a[i - 1][j + 1] == m
&& a[i - 2][j + 2] == m && a[i - 3][j + 3] == m
&& a[i - 4][j + 4] == m) {
System.out.println(n + "下载的最后一个坐标是" + i + j);
System.out.println(n + "获胜,");
return m;
}
if (a[i][j] == m && a[i + 1][j - 1] == m
&& a[i + 2][j - 2] == m && a[i + 3][j - 3] == m
&& a[i + 4][j - 4] == m) {
System.out.println(n + "下载的最后一个坐标是" + i + " " + j);
System.out.println(n + "获胜");
return m;
}

}
}
}
return 0;
}
public static void fang(int p, int q, int a[][]) {// 控制电脑的进攻和防御

for (int i = 0; i < 23; i++) {
for (int j = 0; j < 23; j++) {// 功四个一行
if (i >= 4) {
if (a[i][j] == q && a[i][j + 1] == q && a[i][j + 2] == q
&& a[i][j + 3] == q) {
if (a[i][j + 4] == 0 && hei == 0 && i >= 4 && i < 19
&& j >= 4 && j < 19) {
a[i][j + 4] = q;
hei = 2;
}
if (a[i][j - 1] == 0 && hei == 0 && i >= 4 && i < 19
&& j >= 4 && j < 19) {
a[i][j - 1] = q;
hei = 2;
}
}
}
}
}
for (int i = 0; i < 23; i++) {
for (int j = 0; j < 23; j++) {// 功 4个一列
if (i < 19) {
if (a[i][j] == 1 && a[i + 1][j] == 1 && a[i + 2][j] == 1
&& a[i + 3][j] == 1) {
if (a[i + 4][j] == 0 && hei == 0) {
a[i + 4][j] = 1;
hei = 2;

}
if (a[i - 1][j] == 0 && hei == 0 && i >= 4 && i < 19
&& j >= 4 && j < 19) {
a[i - 1][j] = 1;
hei = 2;
}

}
}
}
}
for (int i = 0; i < 23; i++) {// 功四个右斜
for (int j = 0; j < 23; j++) {
if (i < 19 && j >= 4 && i >= 4 && j < 19) {
if (a[i][j] == q && a[i + 1][j + 1] == q
&& a[i + 2][j + 2] == q && a[i + 3][j + 3] == q) {
if (a[i + 4][j + 4] == 0 && hei == 0 && i >= 4
&& i < 19 && j >= 4 && j < 19) {
a[i + 4][j + 4] = q;
hei = 2;

}
if (a[i - 1][j - 1] == 0 && hei == 0 && i >= 4
&& i < 19 && j >= 4 && j < 19) {
a[i - 1][j - 1] = q;
hei = 2;

}
}

}
}
}
for (int i = 0; i < 23; i++) {// 功 四个左斜
for (int j = 0; j < 23; j++) {
if (i < 19 && j > 4 && i > 4 && j < 19) {
if (a[i][j] == q && a[i - 1][j + 1] == q
&& a[i - 2][j + 2] == q && a[i - 3][j + 3] == q) {
if (a[i - 4][j + 4] == 0 && hei == 0 && i >= 4
&& i < 19 && j >= 4 && j < 19) {
a[i - 4][j + 4] = q;

hei = 2;
}
if (a[i + 1][j - 1] == 0 && hei == 0 && i >= 4
&& i < 19 && j >= 4 && j < 19) {
a[i + 1][j - 1] = q;
hei = 2;
}
}

}
}
}
ko(1, 1, 4);
for (int i = 0; i < 23; i++) {// 防四个一行
for (int j = 0; j < 23; j++) {
if (a[i][j] == p && a[i][j + 1] == p && a[i][j + 2] == p
&& a[i][j + 3] == p) {
if (i >= 4 && j >= 4 && i < 19 && j < 19) {
if (a[i][j - 1] == 0 && hei == 0 && i >= 4 && i < 19
&& j >= 4 && j < 19) {
a[i][j - 1] = q;
hei = 2;
}
if (hei == 0 && a[i][j + 4] == 0 && i >= 4 && i < 19
&& j >= 4 && j < 19) {
a[i][j + 4] = q;
hei = 2;
}
}
}
}
}
for (int i = 0; i < 23; i++) {// 防4个一列
for (int j = 0; j < 23; j++) {
if (i >= 4 && j >= 4 && i < 19 && j < 19)
if (a[i][j] == p && a[i + 1][j] == p && a[i + 2][j] == p
&& a[i + 3][j] == p) {
if (a[i + 4][j] == 0 && hei == 0 && i >= 4 && i < 19
&& j >= 4 && j < 19) {
a[i + 4][j] = q;
hei = 2;
}
if (a[i - 1][j] == 0 && hei == 0 && i >= 4 && i < 19
&& j >= 4 && j < 19) {
a[i - 1][j] = q;
hei = 2;
}
}
}
}
for (int i = 0; i < 23; i++) {// 防4个右斜
for (int j = 0; j < 23; j++) {
if (i < 19 && j < 19 && i >= 4 && j >= 4) {
if (a[i][j] == p && a[i + 1][j + 1] == p
&& a[i + 2][j + 2] == p && a[i + 3][j + 3] == p) {
if (a[i + 4][j + 4] == 0 && hei == 0 && i >= 4
&& i < 19 && j >= 4 && j < 19) {
a[i + 4][j + 4] = q;
hei = 2;
}
if (a[i - 1][j - 1] == 0 && hei == 0 && i >= 4
&& i < 19 && j >= 4 && j < 19) {
a[i - 1][j - 1] = q;
hei = 2;
}
}
}
}
}

for (int i = 4; i < 23; i++) {// 防四个左斜
for (int j = 4; j < 23; j++) {
if (i >= 4 && j >= 4 && i < 19 && j < 19) {
if (a[i][j] == p && a[i - 1][j + 1] == p
&& a[i - 2][j + 2] == p && a[i - 3][j + 3] == p) {
if (a[i - 4][i + 4] == 0 && hei == 0) {
a[i - 4][i + 4] = 1;
hei = 2;

}

if (a[i + 1][i - 1] == 0 && hei == 0) {
a[i + 1][i - 1] = 1;
hei = 2;
}
}
}
}
}


System.out.println(hei);
ko(2, 1, 4);
// ko(1, 1, 3);
// ko(2, 1, 3);
for (int i = 0; i < 23; i++) {// 功三个右斜
for (int j = 0; j < 23; j++) {
if (i >= 4 && j >= 4 && i < 19 && j < 19) {
if (a[i + 1][j + 1] == q && a[i + 2][j + 2] == q) {
if (a[i + 4][j + 4] == q && hei == 0
&& a[i + 3][j + 3] == 0) {
a[i + 3][j + 3] = q;
hei = 2;
}
if (a[i - 2][j - 2] == q && hei == 0
&& a[i - 1][j - 1] == 0) {
a[i - 1][j - 1] = q;
hei = 2;
}
}

}

}
}
for (int i = 0; i < 23; i++) {// 功三个yilie
for (int j = 0; j < 23; j++) {


if (i >= 4 && j >= 4 && i < 19 && j < 19) {
if (a[i][j] == q && a[i + 1][j] == q) {
if (a[i + 3][j] == q && hei == 0 && a[i + 2][j] == 0) {
a[i + 2][j] = q;
hei = 2;
}
if (a[i - 2][j] == q && hei == 0 && a[i - 1][j] == 0) {
a[i - 1][j] = q;
hei = 2;
}
}

}

}
}
for (int i = 0; i < 23; i++) {// 功三个右斜
for (int j = 0; j < 23; j++) {
if (i >= 4 && j >= 4 && i < 19 && j < 19) {
if (a[i][j] == q && a[i - 1][j + 2] == q) {
if (a[i - 3][j + 3] == q && hei == 0
&& a[i - 2][j + 2] == 0) {
a[i - 2][j + 2] = q;
hei = 2;
}
if (a[i + 2][j - 2] == q && hei == 0
&& a[i + 1][j - 1] == 0) {
a[i + 1][j - 1] = q;
hei = 2;
}
}

}

}
}

for (int i = 0; i < 23; i++) {// 功三个一行
for (int j = 0; j < 23; j++) {
if (i >= 4 && j >= 4 && i < 19 && j < 19)
if (a[i][j + 1] == q && a[i][j + 2] == q
&& a[i][j + 3] == q) {
if (a[i][j] == 0 && hei == 0 && i >= 4 && i < 19
&& j >= 4 && j < 19) {
a[i][j] = q;
hei = 2;
}
if (a[i][j + 4] == 0 && hei == 0 && i >= 4 && i < 19
&& j >= 4 && j < 19) {
a[i][j + 4] = q;
hei = 2;
}
}
}

}
for (int i = 0; i < 23; i++) {// 功 三个右斜
for (int j = 0; j < 23; j++) {
if (i >= 4 && j >= 4 && i < 19 && j < 19) {
if (a[i + 1][j + 1] == q && a[i + 2][j + 2] == q
&& a[i + 3][j + 3] == q) {
if (a[i + 4][j + 4] == 0 && hei == 0 && i >= 4
&& i < 19 && j >= 4 && j < 19) {
a[i + 4][j + 4] = q;
hei = 2;
}
if (a[i][j] == 0 && hei == 0 && i >= 4 && i < 19
&& j >= 4 && j < 19) {
a[i][j] = q;
hei = 2;
}
}

}
}
}
for (int i = 0; i < 23; i++) {// 功三个一咧
for (int j = 0; j < 23; j++) {
if (i >= 4 && j >= 4 && i < 19 && j < 19)
if (a[i + 1][j] == q && a[i + 2][j] == q
&& a[i + 3][j] == q) {
if (a[i][j] == 0 && hei == 0 && i >= 4 && i < 19
&& j >= 4 && j < 19) {
a[i][j] = q;
hei = 2;
}
if (a[i + 3][j] == 0 && hei == 0 && i >= 4 && i < 19
&& j >= 4 && j < 19) {
a[i + 3][j] = q;
hei = 2;
}
}
}

}

for (int i = 0; i < 23; i++) {// 功 三个左斜
for (int j = 0; j < 23; j++) {
if (i >= 4 && j >= 4 && i < 19 && j < 19)
if (a[i - 1][j + 1] == q && a[i - 2][j + 2] == q
&& a[i - 3][j + 3] == q) {
if (a[i][j] == 0 && a[i - 4][j + 4] == 0 && hei == 0
&& i >= 4 && i < 19 && j >= 4 && j < 19) {
a[i][j] = q;
hei = 2;
}
}
}

}

for (int i = 0; i < 23; i++) {// 防三个一行
for (int j = 0; j < 23; j++) {
if (i >= 4 && j >= 4 && i < 19 && j < 19)
if (a[i][j + 1] == p && a[i][j + 2] == p

&& a[i][j + 3] == p) {
if (a[i][j] == 0 && a[i][j + 4] == 0 && hei == 0
&& i >= 4 && i < 19 && j >= 4 && j < 19) {
if (a[i][j] == 0) {
a[i][j] = q;
hei = 2;
}
if (hei == 0) {
a[i + 4][j + 4] = q;
hei = 2;
}
}

}
}
}
for (int i = 0; i < 23; i++) {// 防三个一行
for (int j = 0; j < 23; j++) {
if (i >= 4 && j >= 4 && i < 19 && j < 19)
if (a[i][j + 1] == p && a[i][j + 2] == p
&& a[i][j + 4] == p) {
if (a[i][j + 3] == 0 && hei == 0 && i >= 4 && i < 19
&& j >= 4 && j < 19) {
a[i][j + 3] = q;
hei = 2;
}
if (a[i][j - 2] == p && a[i][j - 1] == 0 && hei == 0) {
a[i][j - 1] = q;
hei = 2;
}
}
}

}
for (int i = 0; i < 23; i++) {// 防三个右斜
for (int j = 0; j < 23; j++) {
if (i >= 4 && j >= 4 && i < 19 && j < 19) {
if (a[i + 1][j + 1] == p && a[i + 2][j + 2] == p
&& a[i + 3][j + 3] == p) {
if (a[i + 4][j + 4] == 0 && a[i][j] == 0 && hei == 0
&& i >= 4 && i < 19 && j >= 4 && j < 19) {
a[i + 4][j + 4] = q;
hei = 2;

}

}

}
}
}
for (int i = 0; i < 23; i++) {// 防三个右斜
for (int j = 0; j < 23; j++) {
if (i >= 4 && j >= 4 && i < 19 && j < 19) {
if (a[i + 1][j + 1] == p && a[i + 2][j + 2] == p) {
if (a[i + 4][j + 4] == p && hei == 0
&& a[i + 3][j + 3] == 0) {
a[i + 3][j + 3] = q;
hei = 2;
}
if (a[i - 2][j - 2] == p && hei == 0
&& a[i - 1][j - 1] == 0) {
a[i - 1][j - 1] = q;
hei = 2;
}
}

}

}
}

for (int i = 0; i < 23; i++) {// 防三个一咧
for (int j = 0; j < 23; j++) {
if (i >= 4 && j >= 4 && i < 19 && j < 19)
if (a[i + 1][j] == p && a[i + 2][j] == p
&& a[i + 3][j] == p) {
if (a[i][j] == 0 && a[i + 4][j] == 0 && hei == 0
&& i >= 4 && i < 19 && j >= 4 && j < 19) {
a[i][j] = q;
hei = 2;
if (hei == 0) {
a[i + 4][j] = q;
hei = 2;
}

}

}
}

}

for (int i = 0; i < 23; i++) {// 防三个yilie
for (int j = 0; j < 23; j++) {
if (i >= 4 && j >= 4 && i < 19 && j < 19) {
if (a[i][j] == p && a[i + 1][j] == p) {
if (a[i + 3][j] == p && hei == 0 && a[i + 2][j] == 0) {
a[i + 2][j] = q;
hei = 2;
}
if (a[i - 2][j] == p && hei == 0 && a[i - 1][j] == 0) {
a[i - 1][j - 1] = q;
hei = 2;
}
}

}

}
}
for (int i = 0; i < 23; i++) {// fang三个右斜
for (int j = 0; j < 23; j++) {
if (i >= 4 && j >= 4 && i < 19 && j < 19)
if (a[i - 1][j + 1] == p && a[i - 2][j + 2] == p
&& a[i - 3][j + 3] == p) {
if (a[i][j] == 0 && hei == 0 && a[i - 4][j + 4] == 0
&& i >= 4 && i < 19 && j >= 4 && j < 19) {

a[i][j] = q;
hei = 2;

}

}
}

}

for (int i = 0; i < 23; i++) {// 防三个右斜
for (int j = 0; j < 23; j++) {
if (i >= 4 && j >= 4 && i < 19 && j < 19) {
if (a[i][j] == p && a[i - 1][j + 2] == p) {
if (a[i - 3][j + 3] == p && hei == 0
&& a[i - 2][j + 2] == 0) {
a[i - 2][j + 2] = q;
hei = 2;
}
if (a[i + 2][j - 2] == p && hei == 0
&& a[i + 1][j - 1] == 0) {
a[i + 1][j - 1] = q;
hei = 2;
}
}

}

}
}
for (int i = 4; i < 19; i++) {// 放人
for (int j = 4; j < 19; j++) {
int xp = 0;
if (i > 2 && i < 19 && j > 2 && j < 19) {
if (a[i - 1][j] == q && a[i - 2][j] == q) {
xp++;
}
if (a[i][j - 1] == q && a[i][j - 2] == q) {
xp++;
}
if (a[i + 1][j] == q && a[i + 2][j] == q) {
xp++;
}
if (a[i][j + 1] == q && a[i][j + 2] == q) {
xp++;
}
if (a[i - 1][j - 1] == q && a[i - 2][j - 2] == q) {
xp++;
}
if (a[i + 1][j + 1] == q && a[i + 2][j + 2] == q) {
xp++;
}
if (a[i + 1][j - 1] == q && a[i + 2][j - 2] == q) {
xp++;
}
if (a[i - 1][j + 1] == q && a[i - 2][j + 2] == q) {
xp++;
}
if (xp >= 2 && hei == 0 && a[i][j] == 0) {
a[i][j] = q;
hei = 2;
}
}
}
}
for (int i = 4; i < 19; i++) {// 防人
for (int j = 4; j < 19; j++) {
int xp = 0;
if (i > 2 && i < 19 && j > 2 && j < 19) {
if (a[i - 1][j] == p && a[i - 2][j] == p) {
xp++;
}
if (a[i][j - 1] == p && a[i][j - 2] == p) {
xp++;
}
if (a[i + 1][j] == p && a[i + 2][j] == p) {
xp++;
}
if (a[i][j + 1] == p && a[i][j + 2] == p) {
xp++;
}
if (a[i - 1][j - 1] == p && a[i - 2][j - 2] == p) {
xp++;
}
if (a[i + 1][j + 1] == p && a[i + 2][j + 2] == p) {
xp++;
}
if (a[i + 1][j - 1] == p && a[i + 2][j - 2] == p) {
xp++;
}
if (a[i - 1][j + 1] == p && a[i - 2][j + 2] == p) {
xp++;
}
if (xp >= 2 && hei == 0 && a[i][j] == 0) {
a[i][j] = q;
hei = 2;
}
}
}
}
for (int i = 0; i < 23; i++) {// 中间有空的
for (int j = 0; j < 23; j++) {
if (i > 4 && i < 19 && j > 4 && j < 19) {
if (a[i - 1][j - 1] == p && a[i + 1][j + 1] == p
&& hei == 0 && a[i][j] == 0 && i >= 4 && i < 19
&& j >= 4 && j < 19) {
a[i][j] = q;
hei = 2;
}
}
}
}
for (int i = 0; i < 23; i++) {// 中间有空的
for (int j = 0; j < 23; j++) {
if (i >= 4 && j >= 4 && i < 19 && j < 19) {
if (a[i - 1][j] == p && a[i + 1][j] == p && hei == 0
&& a[i][j] == 0 && i >= 4 && i < 19 && j >= 4
&& j < 19) {
a[i][j] = q;
hei = 2;
}
}
}
}

for (int i = 0; i < 23; i++) {// 中间有空的
for (int j = 0

; j < 23; j++) {
if (i >= 4 && j >= 4 && i < 19 && j < 19) {
if (a[i][j - 1] == p && a[i][j + 1] == p && hei == 0
&& a[i][j] == 0 && i >= 4 && i < 19 && j >= 4
&& j < 19) {
a[i][j] = q;
hei = 2;
}
}
}
}
for (int i = 0; i < 23; i++) {// 中间有空的
for (int j = 0; j < 23; j++) {
if (i >= 4 && i < 19 && j >= 4 && j < 19) {
if (a[i - 1][j + 1] == p && a[i + 1][j - 1] == p
&& hei == 0 && a[i][j] == 0 && i >= 4 && i < 19
&& j >= 4 && j < 19) {
a[i][j] = q;
hei = 2;
}
}
}
}

for (int i = 0; i < 23; i++) {// 防止某种情况,说不清楚。
for (int j = 0; j < 23; j++) {
if (i >= 4 && j >= 4 && i < 19 && j < 19) {
if (a[i][j + 1] == 1 && a[i][j + 2] == 1) {
if (a[i][j] == 0
&& (a[i - 1][j - 1] == 1 || a[i - 1][j] == 1
|| a[i - 1][j + 1] == 1
|| a[i][j + 1] == 1
|| a[i + 1][j - 1] == 1
|| a[i + 1][j] == 1 || a[i + 1][j + 1] == 1)
&& hei == 0 && i >= 4 && i < 19 && j >= 4
&& j < 19) {
a[i][j] = 1;
hei = 2;
}
if (a[i][j + 3] == 0
&& (a[i - 1][j + 2] == 1
|| a[i - 1][j + 3] == 1
|| a[i - 1][j + 4] == 1
|| a[i][j + 4] == 1
|| a[i + 1][j + 2] == 1
|| a[i + 1][j + 3] == 1 || a[i + 1][j + 4] == 1)
&& hei == 0 && i >= 4 && i < 19 && j >= 4
&& j < 19) {
a[i][j + 3] = 1;
hei = 2;
}
}
}
}
}
for (int i = 0; i < 23; i++) {
for (int j = 0; j < 23; j++) {
if (i >= 4 && j >= 4 && i < 19 && j < 19) {
if (a[i + 1][j] == 1 && a[i + 2][j] == 1) {
if (a[i + 3][j] == 0
&& (a[i + 2][j - 1] == 0 || a[i + 2][j] == 1
|| a[i + 2][j + 1] == 1
|| a[i + 3][j + 1] == 1
|| a[i + 4][j - 1] == 1
|| a[i + 4][j] == 0 || a[i + 4][j + 1] == 1)
&& hei == 0 && i >= 4 && i < 19 && j >= 4
&& j < 19) {
a[i][j + 3] = 1;
hei = 2;
}
if (a[i][j] == 0
&& (a[i - 1][j - 1] == 1 || a[i - 1][j] == 1
|| a[i - 1][j + 1] == 1
|| a[i][j + 1] == 1
|| a[i + 1][j - 1] == 1
|| a[i + 1][j] == 1 || a[i + 1][j + 1] == 1)
&& hei == 0 && i >= 4 && i < 19 && j >= 4
&& j < 19) {
a[i][j] = 1;
hei = 2;
}
}
}
}
}
for (int i = 0; i < 23; i++) {
for (int j = 0; j < 23; j++) {
if (i >= 4 && j >= 4 && i < 19 && j < 19) {
if (a[i + 1][j + 1] == 1 && a[i + 2][j + 2] == 1) {
if (a[i + 2][j + 2] == 0
&& (a[i + 1][j + 1] == 1
|| a[i + 1][j + 2] == 1
|| a[i + 1][j + 3] == 1
|| a[i + 2][j + 3] == 1
|| a[i + 3][j + 1] == 1
|| a[i + 3][j + 2] == 1 || a[i + 3][j + 3] == 1)
&& hei == 0 && i >= 4 && i < 19 && j >= 4
&& j < 1

9) {
a[i + 2][j + 2] = 1;
hei = 2;
}
if (a[i][j] == 0
&& (a[i - 1][j - 1] == 1 || a[i - 1][j] == 1
|| a[i - 1][j + 1] == 1
|| a[i][j + 1] == 1
|| a[i + 1][j - 1] == 1
|| a[i + 1][j] == 1 || a[i + 1][j + 1] == 1)
&& hei == 0 && i >= 4 && i < 19 && j >= 4
&& j < 19) {
a[i][j] = 1;
hei = 2;
}
}
}
}
}

for (int i = 0; i < 23; i++) {
for (int j = 0; j < 23; j++) {
if (i >= 4 && j >= 4 && i < 19 && j < 19) {
if (a[i - 1][j + 1] == 1 && a[i - 2][j + 2] == 1) {
if (a[i - 3][j + 3] == 0
&& hei == 0
&& i >= 4
&& i < 19
&& j >= 4
&& j < 19
&& (a[i - 4][j + 2] == 1
|| a[i - 4][j + 2] == 1
|| a[i - 4][j + 4] == 1
|| a[i - 3][j + 4] == 1
|| a[i - 2][j + 2] == 1
|| a[i - 2][j + 3] == 1 || a[i - 2][j + 4] == 1)) {
a[i - 3][j + 3] = 1;
hei = 2;
}
if (a[i][j] == 0
&& hei == 0
&& i >= 4
&& i < 19
&& j >= 4
&& j < 19
&& (a[i - 1][j - 1] == 1 || a[i - 1][j] == 1
|| a[i - 1][j + 1] == 1
|| a[i][j + 1] == 1
|| a[i + 1][j - 1] == 1
|| a[i + 1][j] == 1 || a[i + 1][j + 1] == 1)) {
a[i][j] = 1;
hei = 2;
}
}

}
}
}
// //
for (int i = 0; i < 23; i++) {// 防止某种情况,说不清楚。
for (int j = 0; j < 23; j++) {
if (i >= 4 && j >= 4 && i < 19 && j < 19) {
if (a[i][j + 1] == 2 && a[i][j + 2] == 2) {
if (a[i][j] == 0
&& (a[i - 1][j - 1] != 0 || a[i - 1][j] != 0
|| a[i - 1][j + 1] != 0
|| a[i][j + 1] != 0
|| a[i + 1][j - 1] != 0
|| a[i + 1][j] != 0 || a[i + 1][j + 1] != 0)
&& hei == 0 && i >= 4 && i < 19 && j >= 4
&& j < 19) {
a[i][j] = 1;
hei = 2;
}
if (a[i][j + 3] == 0
&& (a[i - 1][j + 2] != 0
|| a[i - 1][j + 3] != 0
|| a[i - 1][j + 4] != 0
|| a[i][j + 4] != 0
|| a[i + 1][j + 2] != 0
|| a[i + 1][j + 3] != 0 || a[i + 1][j + 4] != 0)
&& hei == 0 && i >= 4 && i < 19 && j >= 4
&& j < 19) {
a[i][j + 3] = 1;
hei = 2;
}
}
}
}
}
for (int i = 0; i < 23; i++) {
for (int j = 0; j < 23; j++) {
if (i >= 4 && j >= 4 && i < 19 && j < 19) {
if (a[i + 1][j] == 2 && a[i + 2][j] == 2) {
if (a[i + 3][j] == 0
&& (a[i + 2][j - 1] != 0 || a[i + 2][j] != 0
|| a[i + 2][j + 1] != 0
|| a[i + 3][j + 1] != 0
|| a[i + 4][j - 1] != 0
|| a[i + 4][j] != 0 || a[i + 4][j + 1] != 0)
&& hei == 0 && i >= 4 && i < 19 && j >= 4
&& j < 19) {
a[i][j + 3] = 1;
hei = 2;
}
if (a[i][j] == 0
&&

(a[i - 1][j - 1] != 0 || a[i - 1][j] != 0
|| a[i - 1][j + 1] != 0
|| a[i][j + 1] != 0
|| a[i + 1][j - 1] != 0
|| a[i + 1][j] != 0 || a[i + 1][j + 1] != 0)
&& hei == 0 && i >= 4 && i < 19 && j >= 4
&& j < 19) {
a[i][j] = 1;
hei = 2;
}
}
}
}
}
for (int i = 0; i < 23; i++) {
for (int j = 0; j < 23; j++) {
if (i >= 4 && j >= 4 && i < 19 && j < 19) {
if (a[i + 1][j + 1] == 2 && a[i + 2][j + 2] == 2) {
if (a[i + 3][j + 3] == 0
&& (a[i + 2][j + 2] != 0
|| a[i + 2][j + 3] != 0
|| a[i + 2][j + 4] != 0
|| a[i + 3][j + 4] != 0
|| a[i + 4][j + 2] != 0
|| a[i + 4][j + 3] != 0 || a[i + 4][j + 4] != 0)
&& hei == 0 && i >= 4 && i < 19 && j >= 4
&& j < 19) {
a[i + 3][j + 3] = 1;
hei = 2;
}
if (a[i][j] == 0
&& (a[i - 1][j - 1] != 0 || a[i - 1][j] != 0
|| a[i - 1][j + 1] != 0
|| a[i][j + 1] != 0
|| a[i + 1][j - 1] != 0
|| a[i + 1][j] != 0 || a[i + 1][j + 1] != 0)
&& hei == 0 && i >= 4 && i < 19 && j >= 4
&& j < 19) {
a[i][j] = 1;
hei = 2;
}
}
}
}
}

for (int i = 0; i < 23; i++) {
for (int j = 0; j < 23; j++) {
if (i >= 4 && j >= 4 && i < 19 && j < 19) {
if (a[i - 1][j + 1] == 2 && a[i - 2][j + 2] == 2) {
if (a[i - 3][j + 3] == 0
&& hei == 0
&& i >= 4
&& i < 19
&& j >= 4
&& j < 19
&& (a[i - 4][j + 2] != 0
|| a[i - 4][j + 2] != 0
|| a[i - 4][j + 4] != 0
|| a[i - 3][j + 4] != 0
|| a[i - 2][j + 2] != 0
|| a[i - 2][j + 3] != 0 || a[i - 2][j + 4] != 0)) {
a[i - 3][j + 3] = 1;
hei = 2;
}
if (a[i][j] == 0
&& hei == 0
&& i >= 4
&& i < 19
&& j >= 4
&& j < 19
&& (a[i - 1][j - 1] != 0 || a[i - 1][j] != 0
|| a[i - 1][j + 1] != 0
|| a[i][j + 1] != 0
|| a[i + 1][j - 1] != 0
|| a[i + 1][j] != 0 || a[i + 1][j + 1] != 0)) {
a[i][j] = 1;
hei = 2;
}
}

}
}
}
for (int i = 0; i < 23; i++) {// g2个子
for (int j = 0; j < 23; j++) {
if (i < 19 && i >= 4 && j < 19 && j >= 4) {
if (a[i][j] == q && a[i + 1][j - 1] == q) {
if (a[i - 1][j + 1] == 0 && hei == 0 && i >= 4
&& i < 19 && j >= 4 && j < 19) {
a[i - 1][j + 1] = q;
hei = 2;
}
if (a[i + 2][j - 2] == 0 && hei == 0 && i >= 4
&& i < 19 && j >= 4 && j < 19) {
a[i + 2][j - 2] = q;
hei = 2;
}
}
}
}
}
for (int i = 0; i < 23; i++) {// g2个子
for (int j = 0; j < 23; j++) {
if (i < 19 && i >= 4 && j < 19 && j >= 4) {
if (a[i][j] == q && a[i][j + 1] == q && i >= 4 && i <

19
&& j >= 4 && j < 19) {
if (a[i][j - 1] == 0 && hei == 0) {
a[i][j - 1] = q;
hei = 2;

}
if (a[i][j + 2] == 0 && hei == 0 && i >= 4 && i < 19
&& j >= 4 && j < 19) {
a[i][j + 2] = q;

hei = 2;
}
}
}
}
}
for (int i = 0; i < 23; i++) {// g2个子
for (int j = 0; j < 23; j++) {
if (i < 19 && i >= 4 && j < 19 && j >= 4) {
if (a[i][j] == q && a[i + 1][j + 1] == q && i >= 4
&& i < 19 && j >= 4 && j < 19) {
if (a[i - 1][j - 1] == 0 && hei == 0) {
a[i - 1][j - 1] = q;
hei = 2;
}
if (a[i + 2][j + 2] == 0 && hei == 0 && i >= 4
&& i < 19 && j >= 4 && j < 19) {
a[i + 2][j + 2] = q;
hei = 2;
}
}
}
}
}
for (int i = 0; i < 23; i++) {// g2个子
for (int j = 0; j < 23; j++) {
if (i < 19 && i >= 4 && j < 19 && j >= 4) {
if (a[i][j] == p && a[i - 1][j + 1] == p && i >= 4
&& i < 19 && j >= 4 && j < 19) {
if (a[i + 1][j - 1] == 0 && hei == 0) {
a[i + 1][j - 1] = q;
hei = 2;
}
if (a[i - 2][j + 2] == 0 && hei == 0 && i >= 4
&& i < 19 && j >= 4 && j < 19) {
a[i - 2][j + 2] = q;
hei = 2;
}
}
}
}
}
for (int i = 0; i < 23; i++) {// g 2个子
for (int j = 0; j < 23; j++) {
if (i < 19 && i >= 1 && j < 19 && j >= 1) {
if (a[i][j] == q && a[i + 1][j] == q && i >= 1 && i < 19
&& j >= 1 && j < 19) {
if ((a[i - 1][j] == 0 || a[i + 2][j] == 0) && hei == 0) {
a[i - 1][j] = q;
hei = 2;
System.out.println(222);
if (hei == 0 && a[i + 2][j] == 0) {
a[i + 2][j] = q;
hei = 2;
}
}
}
}
}
}
// 防御人2子的
for (int i = 0; i < 23; i++) {
for (int j = 0; j < 23; j++) {
if (i >= 4 && j >= 4 && i < 19 && j < 19)
if (a[i][j] == p && a[i + 1][j - 1] == p
&& a[i + 2][j - 2] == p) {
if (a[i - 1][j + 1] == 0 && hei == 0 && i >= 4
&& i < 19 && j >= 4 && j < 19) {
a[i - 1][j + 1] = q;
hei = 2;
}
if ((a[i + 3][j - 3] == p && a[i + 4][j - 4] == 0 && hei == 0)
&& i >= 4 && i < 19 && j >= 4 && j < 19) {
a[i + 4][j - 4] = q;
hei = 2;
}
}
}
}
for (int i = 0; i < 23; i++) {
for (int j = 0; j < 23; j++) {
if (i >= 4 && j >= 4 && i < 19 && j < 19) {
if (a[i][j] == p && a[i][j + 1] == p) {
if (a[i][j + 2] == 0 && hei == 0 && i >= 4 && i < 19
&& j >= 4 && j < 19) {
a[i][j + 2] = q;
hei = 2;
}
if (a[i][j - 1] == 0 && hei == 0 && i >= 4 && i < 19
&& j >= 4 && j < 19) {
a[i][j - 1] = q;
hei = 2;
}

}
}
}
}
for (int i = 0; i < 23; i++) {
for (int j = 0; j < 23; j++) {
if (i >= 4 && j >= 4 && i < 19 && j < 19) {
if (a[i][j] == p &&

相关文档
最新文档