간단한 오목
15152 단어 오목
1 import java.util.Scanner;
2
3 //
4 public class wuziqi {
5
6 //
7 private static char[][] board=new char[16][16];
8 //
9 private static int cnt;
10 // 1,2
11 private static char[] qizi={'#','@'};
12 //
13 private static int[] dx={-1,0,-1,-1,1,1,0,1};
14 private static int[] dy={0,-1,-1,1,-1,1,1,0};
15
16 //
17 private static int CheckInput(int x,int y){
18
19 if(board[x][y]!='+')
20 return 0;
21 if(x<1||x>15||y<1||y>15)
22 return 0;
23 return 1;
24 }
25
26 //
27 private static int Check(int x,int y){
28 if(x>15||x<1||y>15||y<1)
29 return 0;
30 return 1;
31 }
32 // , ,
33 private static int CheckAns(int num,int x,int y){
34 if(cnt==15*15)
35 return 1;
36 //
37 for(int i=0;i<4;i++){
38 int sum=1;
39 int xx=x+dx[i];
40 int yy=y+dy[i];
41 while(board[xx][yy]==qizi[num]&&Check(xx,yy)==1){
42 sum++;
43 xx=xx+dx[i];
44 yy=yy+dy[i];
45 }
46 xx=x+dx[7-i];
47 yy=y+dy[7-i];
48 while(board[xx][yy]==qizi[num]&&Check(xx,yy)==1){
49 sum++;
50 xx=xx+dx[7-i];
51 yy=yy+dy[7-i];
52 }
53 if(sum>=5)
54 return 1;
55 }
56 return 0;
57 }
58
59 //
60 private static void Init(){
61 cnt=0;
62 for(int i=1;i<=15;i++)
63 for(int j=1;j<=15;j++)
64 board[i][j]='+';
65 }
66
67 //
68 private static void Print(){
69 int i,j;
70 for(i=1;i<=15;i++){
71 for(j=1;j<=15;j++){
72
73 System.out.print(board[i][j]);
74 }
75 System.out.println();
76 }
77 }
78
79 public static int run(){
80
81 int x,y;
82 Init();
83 // , 0
84 int num=0;
85 while(true){
86 Print();
87 System.out.print(num+1+" , x y : ");
88 Scanner sc =new Scanner(System.in);
89 while(true){
90 x=sc.nextInt();
91 y=sc.nextInt();
92 if(CheckInput(x,y)==1)
93 break;
94 System.out.print(" , : ");
95 }
96 board[x][y]=qizi[num];
97 if(CheckAns(num,x,y)==1){
98 return num+1;
99 }
100 num=1-num;
101 }
102 }
103
104 public static void main(String[] args){
105
106 System.out.println(" lkl !");
107 int ans=run();
108 System.out.println(" "+ans+" ");
109 }
110 }