Forum    News    Downloads    Saved Games


Tic-Tac-Toe

<<

roxfox64

User avatar

Brew Guru
Brew Guru

Posts: 2287

Joined: June 12 2007

Location: Smyrna, GA Current Status: Its true... I am a fur.

Thanks given: 0

Thanks received: 2 times

Post Tue Mar 16, 2010 8:16 pm

Tic-Tac-Toe

A group of IRC buddies and I have been working on getting every possible scenario in a game of Tic-Tac-Toe.

We're at a point where we need a way to read through the grid and determine who won the game first.

Now, a quick bit of info:
    Pre-requisites:
    :!: You must know C,C++,C#, Java, or any C based language(At the very least)
    :!: You must know how to work with two dimensional Arrays.
    :!: You must know how to properly make a function.
    :!: You must have a compiler available to use.

    _~*:!: [End of list] :!: *~_

That being said, now we'll get into the technical side of things:
    We are using an Ennead system to go about this as there are only 9 possible moves in tic-tac-toe.
    The idea behind the Ennead system is to create a sort of Pseudo-Ennead(An Ennead instead of a decimal. We convert a decimal to an Ennead, obviously.
    Each digit of the Ennead represents a different move at a different position. A sample Ennead would be 123456789 which would look like this on the Move_Grid[][] array:
    123
    456
    789

    And, on the Player_Array[][]:
    010
    101
    010

    On the Player_Array, Player 1 is stored as 0, and player 2 is stored as 1.
    The idea behind the Ennead's is that each integer represents the order of it's move.
    So, the '1' you see at Move_Grid[0][0] is move number 1, and the '5' you see at Move_Grid[1][1] is move number 5.

    Now, the spot we're at requires for the move grid to be read, and for it's ordering to be noted, so we can see who the true winner is.

    A good example of how it currently fails to do this is on Run #5993(Oh yeah, I forgot to tell you guys. In Tic-Tac-Toe there are 9!(362880) possible games. We're bruteforcing them):

    123465987 Run #5993 Result: Loss [As seen in the LOG.txt generated by the program.]

    123465987 is a win actually.

    123 010
    465 110
    987 010

    The three 0's occurred first, however, due to the fact that loss detection happens after Win detection this is the result.


With all that out of the way...
Here's the code :D
http://roxfox64.pastebin.com/fWPauNjb
5.00M33-6
Image
Image Veemon
Image
Image
<<

roxfox64

User avatar

Brew Guru
Brew Guru

Posts: 2287

Joined: June 12 2007

Location: Smyrna, GA Current Status: Its true... I am a fur.

Thanks given: 0

Thanks received: 2 times

Post Thu Mar 18, 2010 1:46 am

Aaaaaaaaaaaaaaaaand, I've finished.
The last bit I had to get by myself.

http://roxfox64.pastebin.com/c8n4fcqE
Total Project results(Source,GAMES,LOG)
Special Thanks to AC-Snowleopard, and Chesamo 8)
5.00M33-6
Image
Image Veemon
Image
Image
<<

Mailas

Post Thu Mar 18, 2010 11:27 am

This is pretty nice.
One suggestion, you could have used a loop when doing this:
if(
Player_Grid[0][0] == 1 && Player_Grid[0][1] == 1 && Player_Grid[0][2] == 1 ||
Player_Grid[1][0] == 1 && Player_Grid[1][1] == 1 && Player_Grid[1][2] == 1 ||
Player_Grid[2][0] == 1 && Player_Grid[2][1] == 1 && Player_Grid[2][2] == 1 ||


Player_Grid[0][0] == 1 && Player_Grid[1][0] == 1 && Player_Grid[2][0] == 1 ||
Player_Grid[0][1] == 1 && Player_Grid[1][1] == 1 && Player_Grid[2][1] == 1 ||
Player_Grid[0][2] == 1 && Player_Grid[1][2] == 1 && Player_Grid[2][2] == 1 ||


Player_Grid[0][0] == 1 && Player_Grid[1][1] == 1 && Player_Grid[2][2] == 1 ||
Player_Grid[2][0] == 1 && Player_Grid[1][1] == 1 && Player_Grid[0][2] == 1
)
{
return 1;
}
else if(
// [-]
Player_Grid[0][0] == 2 && Player_Grid[0][1] == 2 && Player_Grid[0][2] == 2 ||
Player_Grid[1][0] == 2 && Player_Grid[1][1] == 2 && Player_Grid[1][2] == 2 ||
Player_Grid[2][0] == 2 && Player_Grid[2][1] == 2 && Player_Grid[2][2] == 2 ||

// [|]
Player_Grid[0][0] == 2 && Player_Grid[1][0] == 2 && Player_Grid[2][0] == 2 ||
Player_Grid[0][1] == 2 && Player_Grid[1][1] == 2 && Player_Grid[2][1] == 2 ||
Player_Grid[0][2] == 2 && Player_Grid[1][2] == 2 && Player_Grid[2][2] == 2 ||

// [X]
Player_Grid[0][0] == 2 && Player_Grid[1][1] == 2 && Player_Grid[2][2] == 2 ||
Player_Grid[2][0] == 2 && Player_Grid[1][1] == 2 && Player_Grid[0][2] == 2
)



Good job nonetheless.
<<

roxfox64

User avatar

Brew Guru
Brew Guru

Posts: 2287

Joined: June 12 2007

Location: Smyrna, GA Current Status: Its true... I am a fur.

Thanks given: 0

Thanks received: 2 times

Post Thu Mar 18, 2010 3:38 pm

Oh, yeah.
Eh, I never really thought of anything right there.
Like, now that you've said something about I probably could have had a linear array within a for loop that stored the value of each member of Player_Grid.

Actually, I started to do that in this post. It can't be achieved normally because of diagonals
Normally, I would start with the classic double nested for loop:

    int get_Winner()
    {
    for(int i = 0;i<3;i++)
    {
    int SUM;
    for(int j = 0;j<3;j++)
    {
    SUM+= Player_Grid[i][j];
    }
    if(SUM == 6)
    {
    return 2;
    }
    else if(SUM == 3)
    {
    return 1;
    }
    }
    return 0;
    }


I can't really check diagonals seamlessly in there.
5.00M33-6
Image
Image Veemon
Image
Image
<<

roxfox64

User avatar

Brew Guru
Brew Guru

Posts: 2287

Joined: June 12 2007

Location: Smyrna, GA Current Status: Its true... I am a fur.

Thanks given: 0

Thanks received: 2 times

Post Thu Mar 18, 2010 5:31 pm

Aaaaaaaaaaand, this is the FINAL post...
The results.

http://www.btinternet.com/~se16/hgb/tictactoe.htm

Henry George Bottomley states above that there are only 26,830 possible Tic-Tac-Toe games.
I, in fact, have proof that he's wrong.

If you run my app you will see every move from the first possible, to the last possible.

There are 725,760 possible Tic-Tc-Toe games.
WOOOOOOOOOOOOOOOT~!
5.00M33-6
Image
Image Veemon
Image
Image
<<

Mailas

Post Mon Apr 19, 2010 9:29 pm

Compiled it, works really well.
Nice job.

Return to Developers & Programming

Who is online

Users browsing this forum: No registered users and 1 guest

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for blacklist.org.