Created
March 2, 2015 07:42
-
-
Save jdetle/0bfa181d4b20e1061d61 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public WinDrawLose returnmoveoutcome(ToeBoard tictac, char playerchar){ | |
//System.out.println("Remember to input your move in terms of the row and column that you want to place your character in."); | |
WinDrawLose outcome = new WinDrawLose(); | |
char nextplayerchar = 'O'; | |
if(playerchar == 'O'){ | |
nextplayerchar = 'X'; | |
} | |
int[] move = new int[2]; | |
int row = 0; | |
int column = 0; | |
ArrayList<int[]> playable = new ArrayList<int[]>(); | |
playable = playablemoves(tictac); | |
int movesleft = playable.size(); | |
ToeBoard[] boardsaftermove = new ToeBoard[movesleft]; | |
//System.out.println("\n"+playable.size()); | |
for(int i=0; i<movesleft; i++){ | |
//System.out.println(i); | |
boardsaftermove[i] = new ToeBoard(tictac); | |
//boardsaftermove[i].printBoard(); | |
move = playable.get(i); | |
row = move[0]; | |
column = move[1]; | |
boardsaftermove[i].updateboard(move, playerchar); | |
//System.out.print(row+" "+column); | |
if(boardsaftermove[i].checkwin(playerchar, move) == true){ | |
outcome.move= move; | |
outcome.win = true; | |
return outcome; | |
} | |
else{ | |
WinDrawLose nextoutcome = new WinDrawLose(); | |
//System.out.println("\n"+i+"\n"); | |
nextoutcome = returnmoveoutcome(boardsaftermove[i], nextplayerchar); | |
//System.out.println("moverow "+nextoutcome.move[0]); | |
//System.out.println("movecolumn "+nextoutcome.move[0]); | |
if(nextoutcome.win == true){ | |
outcome.lose = true; | |
outcome.move = move; | |
} | |
else{ | |
outcome.draw = true; | |
outcome.move = move; | |
return outcome; | |
} | |
} | |
//This state is only returned when the only possible choice is a losing move. Not possible for a game of tic tac toe started at zero moves. | |
} | |
return outcome; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment