Thread: C++ & Tic Tac Toe

  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,318
    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
    28,413
    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
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #20
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    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.

  6. #21
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    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"

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, 07: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