one way might be to set up another array of 'lines'
e.g. say you have a button array button[9] so they are indexed 0 to 8
JButton[][] lines = {{button[0],button[1],button[2]},
then
3,4,5 (row)
6,7,8 (row)
0,3,6 (column)
1,4,7 (column)
2,5,8 (column)
0,4,8 (diagonal)
2,4,6 (diagonal)

and check each 'line' to see if they're all the same i.e. winner

Andres John wrote:this is just part of the ttt program that i need to know how i could check the four main diagonals line for the winner.

Four? Must be a new version of TTT I haven't heard of. And if this is for a 3D TTT game, there will be a lot more than 4, because there will be 2 for each plane, plus 4 "3D" diagonals (and you should probably come up with a name for them to differentiate them from a "normal" diagonal).

My suggestion: Write methods that return you rows, columns, and diagonals for each plane and "apex to apex" lines as arrays of your TTT cells. That way, you can program the game for any size of board.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Artlicles by Winston can be found here

Andres John
Ranch Hand

Joined: Jun 07, 2012
Posts: 34

posted

0

Winston Gutkowski wrote:

Andres John wrote:this is just part of the ttt program that i need to know how i could check the four main diagonals line for the winner.

Four? Must be a new version of TTT I haven't heard of. And if this is for a 3D TTT game, there will be a lot more than 4, because there will be 2 for each plane, plus 4 "3D" diagonals (and you should probably come up with a name for them to differentiate them from a "normal" diagonal).

My suggestion: Write methods that return you rows, columns, and diagonals for each plane and "apex to apex" lines as arrays of your TTT cells. That way, you can program the game for any size of board.

Winston

i already did that which is this
using For Loop

i just need to find all the possible diagonal. I think i'm missing few of them.

Andres John wrote:i already did that which is this
...
using For Loop

which isn't creating methods.

i just need to find all the possible diagonal. I think i'm missing few of them.

Which is probably because you haven't broken the problem down enough. Monolithic code like that, especially when it involves multi-layered loops, can become incrediby difficult to follow, so my suggestion would be something like this:
1. You know how to find a winning line on a 2D board. Well, in an NxNxN cube there are 3N "planes" or "sections" - N for each of the x, y and z dimensions - each of which is the equivalent of a 2D TTT board. Write a method that returns you a single plane of NxN squares (the x dimension planes are dirt simple; the y and z ones only marginally more difficult).
2. Run the method for each plane in your cube, and check what it returns just like you would an ordinary TTT board.
3. The only "lines" left to process after that are your 4 "apex-to-apex" diagonals.

HIH

Winston

Andres John
Ranch Hand

Joined: Jun 07, 2012
Posts: 34

posted

0

Winston Gutkowski wrote:

Andres John wrote:i already did that which is this
...
using For Loop

which isn't creating methods.

i just need to find all the possible diagonal. I think i'm missing few of them.

Which is probably because you haven't broken the problem down enough. Monolithic code like that, especially when it involves multi-layered loops, can become incrediby difficult to follow, so my suggestion would be something like this:
1. You know how to find a winning line on a 2D board. Well, in an NxNxN cube there are 3N "planes" or "sections" - N for each of the x, y and z dimensions - each of which is the equivalent of a 2D TTT board. Write a method that returns you a single plane of NxN squares (the x dimension planes are dirt simple; the y and z ones only marginally more difficult).
2. Run the method for each plane in your cube, and check what it returns just like you would an ordinary TTT board.
3. The only "lines" left to process after that are your 4 "apex-to-apex" diagonals.