I really, REALLY need a C programmers help...(Please Help)

This is a discussion on I really, REALLY need a C programmers help...(Please Help) within the C++ Programming forums, part of the General Programming Boards category; Hi from the new guy Well Im in a Computer Programing class in college and I plan on majoring in ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    38

    Unhappy I really, REALLY need a C programmers help...(Please Help)

    Hi from the new guy

    Well Im in a Computer Programing class in college and I plan on majoring in this. but I need some help. We have to do a program in Turbo C and it has to be tic tac toe. The stupid teacher gave us NO examples on how to do this and she just through out the assignment to us. Its simple and she is asking for this:

    Write a C program that plays tic-tac-toe. Use:
    char ttt [3][3]
    to represent the board state. Assume there are two human players and have X go first. Show the game board for each move using X and O for the players. At the end of a game, say who won and ask if the user wants to play again.

    Its due Tues (Oct. 30) and Ive been working on it since Yesterday from 8:00 PM to 2:00 AM. Today its 11:00 PM and Ive been working on it since 5:00 PM. Ive found sites on the net that give everything away for me but I dont want to cheat in college and I really want to get this but Im running out of time. Im really thankful I found this site and I am really desperate and hopeful that someone here can help me.

    Has anyone here done any program like this? Can anyone maybe give a few tips or a bare bones outline.

    Thank you very much and I hope someone can help. Thanks

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    What is your biggest problem? Checking the winners?
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    38

    Unhappy

    My biggest problem is getting started man. This is all I have so far:


    int main()

    {
    printf("Welcome to Tic-Tac-Toe!\n\n");
    printf("Here is the board numbering:\n");
    printf(" 1 | 2 | 3\n");
    printf("---+---+---\n");
    printf(" 4 | 5 | 6\n");
    printf("---+---+---\n");
    printf(" 7 | 8 | 9\n");
    printf("\n");
    printf("First player is X, second player is O.\n");



    }


    I am totally lost and dont know what to do

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    38

    Unhappy

    My biggest problem is getting started man. This is all I have so far:


    int main()

    {
    printf("Welcome to Tic-Tac-Toe!\n\n");
    printf("Here is the board numbering:\n");
    printf(" 1 | 2 | 3\n");
    printf("---+---+---\n");
    printf(" 4 | 5 | 6\n");
    printf("---+---+---\n");
    printf(" 7 | 8 | 9\n");
    printf("\n");
    printf("First player is X, second player is O.\n");



    }


    I am totally lost and dont know what to do

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    First you will need to get the user input (only position as you will know which player is due to have a turn).Place the X or 0 in the array at the right spot. Use the % operator on the 1-9 number ie X player inputs 6 so as zero based 6-1=5 5/3=1, 5%3=2 to give iArray[1][2]=X

    Then check to see if someone has won or tht there are still places to go. I would use 0/1 FALSE/TRUE for each element of the array. Init them to say -1 so you can tell how many left.

    you will need a few for loops like

    Code:
    int     iArray[3][3];
    
    for(i=0;i<3;i++)//for each row
    {
        for(j=0;j<3;j++)//for each column
        {
             iArray[i][j]=-1;//init array
        }
    }
    Last edited by novacain; 10-31-2001 at 06:51 PM.

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    38

    Smile

    Cool, thanks alot man. Im gonna try that out tonight

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    38

    Unhappy

    I cant get it to work or nothing man. This is all I have so far:



    #include <stdio.h>
    #include <ctype.h>

    #define String_Length 80

    #define Squares 9
    typedef char Square_Type;
    typedef Square_Type Board_Type[Squares];
    const Square_Type Empty = ' ';

    const int Infinity = 10; /* Higher value than any score */
    const int Maximum_Moves = Squares; /* Maximum moves in a game */

    int Total_Nodes; /* Nodes searched with minimax */
    int iArray[3][3];



    int main()

    {
    printf("Welcome to Tic-Tac-Toe!\n\n");
    printf("Here is the board numbering:\n");
    printf(" 1 | 2 | 3\n");
    printf("---+---+---\n");
    printf(" 4 | 5 | 6\n");
    printf("---+---+---\n");
    printf(" 7 | 8 | 9\n");
    printf("\n");
    printf("First player is X, second player is O.\n");


    for(i=0;i<3;i++)//for each row
    {
    for(j=0;j<3;j++)//for each column
    {
    iArray[i][j]=-1;//init array
    }
    }




    }


    I tried moving things around, adding this and removing things but Im stuck. I was able to buy some time from the teacher and I have to have it do Monday. But I need more help..Please

  8. #8
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    This is pseudocode of what your program should do.
    Obviously you already got some code as the useful
    typedefs aren't used in the actual program.


    TIC TAC TOE

    Board[3,3]
    LastPlayer
    Winner

    InitializeBoard with Empty
    Initialize LastPlayer with PlayerTwo
    Ask for player one name
    Ask for player two name
    while( Winner is unknown )
    {
    ..If( LastTurn == PlayerOne )
    ....Ask For Input of Player two
    ..ELSE
    ....Ask for Input of Player one
    ..DrawBoard to Screen
    ..CheckForWinner
    }
    print out congratulations to the Winner


    The CheckForWinner function is probably the
    part that will cost you the most typing
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  9. #9
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Make sure that a draw is possible or possible to quit. (No spaces left, if you get it going you could check to see if a win is still possible but that is harder)
    Start with the horizontal "if((Array[i][0]==Array[i][1])&&(Array[i][1]==Array[i][2]))"
    and vertical winning moves and move onto the diagonal (only two possible).

    The for loop you have will do most of the work if you ask it the right questions.

    do a #define for the output/input
    ie
    #define O 0 //alpha 'o' = zero
    #define X 1 //alpha 'x' = one
    #define 0 "O" //zero is an alpha 'o'
    #define 1 "X"

    this is so you can use
    Code:
    if((Array[i][0]==Array[i][1])&&(Array[i][1]==Array[i][2]))
       if(Array[i][0]==X)//"X" is defined as one
            //player X has won
    Good luck.
    (I once played TicTacToe against a 10yr old street kid in Singapore for money and lost, shouldn't have had that last beer, but he was a professional TTT'er)
    Last edited by novacain; 11-02-2001 at 02:38 AM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cprogra
    By BobMcGee123 in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 05-05-2006, 03:34 PM
  2. PC Game project requires c++ programmers
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 02-21-2006, 11:23 PM
  3. Game Programmer's AIM Circle: Join Today
    By KingZoolerius66 in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 12-20-2003, 11:12 AM
  4. Are programmers engineers?
    By joshdick in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 04-01-2003, 12:55 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21