import java.util.Scanner;
public class Test{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
final int size = 3;
int [] [] board = new int[size][size] ;
int numofx=0;
int numofo=0;
int result=-1; //-1:没人赢,1:x赢, 0:0赢
int cnt_o=0;
int cnt_x=0;
int count=0;
int i,j;
int ope=0;
for(i=0; i<size; i++){
for(j=0; j<size; j++){
board[i][j]=-1;
}
}
System.out.print("\t 0 \t 1 \t 2 \t\n\n");
for(i=0;i<3;i++){
System.out.print(i+"\t ___\t___\t___\t\n\n");
}
do {
System.out.print("玩家一请输入坐标\n");
i=in.nextInt();
j=in.nextInt();
System.out.print("\n");
System.out.print("\t");
for(int k=0;k<size;k++){
System.out.print(k+" \t");
}
// System.out.print("\t 0 \t 1 \t 2 \t");
System.out.print("\n\n");
System.out.print(" 0 \t");
board[i][j]=1;
ope=0;
for(i=0; i<size;i++){
for(j=0;j<size; j++ )
{
if(board[i][j]==1){
System.out.print("_X_");
ope++;
if(ope%size==0){
if(ope/size==size){
System.out.print("\n\n\n");
}else if(ope/size<size){
System.out.print("\n\n\n"+(ope/size)+"\t");
}
}else{
System.out.print("\t");
}
}else if(board[i][j]==-1){
System.out.print("___");
ope++;
if(ope%size==0){
if(ope/size==size){
System.out.print("\n\n\n");
}else if(ope/size<size){
System.out.print("\n\n\n"+(ope/size)+"\t");
}
}else{
System.out.print("\t");
}
}else if(board[i][j] == 0){
System.out.print("_O_");
ope++;
if(ope%size==0){
if(ope/size==size){
System.out.print("\n\n\n");
}else if(ope/size<size){
System.out.print("\n\n\n"+(ope/size)+"\t");
}
}else{
System.out.print("\t");
}
}
}
}
// System.out.print("board[%d][%d]=%d\n",i,j,board[i][j]);
System.out.print("请玩家二输入坐标\n");
i=in.nextInt();
j=in.nextInt();
count++;
System.out.print("\n");
System.out.print("\t");
for(int k=0;k<size;k++){
System.out.print(k+" \t");
}
// System.out.print("\t 0 \t 1 \t 2 \t");
System.out.print("\n\n");
System.out.print(" 0 \t");
board[i][j]=0;
ope=0;
for(i=0; i<size;i++){
for(j=0;j<size; j++ )
{
if(board[i][j]==1){
System.out.print("_X_");
ope++;
if(ope%size==0){
if(ope/size==size){
System.out.print("\n\n\n");
}else if(ope/size<size){
System.out.print("\n\n\n"+(ope/size)+"\t");
}
}else{
System.out.print("\t");
}
}else if(board[i][j]==-1){
System.out.print("___");
ope++;
if(ope%size==0){
if(ope/size==size){
System.out.print("\n\n\n");
}else if(ope/size<size){
System.out.print("\n\n\n"+(ope/size)+"\t");
}
}else{
System.out.print("\t");
}
}else if(board[i][j] == 0){
System.out.print("_O_");
ope++;
if(ope%size==0){
if(ope/size==size){
System.out.print("\n\n\n");
}else if(ope/size<size){
System.out.print("\n\n\n"+(ope/size)+"\t");
}
}else{
System.out.print("\t");
}
}
}
}
//System.out.print("board[%d][%d]=%d\n",i,j,board[i][j]);
// System.out.print("%d",board[2][2]);
//检查行
for (i=0; i<size ; i++ )
{
numofo=0;
numofx=0;
for(j=0; j<size; j++ ){
if( board[i][j] == 1){
numofx++;
// System.out.print("numofx的值是:%d\n",numofx);
}else if(board[i][j]==0){
numofo++;
// System.out.print("numofo的值是:%d\n",numofo);
}else{
}
}
if(numofo == size){
result = 0;
cnt_o++;
} else if(numofx == size) {
result =1;
cnt_x++;
} else{
result =-1;
}
}
// System.out.print("1.检查的行\n cnt_o值是:%d\ncnt_x值是:%d\n",cnt_o,cnt_x);
//检查列
for(j=0; j<size ; j++){
numofo = numofx = 0;
for(i=0; i<size; i++){
if( board[i][j] == 1){
numofx ++;
}else if(board[i][j]==0) {
numofo ++;
}
}
if(numofo == size){
result = 0;
cnt_o++;
}else if(numofx == size){
result = 1;
cnt_x++;
}
}
// System.out.print("2.检查的列\n cnt_o值是:%d\ncnt_x值是:%d\n",cnt_o,cnt_x);
//正对角线
numofo = numofx = 0;
for(i=0; i<size; i++){
if( board[i][i] == 1){
numofx ++;
}else if(board[i][i]==0) {
numofo ++;
}
}
if( numofo == size){
result = 0;
cnt_o++;
}else if( numofx == size){
result = 1;
cnt_x++;
}
// System.out.print("3.检查的正对角线\n cnt_o值是:%d\n cnt_x值是:%d\n",cnt_o,cnt_x);
//斜对角线
numofo = numofx = 0;
for(i=0; i<size; i++ ){
if( board[i][size-i-1] == 1){
numofx++;
}else if( board[i][size-i-1] == 0){
numofo++;
}
}
if( numofo == size){
result = 0;
cnt_o++;
}else if(numofx == size){
result = 1;
cnt_x++;
}
// System.out.print("4.检查的斜对角线\n cnt_o值是:%d\ncnt_x值是:%d\n",cnt_o,cnt_x);
}while(cnt_o==0 && cnt_x==0 &&count<(size*size-1)/2);
//int count=9;
if(cnt_x==0 && cnt_o==0 && count==(size*size-1)/2){
do {
System.out.print("玩家一请输入坐标\n");
i=in.nextInt();
j=in.nextInt();
System.out.print("\n");
System.out.print("\t");
for(int k=0;k<size;k++){
System.out.print(k+" \t");
}
// System.out.print("\t 0 \t 1 \t 2 \t");
System.out.print("\n\n");
System.out.print(" 0 \t");
board[i][j]=1;
ope=0;
for(i=0; i<size;i++){
for( j=0;j<size; j++ )
{
if(board[i][j]==1){
System.out.print("_X_");
ope++;
if(ope%size==0){
if(ope/size==size){
System.out.print("\n\n\n");
}else if(ope/size<size){
System.out.print("\n\n\n"+(ope/size)+"\t");
}
}else{
System.out.print("\t");
}
}else if(board[i][j]==-1){
System.out.print("___");
ope++;
if(ope%size==0){
if(ope/size==size){
System.out.print("\n\n\n");
}else if(ope/size<size){
System.out.print("\n\n\n"+(ope/size)+"\t");
}
}else{
System.out.print("\t");
}
}else if(board[i][j] == 0){
System.out.print("_O_");
ope++;
if(ope%size==0){
if(ope/size==size){
System.out.print("\n\n\n");
}else if(ope/size<size){
System.out.print("\n\n\n"+(ope/size)+"\t");
}
}else{
System.out.print("\t");
}
}
}
}
//检查行
for (i=0; i<size ; i++ )
{
numofo=0;
numofx=0;
for(j=0; j<size; j++ ){
if( board[i][j] == 1){
numofx++;
// System.out.print("numofx的值是:%d\n",numofx);
}else if(board[i][j]==0){
numofo++;
// System.out.print("numofo的值是:%d\n",numofo);
}else{
}
}
if(numofo == size){
result = 0;
cnt_o++;
} else if(numofx == size) {
result =1;
cnt_x++;
} else{
result =-1;
}
}
// System.out.print("1.检查的行\n cnt_o值是:%d\ncnt_x值是:%d\n",cnt_o,cnt_x);
//检查列
for( j=0; j<size ; j++){
numofo = numofx = 0;
for( i=0; i<size; i++){
if( board[i][j] == 1){
numofx ++;
}else if(board[i][j]==0) {
numofo ++;
}
}
if(numofo == size){
result = 0;
cnt_o++;
}else if(numofx == size){
result = 1;
cnt_x++;
}
}
// System.out.print("2.检查的列\n cnt_o值是:%d\ncnt_x值是:%d\n",cnt_o,cnt_x);
//正对角线
numofo = numofx = 0;
for( i=0; i<size; i++){
if( board[i][i] == 1){
numofx ++;
}else if(board[i][i]==0) {
numofo ++;
}
}
if( numofo == size){
result = 0;
cnt_o++;
}else if( numofx == size){
result = 1;
cnt_x++;
}
// System.out.print("3.检查的正对角线\n cnt_o值是:%d\n cnt_x值是:%d\n",cnt_o,cnt_x);
//斜对角线
numofo = numofx = 0;
for( i=0; i<size; i++ ){
if( board[i][size-i-1] == 1){
numofx++;
}else if( board[i][size-i-1] == 0){
numofo++;
}
}
if( numofo == size){
result = 0;
cnt_o++;
}else if(numofx == size){
result = 1;
cnt_x++;
}
// System.out.print("4.检查的斜对角线\n cnt_o值是:%d\ncnt_x值是:%d\n",cnt_o,cnt_x);
}while(cnt_o==0 && cnt_x==0 &&count<(size*size-1)/2);
}
if(cnt_x==1 && cnt_o==0&& count<=(size*size-1)/2){
System.out.print("恭喜玩家一,你赢啦!\n");
}else if(cnt_o==1 && cnt_x==0){
System.out.print("恭喜玩家二,你赢啦!\n");
}else if(cnt_o==0 &&cnt_x==0 && count==(size*size-1)/2){
System.out.print("恭喜双方打成平局,以和为贵!");
}else if(cnt_o==1 &&cnt_x==1 ){
System.out.print("恭喜你们双赢啦!\n");
Scanner scan=new Scanner(System.in);
String s1=new String();
s1=scan.nextLine();
System.out.print("开个玩笑,其实是 玩家一 赢了!\n");
}
}
}