• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Check winner diagonal

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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. this what i got
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Andres John
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

HIH
Winston


k will try to figure this out
 
reply
    Bookmark Topic Watch Topic
  • New Topic