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.

Recommended Answers

All 4 Replies

Start resolve from 1d tic tac toe

1D is Point

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. :)

Member Avatar for ztini

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.