0

I am writing a game of three dimensional tic-tac-toe. I need to have a method that can look at the board, and determine if a player has won. Your requirement is that this method is passed an array that represents the board, and returns an answer that can be used to determine the state of the game.

I got one of these questions during my java test. I was wondering what this answer was.

5
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by ztini
0

1D is a line. 0D is a Point. If you want to do this OO style, you could make a case for starting for 0D Tic Tac Toe - "Tic" you'd call it, I guess - and working out from there.

I bet you he won't do it that way, though. :)

0

So basically you receive a 3d array like int[][][]? lol

Yeah, your algorithm could potentially scan each horizontal 3x3 row for a win, then scan each vertical 3x3 column, then each row/column diagonal. Of course, that is not very efficient, some points will get checked multiple times.

I'd imagine an efficient solution would model Prim's algorithm or a simple Breadth-First Search algorithm. Really, I think if you're queuing a start point (e.g. a player places an an 'X' or an 'O') into an algorithm that recursively queues adjacent points for solutions...you're on the right track.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.