我已经完成了90%的Tic TAC脚趾游戏,并且拥有一种电脑AI形式,但是效果并不好。我正在寻找一种新的更容易的电脑来移动游戏板的地方。Tic tac脚趾电脑选择现货?
我需要这台电脑移动选择来选择一个点,但也要确保点是免费提供的,并且在该点没有'X'。关于如何让电脑选择一个点的任何想法?
/* I have 3 other methods drawing the board, and determining a tie, a loss, and a win not shown here for simplicity*/
public static void main(String[] args) {
//Variable declaration
Scanner kbReader = new Scanner(System.in);
char[][] Board = new char[3][3];
String MenuInput;
int BoardOutput;
int UserSpotChoice;
int ComputerSpotChoice = 0;
int UserTurn = 0;
int Winner = 0;
Board[0][0] = '-';
Board[0][1] = '-';
Board[0][2] = '-';
Board[1][0] = '-';
Board[1][1] = '-';
Board[1][2] = '-';
Board[2][0] = '-';
Board[2][1] = '-';
Board[2][2] = '-';
//Welcome
System.out.println("Welcome to Alex Montague's Tic Tac Toe game!");
System.out.println("");
System.out.println("If you wish to play, type 'Play'");
System.out.println("If you wish to read the instructions, type 'Instructions'");
System.out.println("If you wish to exit, type 'Exit'");
MenuInput = kbReader.next();
do {
if (MenuInput.equals("Play") || MenuInput.equals("play")) {
while (!GameOver) {
System.out.println("\f");
System.out.println(" Tic Tac Toe");
BoardOutput = DrawBoard(Board);
System.out.println(" 1 2 3");
System.out.println(" 4 5 6");
System.out.println(" 7 8 9");
System.out.println("Please enter the number you would like to move your spot to");
UserSpotChoice = kbReader.nextInt();
if (UserSpotChoice == 1) Board[0][0] = 'X';
if (UserSpotChoice == 2) Board[0][1] = 'X';
if (UserSpotChoice == 3) Board[0][2] = 'X';
if (UserSpotChoice == 4) Board[1][0] = 'X';
if (UserSpotChoice == 5) Board[1][1] = 'X';
if (UserSpotChoice == 6) Board[1][2] = 'X';
if (UserSpotChoice == 7) Board[2][0] = 'X';
if (UserSpotChoice == 8) Board[2][1] = 'X';
if (UserSpotChoice == 9) Board[2][2] = 'X';
do {
ComputerSpotChoice = (int)(Math.random() * 9) + 1;
}
while (Board[(ComputerSpotChoice - 1)/3][(ComputerSpotChoice - 1) % 3] != '-'); //HERE IS THE OLD COMPUTER SPOT GENERATION THAT DID NOT WORK
if (ComputerSpotChoice == 1) Board[0][0] = 'O';
if (ComputerSpotChoice == 2) Board[0][1] = 'O';
if (ComputerSpotChoice == 3) Board[0][2] = 'O';
if (ComputerSpotChoice == 4) Board[1][0] = 'O';
if (ComputerSpotChoice == 5) Board[1][1] = 'O';
if (ComputerSpotChoice == 6) Board[1][2] = 'O';
if (ComputerSpotChoice == 7) Board[2][0] = 'O';
if (ComputerSpotChoice == 8) Board[2][1] = 'O';
if (ComputerSpotChoice == 9) Board[2][2] = 'O';
Winner(Board);
Loser(Board);
Tie(Board);
} //While loop
//if (GameOver) System.exit (0) ;
} //If play
else if (MenuInput.equals("Instructions") || MenuInput.equals("instructions")) {
System.out.println("\f");
System.out.println("You will be playing the game of Tic Tac Toe against the computer.");
System.out.println("The object of this game is to get three of your own x's or o's in a line.");
System.out.println("You take turns placing the x's and o's and whoever gets three in a row first wins.");
System.out.println("Good Luck!");
System.out.println("");
System.out.println("If you wish to play, type 'Play'");
System.out.println("If you wish to exit, type 'Exit'");
MenuInput = kbReader.next();
} else if (MenuInput.equals("Exit") || MenuInput.equals("exit")) {
System.out.println("Thank you for using Alex Montague's Tic Tac Toe game!");
System.exit(0);
} else {
System.out.println("Sorry, that is not a valid choice.");
System.out.println("If you wish to play, type 'Play'");
System.out.println("If you wish to read the instructions, type 'Instructions'");
System.out.println("If you wish to exit, type 'Exit'");
MenuInput = kbReader.next();
}
} //do while
while (!MenuInput.equals("Instructions") || !MenuInput.equals("instructions") || !MenuInput.equals("Play") || !MenuInput.equals("play") || !MenuInput.equals("Exit") || !MenuInput.equals("exit"));
为双方球员的最佳策略可以在[百科]中找到(http://en.wikipedia.org/wiki/Tic-tac-toe)。 – Stefan
这个问题似乎无关紧要,因为它涉及游戏开发,因此更适合http://gamedev.stackexchange.com/。 – TLama
这与您[最近发布的其他问题](http://stackoverflow.com/q/27539015/3097506)有何不同? –