Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Someone -H-E-L-P--M-E- with tic tac toe games
Author Message
SilverSprite

Posted: Fri Jul 25, 2003 1:01 am   Post subject: Someone -H-E-L-P--M-E- with tic tac toe games

I'm writing a tic tac toe program to calculate the total number of various games assuming that x starts first. Anyways my program must double count somewhere.. someone help???? I'll post both turing and c++ sources.

UNCOMMENT THE TURING COMMENTS TO SEE THE PROGRAM AT WORK
 code: var count := 0 var grid : array 1 .. 3, 1 .. 3 of int for i : 1 .. 3     for j : 1 .. 3         grid (i, j) := 0     end for end for procedure drawboard     for i : 1 .. 3         for j : 1 .. 3             put grid (j, i), " " ..         end for         put ""     end for     put count end drawboard function check : boolean     for j : 1 .. 2         for i : 1 .. 3             if grid (1, i) = j and grid (2, i) = j and grid (3, i) = j then                 result true             end if             if grid (i, 1) = j and grid (i, 2) = j and grid (i, 3) = j then                 result true             end if         end for         if grid (1, 1) = j and grid (2, 2) = j and grid (3, 3) = j then             result true         elsif grid (3, 1) = j and grid (2, 2) = j and grid (1, 3) = j then             result true         end if     end for     result false end check function checkall : boolean     for i : 1 .. 3         for j : 1 .. 3             if grid (j, i) = 0 then                 result false             end if         end for     end for     result true end checkall procedure recurse (k : int)     put k     delay (100)     if check then         count += 1         return     end if     for i : 1 .. 3         for j : 1 .. 3             if grid (j, i) = 0 then                 if (k mod 2 = 1) then                     grid (j, i) := 2                     %drawboard                     %delay (750)                     %cls                     recurse (k + 1)                     grid (j, i) := 0                     %drawboard                     %delay (750)                     %cls                 else                     grid (j, i) := 1                     %drawboard                     %delay (750)                     %cls                     recurse (k + 1)                     grid (j, i) := 0                     %drawboard                     % delay (750)                     % cls                 end if             end if         end for     end for     if checkall then         count += 1     end if end recurse for i : 1 .. 3     for j : 1 .. 3         grid (j, i) := 1         %drawboard         %delay (750)         %cls         recurse (1)         grid (j, i) := 0         %drawboard         %delay (750)         %cls     end for end for put count

I HAVENT GOTTEN CLEARSCREEN OR DELAY TO WORK ON C++ SO DONT UNCOMMENT
 code: #include using namespace std; int count, grid[3][3]; /*void drawboard() {     for (int i=0; i<3; i++)     {         for (int k=0; j<3; j++)             cout << grid [j][i]<< " ";         clrscr();            }     cout << count << endl; } void clrscr() {   HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);   COORD coord = {0, 0};   DWORD count;     CONSOLE_SCREEN_BUFFER_INFO csbi;   GetConsoleScreenBufferInfo(hStdOut, &csbi);     FillConsoleOutputCharacter(hStdOut, ' ', csbi.dwSize.X * csbi.dwSize.Y, coord, &count);     SetConsoleCursorPosition(hStdOut, coord); }*/ bool check() {     for (int i=0; i<3; i++)     {         for (int j=0; j<3; j++)             if (grid[0][i] == j && grid[1][i] == j && grid[2][i] == j) return true;             else if (grid[i][0] == j && grid[i][1] == j && grid[i][2] == j) return true;         if (grid[0][0]==j && grid[1][1]==j && grid[2][2]==j) return true;         if (grid[2][0]==j && grid[1][1]==j && grid[0][2]==j) return true;     }     return false; } bool checkall() {     for (int i=0; i<3; i++)         for (int j=0; j<3; j++)             if (grid[j][i] == 0) return false;     return true; } void recurse(int k) {     if (check()){count++; return;}     for (int i=0; i<3; i++)         for (int j=0; j<3; j++)             if (k%2 == 1)             {                 grid[j][i]=2;                 //            drawboard(); //            sleep(600); //            clrscr();                                 recurse(k+1);                 grid[j][i]=0;                 //            drawboard(); //            sleep(600); //            clrscr();             }             else             {                 grid[j][i]=1;                 //            drawboard(); //            sleep(600); //            clrscr();                                 recurse(k+1);                 grid[j][i]=0;                 //            drawboard(); //            sleep(600); //            clrscr();             }     if (checkall()) count++; } int main() {     for (int i=0; i<3; i++)         for (int j=0; j<3; j++)         {             grid[j][i]=1;              //          drawboard(); //            sleep(600); //            clrscr();                          recurse(1);             grid[j][i]=0;              //          drawboard(); //            sleep(600); //            clrscr();         }     cout << count << endl; }

JayLo

Posted: Fri Jul 25, 2003 1:08 am   Post subject: (No subject)

there.

TTT.t
Description:
Filename:  TTT.t
Filesize:  5.52 KB

Dan

Posted: Fri Jul 25, 2003 1:17 am   Post subject: (No subject)

moved to turing help

also thats not a great title for the post

lucky i am not asok b/c he whould have blown this post to hell and back agean
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
SilverSprite

Posted: Fri Jul 25, 2003 1:47 am   Post subject: (No subject)

Jay Lo wrote:
there.

Didn't you read my post?? I don't have trouble with making tic tac toe. I'm having trouble couting EVERY SINGLE POSSIBLE CAASE.
JayLo

Posted: Fri Jul 25, 2003 12:02 pm   Post subject: (No subject)

SilverSprite

Posted: Fri Jul 25, 2003 1:46 pm   Post subject: (No subject)

np btw dont i get bits for my excellent example of a depth frsit search (or the other one i always confuse them.)
JayLo

Posted: Sun Jul 27, 2003 10:47 pm   Post subject: (No subject)

if you want 30 bits from me, just ask... geez... lol.
krishon

Posted: Tue Jul 29, 2003 8:12 pm   Post subject: (No subject)

lol, wut ppl do for bits these days

SilverSprite

Posted: Wed Jul 30, 2003 10:56 am   Post subject: (No subject)

i'm jk.. whoa
bugzpodder

Posted: Thu Jul 31, 2003 12:25 pm   Post subject: (No subject)

i sent you my proggie back a few weeks ago. do you want bits that badly? here, i gave you all my bits, plus darkness still owns me 500 so i'll give it to you once i get it
rizzix

Posted: Fri Aug 01, 2003 12:00 am   Post subject: (No subject)

500!!! even mods don't give that much!
SilverSprite

Posted: Fri Aug 01, 2003 1:12 pm   Post subject: (No subject)

yeah ok bugz.. heres all of mine too.. +1429
AsianSensation

Posted: Fri Aug 01, 2003 6:48 pm   Post subject: (No subject)

btw, speaking of giving bits...

I still own SilverSprite and Bugz bits for math questions

so here is 5 for SilverSprite
+5 bits to SilverSprite

and 40 for Bugz
+40 bits to Bugz
SilverSprite

Posted: Fri Aug 01, 2003 8:51 pm   Post subject: (No subject)

why do you owe me bits?
AsianSensation

Posted: Sat Aug 02, 2003 9:00 am   Post subject: (No subject)

check the "Math Solution" thread, I own you guys bits, I don't even know why, but oh well...
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 15 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: