Like Tree1Likes

C++ & Tic Tac Toe

This is a discussion on C++ & Tic Tac Toe within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by iMalc Looks like you missed the diagonal win checks Mozza. The best way to check for wins ...

  1. #16
    C++ Junkie Mozza314's Avatar
    Join Date
    Jan 2011
    Location
    Australia
    Posts
    174
    Quote Originally Posted by iMalc View Post
    Looks like you missed the diagonal win checks Mozza.

    The best way to check for wins in TTT is to define an array of the win positions.
    Code:
    const int wins[][3] = {{0,1,2},{3,4,5},{6,7,8},{0,3,6},{1,4,7},{2,5,8},{0,4,8},{2,4,6}};
    Of course you'd need to use a 1D array for the board, which you'd find produces much shorter code anyway.
    Lookup tables FTW!
    Ah you're right, I did miss them. I would prefer to use vector<vector<char&> >, but it's a shame C++ is averse to using references like that. I suppose vector<vector<tr1::reference_wrapper<char> > > could be used.

  2. #17
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,296
    When the array dimensions are fixed and very small I would not use a vector.
    Last edited by iMalc; 04-01-2011 at 09:13 PM.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  3. #18
    Registered User
    Join Date
    Mar 2011
    Posts
    6

    Thanks all, that is another option

    However, Mozza, we hadn't learned structures or classes at the point this was due, and we hadn't really gone into any depth with vectors. Now, of course, we are done messing with C++ and all of the above and are moving on to Linux.

    Linux looks like it's going to be very very interesting. The professor has us choosing between Wubi, Ubuntu, or Knoppix. What do you think? These OS's are all new to me.

    Thanks again to all who helped.

  4. #19
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,460
    Quote Originally Posted by nysunlass
    The professor has us choosing between Wubi, Ubuntu, or Knoppix. What do you think? These OS's are all new to me.
    Triple boot
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #20
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    Aren't Wubi and Ubuntu the same?...differing only by the bootloader (Wubi uses the windows mbr..and ubuntu uses whatever you want it to)?
    Ubuntu is the best for the the new user...(well you could install it using wubi to avoid problems with partitioning and the resident windows bootloader...but traditionally wubi is slower than a normal install).
    Last edited by manasij7479; 04-08-2011 at 08:43 PM.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  6. #21
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,296
    Knoppix FTW!
    You can boot from CD and don't need to install squat on your hard drive.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. tic tac toe check winner
    By dhardin in forum C++ Programming
    Replies: 15
    Last Post: 12-20-2009, 06:57 PM
  2. Help me with my simple Tic tac toe prog
    By maybnxtseasn in forum C Programming
    Replies: 2
    Last Post: 04-04-2009, 06:25 PM
  3. Tic Tac Toe... so close...
    By SlayerBlade in forum C Programming
    Replies: 14
    Last Post: 10-10-2005, 08:58 PM
  4. Help with Tic Tac Toe game
    By snef73 in forum C++ Programming
    Replies: 1
    Last Post: 04-25-2003, 08:33 AM
  5. tic tac toe game
    By Leeman_s in forum Game Programming
    Replies: 9
    Last Post: 04-24-2002, 03:24 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21