• 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

5 x 5 Tic Tac Toe

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I made a 5 x 5 tic tac toe but I can't seem to figure out how to make the bottom right - top left diagonal work. I've figured everything else out but that bit is giving me trouble, here is the code


The second line is for the bottom right-top left diagonal.
 
Master Rancher
Posts: 4806
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Zain Toor wrote:I made a 5 x 5 tic tac toe but I can't seem to figure out how to make the bottom right - top left diagonal work. I've figured everything else out but that bit is giving me trouble, here is the code


The second line is for the bottom right-top left diagonal.


Ignoring the second line, which seems incomplete... I guess there must be three different values possible at each location, right?  One value for "this space is empty", one for "this space has an X", and one for "this space has an O".  Maybe those values are 0, 1, 2, or maybe 1, 2, 3, or maybe ' ', 'X', 'O'.

Anyway, when you write check[0][0]==check[1][1], that verifies that position (0,0) has the same thing as position (1, 1).  And the rest of the line verifies that (2,2), (3,3) and (4,4) also have the same thing.  So either you have 5 X marks, or 5 O marks... or 5 empty spaces.  How can you add something to test whether one of those positions is empty or not?
 
Zain Toor
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh yeah, so I have all the code for everything else, and it works great, and the double arrays are set up like this

(0,0)(0,1)(0,2)(0,3)(0,4)
(1,0)(1,1)(1,2)(1,3)(1,3)
(2,0)(2,1)(2,2)(2,3)(2,4)
(3,0)(3,1)(3,2)(3,3)(3,4)
(4,0)(4,1)(4,2)(4,3)(4,4)
 
Mike Simmons
Master Rancher
Posts: 4806
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, but I don't see answers to my questions there.

What data type is the check array?  Clearly it's an array of arrays... of what?  A char?  An int?  How do you represent "this space is empty", "this space has an X", or "this space has an O"?
 
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A way of doing it by counting each blank, x, and o in the diagonal. If any of the x or o count is 5 then that is who won.
 
Zain Toor
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks but I figured it out on my own, it was a stupid mistake
 
Marshal
Posts: 79177
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is unnecessary to count all the rows and diagonals. It is only necessary to count the row diagonal (if any) and column containing the most recent move.
 
I'm full of tinier men! And a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic