Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Tic then Tac the Toe
Index -> Programming, C++ -> C++ Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
QuantumPhysics




PostPosted: 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 Razz



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

Download
 Filename:  ticTHENtacTHEtoe.cpp
 Filesize:  12.59 KB
 Downloaded:  388 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
QuantumPhysics




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

Looking for feedback
Zren




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
QuantumPhysics




PostPosted: 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




PostPosted: 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




PostPosted: 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:   
   Index -> Programming, C++ -> C++ Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: