+ 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!

9th Feb 2018, 3:03 AM
David Botsolis
David Botsolis - avatar
3 Antworten
+ 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
9th Feb 2018, 7:21 AM
Dev
Dev - avatar
+ 10
@David: Most probably. You can check the stackoverflow link in my previous answer :)
10th Feb 2018, 6:01 AM
Dev
Dev - avatar
+ 2
So would a for loop help to search and compare these better?
9th Feb 2018, 9:07 PM
David Botsolis
David Botsolis - avatar