Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Tic then Tac the Toe
Author Message
QuantumPhysics

Posted: Tue May 22, 2012 4:02 pm   Post subject: Tic then Tac the Toe

Just something i cooked up on my free time.
Have fun, and play safe

ticTHENtacTHEtoe.cpp
Description:
 Note: I used a precompiled header in MSVS 2010 Ultimate Edition

Filename:  ticTHENtacTHEtoe.cpp
Filesize:  12.59 KB

QuantumPhysics

Posted: Tue May 22, 2012 10:25 pm   Post subject: RE:Tic then Tac the Toe

Looking for feedback
Zren

Posted: Wed May 23, 2012 2:14 am   Post subject: RE:Tic then Tac the Toe

 c++: enum bool { false, true};

Waaaaaa-

I don't know much about C++, but there's no way you should need to define a boolean data type. No way...

 c++: {    int *ptr;    if(player==human1)       ptr=p1;            // point to appropriate array    else       ptr=p2;    // check for 3 in a Row or 3 in a Column    if( (ptr[0] && ptr[1] && ptr[2]) ||  // horizontal        (ptr[3] && ptr[4] && ptr[5]) ||        (ptr[6] && ptr[7] && ptr[8]) ||        (ptr[0] && ptr[3] && ptr[6]) ||  // vertical        (ptr[1] && ptr[4] && ptr[7]) ||        (ptr[2] && ptr[5] && ptr[8]) ||        (ptr[0] && ptr[4] && ptr[8]) ||  // diagonal        (ptr[2] && ptr[4] && ptr[6]) )    {       setcolor(BLACK);       setlinestyle(SOLID_LINE,1,THICK_WIDTH);       if(ptr[0] && ptr[1] && ptr[2])          line(midx[0],midy[0],midx[2],midy[2]);       if(ptr[3] && ptr[4] && ptr[5])          line(midx[3],midy[3],midx[5],midy[5]);       if(ptr[6] && ptr[7] && ptr[8])          line(midx[6],midy[6],midx[8],midy[8]);       if(ptr[0] && ptr[3] && ptr[6])          line(midx[0],midy[0],midx[6],midy[6]);       if(ptr[1] && ptr[4] && ptr[7])          line(midx[1],midy[1],midx[7],midy[7]);       if(ptr[2] && ptr[5] && ptr[8])          line(midx[2],midy[2],midx[8],midy[8]);       if(ptr[0] && ptr[4] && ptr[8])          line(midx[0],midy[0],midx[8],midy[8]);       if(ptr[2] && ptr[4] && ptr[6])          line(midx[2],midy[2],midx[6],midy[6]);

All right. Now imagine TicTacToe is a 7x7 board. What would you do differently? Having only 8 win conditions is useful for grasping all end scenarios, but manually checking each grid cell isn't very practical.

Don't bother coding it, just brainstorm.
Raknarg

Posted: Wed May 23, 2012 8:28 am   Post subject: RE:Tic then Tac the Toe

@Zren Actually, I don't think C++ has built in booleans. Generally it seems that the programs just use 1 as true and 0 as false, which is basically the same thing.
y4y

Posted: Wed May 23, 2012 8:13 pm   Post subject: RE:Tic then Tac the Toe

what are you talking about bool is a type in c++.
md

Posted: Wed May 23, 2012 8:33 pm   Post subject: Re: RE:Tic then Tac the Toe

Raknarg @ 2012-05-23, 8:28 am wrote:
@Zren Actually, I don't think C++ has built in booleans. Generally it seems that the programs just use 1 as true and 0 as false, which is basically the same thing.

C++ does indeed have a boolean type - it's called "boolean" and it has the values "true" and "false" which are equivalent to 1 and 0 respectively. C didn't have a boolean type for a long time but newer standards do define Boolean and there is a long standing bool.h header which does all the defines for you as well.
Raknarg

Posted: Thu May 24, 2012 8:33 am   Post subject: RE:Tic then Tac the Toe

Oh, ok then. I just remember hearing that somewhere, I jsut assumed.
QuantumPhysics

Posted: Fri May 25, 2012 8:17 am   Post subject: RE:Tic then Tac the Toe

Okay guys, haha but what do you think of my program? pretty good? Im thinking of posting my chess vs ai game in a Windows console, it has 3-D visuals and many more options. But im just finishing it up.

QuantumPhysics

Posted: Fri May 25, 2012 8:18 am   Post subject: RE:Tic then Tac the Toe

Okay guys, haha but what do you think of my program? pretty good? Im thinking of posting my chess vs ai game in a Windows console, it has 3-D visuals and many more options. But im just finishing it up.
bl0ckeduser

Posted: Fri May 25, 2012 8:34 am   Post subject: Re: RE:Tic then Tac the Toe

Raknarg @ 2012-05-23, 8:28 am wrote:
C didn't have a boolean type for a long time but newer standards do define Boolean and there is a long standing bool.h header which does all the defines for you as well.

As was mentioned earlier by Raknarg, I think the usual convention in C is to use a nonzero integer (often 1) for true and zero for false. This is how conditional expressions get evaluated, but there are other uses as well.
mirhagk

Posted: Fri May 25, 2012 10:15 am   Post subject: RE:Tic then Tac the Toe

As for the discussion of whether C++ has booleans, the answer is depends. Some versions have boolean types defined, others don't Actually the enum for true and false is a decent way of doing it, many people use macros for the same thing.

As Zren said you should really code how to solve the solution vs just putting everything in an if statement.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 11 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: