+ 2
What's a more efficient way to test for a winner in 3D tic tac toe? (Java)
I have a method named "testIfWinner" and it takes String [] [] [] board, String player, int count, String placeHolderString. Currently I have my method to test every variable in each element of the array. "if(!board[0][0][0].equals(placeHolderString) & & board[0][0][0].equals(board[0][0][1]) & & board[0][0][1].equals([0][0][2]))" and so on for every combination. So basically I was wondering if anyone knew of a faster solution so I can reduce all these lines of code to a few. Any help is appreciated!
3 Answers
+ 10
The best you can do is use the minimax algorithm for searching. I'd also suggest using loops for better consistency.
Check the algorithm here:
https://www.ntu.edu.sg/home/ehchua/programming/java/JavaGame_TicTacToe_AI.html
To effectively test a winner,
https://stackoverflow.com/questions/1056316/algorithm-for-determining-tic-tac-toe-game-over
+ 10
@David: Most probably. You can check the stackoverflow link in my previous answer :)
+ 2
So would a for loop help to search and compare these better?