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

Username:   Password: 
 RegisterRegister   
 Someone -H-E-L-P--M-E- with tic tac toe games
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
SilverSprite




PostPosted: 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 <iostream>
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;
}
Sponsor
Sponsor
Sponsor
sponsor
JayLo




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

there.


TTT.t
 Description:

Download
 Filename:  TTT.t
 Filesize:  5.52 KB
 Downloaded:  379 Time(s)

Dan




PostPosted: 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 Twisted Evil
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
SilverSprite




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




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

sorry. my bad. Embarassed
SilverSprite




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




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

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




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

lol, wut ppl do for bits these days
Sponsor
Sponsor
Sponsor
sponsor
SilverSprite




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

i'm jk.. whoa
bugzpodder




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




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

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




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

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




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




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

why do you owe me bits?
AsianSensation




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

Page 1 of 1  [ 15 Posts ]
Jump to:   


Style:  
Search: