【发布时间】:2015-10-31 00:48:20
【问题描述】:
致力于构建井字游戏。我正在尝试使用尽可能简单的方法。我目前正在努力让 CPU 随机选择阵列中的一个点来放置“O”。我该怎么做呢?这是我目前所拥有的。
import java.util.Scanner;
import java.util.Random;
public class Player
{
String player = "X";
String cpu = "O";
//private int[][] theBoard= new int [3][3] ;
private String[][] theBoard= {{" "," "," "}, {" "," "," "}, {" ", " "," "}};;
Random cpuInput = new Random();
private Board board1;
public static Scanner scan = new Scanner(System.in);
public Player(Board board, String inBoard )
{
theBoard = theBoard;
}
public void computerMove()
{
String spacing = " ";
for (int i = 0; i < theBoard.length; i++)
{
for (int j = 0; j < theBoard[i].length; j++)
{
//int random = cpuInput.nextInt(theBoard[i][j]);
theBoard[2][2] = (cpu); //STUCK HERE!
}
}
}
【问题讨论】: