shadow427
11-12-2005, 10:27 PM
I have a fully functional tic tac toe game I created. However, its very easy to beat... to easy. Right now its set up so that a human player can play against the computer, and the human always wins because as the program is now, the computer just picks the last open space. Not very fun at all. I have three classes, the application class where i have the human player and computer player instantiation and declaring the winner, a player class which has a loop so that the human and computer takes turns, and then a tic tac toe class which is where im stuck. ill post the code, any help would be greatly appreciated. I want it so that the computer player either always beats the human player or the two players always tie.
//provide logic for computer to choose its next move
public int[] chooseMove(char symbol){
int[] move = new int[2];
int blockRow = 0;
int blockCol = 0;
int progressRow = 0;
int progressCol = 0;
//check across the rows (this is where im stuck)
for (int i=0; i < ticTacToe.length; i++){
for (int j=0; j < ticTacToe[i].length; j++){
if (ticTacToe[i][j] == '_'){
progressRow = i;
progressCol = j;
} else if (ticTacToe[i][j] != symbol){ //my opponent has it
} else { //it is mine, see if space around it
}
}
}
if(blockRow != 0 || blockCol != 0){
move[0] = blockRow;
move[1] = blockCol;
} else {
move[0] = progressRow;
move[1] = progressCol;
}
return move;
}
//provide logic for computer to choose its next move
public int[] chooseMove(char symbol){
int[] move = new int[2];
int blockRow = 0;
int blockCol = 0;
int progressRow = 0;
int progressCol = 0;
//check across the rows (this is where im stuck)
for (int i=0; i < ticTacToe.length; i++){
for (int j=0; j < ticTacToe[i].length; j++){
if (ticTacToe[i][j] == '_'){
progressRow = i;
progressCol = j;
} else if (ticTacToe[i][j] != symbol){ //my opponent has it
} else { //it is mine, see if space around it
}
}
}
if(blockRow != 0 || blockCol != 0){
move[0] = blockRow;
move[1] = blockCol;
} else {
move[0] = progressRow;
move[1] = progressCol;
}
return move;
}