-2
对不起之前的代码。这是电脑的代码。如果用户选择坐标N1,则它随机选择另一个可以阻挡该位置的坐标。这是我尝试在java中制作的一个tic tac toe游戏的一部分。我无法让x在坐标上打印。如果你能帮助我,我将不胜感激。 只是简单的AI。程序在随机选择后会在主板上显示o
here is the code:
import java.util.*;
public class compbrain{
public static void main(String [] args)
{
char x = 'X';
char [][] ar = new char [3][3];
System.out.println("Player X: Enter the coordinate where you want an X placed. Example 1 0");
int choice1 = input.nextInt();
int choice2 = input.nextInt();
char N = ar[choice1][choice2] = x;
char N1 = ar[0][0];
char N2 = ar[0][1];
char N3 = ar[0][2];
char N4 = ar[1][0];
char N5 = ar[1][1];
char N6 = ar[1][2];
char N7 = ar[2][0];
char N8 = ar[2][1];
char N9 = ar[2][2];
int r = (int)(Math.random() * 4);
char [] arrayN1 = {N4,N7,N2,N3,N5,N9};
if(N == N1){arrayN1[r] = x;}
System.out.println(" 0 1 2 ");
System.out.println(" --------------------");
System.out.println("0 | "+N1+" | "+N4+" | "+N7+" |");
System.out.println(" --------------------");
System.out.println("1 | "+N2+" | "+N5+" | "+N8+" |");
System.out.println(" --------------------");
System.out.println("2 | "+N3+" | "+N6+" | "+N9+" |");
System.out.println(" --------------------");
}
}
什么坐标?你用arrayN1和r做什么? – Sibbo
arrayN1包含二维数组N4,N7,N2,N3,N5,N9。随机产生一个数字。 r选择arrayN1的索引。我希望arrayN1在板上的任何坐标上显示一个o,这个坐标是arrayN1的索引。 – user1008914
什么'麻烦'?假装我们无法读懂你的思想,也不会坐在电脑前。 –