对不起之前的代码。这是计算机的代码。如果用户选择坐标 N1,那么它会随机选择另一个可以阻挡该位置的坐标。这是我试图用java制作的井字游戏的一部分。我无法在坐标上打印 x。如果你能帮助我,我将不胜感激。只是简单的ai。
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(" --------------------");
}
}