Thread: My first game

  1. #1
    C/C++ homeyg's Avatar
    Join Date
    Nov 2004
    Location
    Louisiana, USA
    Posts
    209

    My first game

    It's just a text based version of Connect Four. I ran into that old Connect Four tournament thread and that inspired me to write my own version. It pretty much sucks (it is the first full game I've written in any language). Feel free to offer constructive criticism (or non-constructive, whichever). It's only two player right now as I would have no idea where to start with programming the AI. The source code is attached below. Just copy and paste it into your compiler (for I do not have win zip to upload a zip file).

  2. #2
    ---
    Join Date
    May 2004
    Posts
    1,379
    I've heard the Min-Max algo is suitable for connect four clones.
    I googled up this .pdf file
    http://www.progtools.org/games/tutor...ax_contest.pdf

  3. #3
    yes, I'm registered!!! algi's Avatar
    Join Date
    Nov 2004
    Location
    Ipswich
    Posts
    161
    not bad but after the iostream header you should put
    [code]
    using std::cout;
    using std::cin;

  4. #4
    Registered User
    Join Date
    Dec 2004
    Posts
    7
    my compiler says this error:
    g++ -g run.x connectfour.cpp && ./run.x
    connectfour.cpp: In function `int main()':
    connectfour.cpp:29: implicit declaration of function `int system(...)'


    I am on linux so that could aslo be the reason

  5. #5
    Registered User
    Join Date
    Mar 2004
    Posts
    180
    Quote Originally Posted by algi
    not bad but after the iostream header you should put
    Code:
    using std::cout;
    using std::cin;
    Or
    Code:
    using namespace std;

  6. #6
    C/C++ homeyg's Avatar
    Join Date
    Nov 2004
    Location
    Louisiana, USA
    Posts
    209
    I always use 'using namespace std;'. I just don't see why someone would waste time writing 'std::cout', etc.

    And yes, I think system(...) is a Windows thing.

  7. #7
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656
    I've decided that this probably isn't C code:
    Code:
    Shiva:/home/kleid/Programming/Focus# gcc connect4.c
    connect4.c:6:20: iostream: No such file or directory
    connect4.c:8: error: parse error before "namespace"
    connect4.c:8: warning: data definition has no type or storage class
    connect4.c:9: error: parse error before "testFull"
    connect4.c:9: warning: data definition has no type or storage class
    connect4.c:10: error: parse error before "testGameA"
    connect4.c:10: warning: data definition has no type or storage class
    connect4.c:11: error: parse error before "testGameB"
    connect4.c:11: warning: data definition has no type or storage class
    connect4.c: In function `main':
    connect4.c:23: error: `bool' undeclared (first use in this function)
    connect4.c:23: error: (Each undeclared identifier is reported only once
    connect4.c:23: error: for each function it appears in.)
    connect4.c:23: error: parse error before "fullTestA"
    connect4.c:26: error: `cout' undeclared (first use in this function)
    connect4.c:26: error: `endl' undeclared (first use in this function)
    connect4.c:28: error: `cin' undeclared (first use in this function)
    connect4.c:41: error: `for' loop initial declaration used outside C99 mode
    connect4.c:61: error: `for' loop initial declaration used outside C99 mode
    connect4.c:81: error: `for' loop initial declaration used outside C99 mode
    connect4.c:101: error: `for' loop initial declaration used outside C99 mode
    connect4.c:121: error: `for' loop initial declaration used outside C99 mode
    connect4.c:141: error: `for' loop initial declaration used outside C99 mode
    connect4.c:163: error: `for' loop initial declaration used outside C99 mode
    connect4.c:165: error: `for' loop initial declaration used outside C99 mode
    connect4.c:172: error: parse error before "winTestA"
    connect4.c:173: error: `winTestA' undeclared (first use in this function)
    connect4.c:173: error: `false' undeclared (first use in this function)
    connect4.c:179: error: `fullTestB' undeclared (first use in this function)
    connect4.c:180: error: `true' undeclared (first use in this function)
    connect4.c:196: error: `for' loop initial declaration used outside C99 mode
    connect4.c:216: error: `for' loop initial declaration used outside C99 mode
    connect4.c:235: error: `for' loop initial declaration used outside C99 mode
    connect4.c:254: error: `for' loop initial declaration used outside C99 mode
    connect4.c:273: error: `for' loop initial declaration used outside C99 mode
    connect4.c:292: error: `for' loop initial declaration used outside C99 mode
    connect4.c:316: error: redeclaration of `i'
    connect4.c:163: error: `i' previously declared here
    connect4.c:316: error: `for' loop initial declaration used outside C99 mode
    connect4.c:318: error: `for' loop initial declaration used outside C99 mode
    connect4.c:325: error: parse error before "winTestB"
    connect4.c:326: error: `winTestB' undeclared (first use in this function)
    connect4.c:332: error: `fullTestA' undeclared (first use in this function)
    connect4.c: At top level:
    connect4.c:347: error: parse error before "testFull"
    connect4.c: In function `testFull':
    connect4.c:376: error: `true' undeclared (first use in this function)
    connect4.c:380: error: `false' undeclared (first use in this function)
    connect4.c: At top level:
    connect4.c:384: error: parse error before "testGameA"
    connect4.c: In function `testGameA':
    connect4.c:388: error: `false' undeclared (first use in this function)
    connect4.c:656: error: `true' undeclared (first use in this function)
    connect4.c: At top level:
    connect4.c:659: error: parse error before "testGameB"
    connect4.c: In function `testGameB':
    connect4.c:663: error: `false' undeclared (first use in this function)
    connect4.c:931: error: `true' undeclared (first use in this function)
    connect4.c:933:1: warning: no newline at end of file

  8. #8
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    system() itself is a standard function. However the program name you put in it may not be.

    kleid thats a good guess considering its C++ code (#include <iostream> is a dead give away)

    I always use 'using namespace std;'. I just don't see why someone would waste time writing 'std::cout', etc.
    This has been discussed in circles many times. I'd suggest you do a board search to find the pros & cons of it. Its much more then having to type std::

  9. #9
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656
    Quote Originally Posted by homeyg
    I always use 'using namespace std;'. I just don't see why someone would waste time writing 'std::cout', etc.
    You might as well go like this:
    Code:
    #define cout std::cout
    cout << "Much better *sips a glass of wine*";

  10. #10
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Oh god no. I'd rather someone use "using namespace std;" all the time then use a macro

  11. #11
    Registered User
    Join Date
    Mar 2004
    Posts
    180
    whats wrong with the macro?

  12. #12
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656
    Because it's the opposite of micro lol

  13. #13
    C/C++ homeyg's Avatar
    Join Date
    Nov 2004
    Location
    Louisiana, USA
    Posts
    209
    Yes, this is C++ code (sorry I didn't mention that earlier).

    Btw, is there really a difference between using 'using namespace std;' and using 'std::cout'?

  14. #14
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Code:
    using namespace std;
    brings the entire std namespace into the global namespace
    Code:
    using std::cout;
    brings only std::cout into the global namespace

    whats wrong with the macro?
    A lot. Here are two code segments that would not work with the above macro:
    Code:
    std::cout<<"Hello world"<<std::endl;
    mynamespace::<<cout<<"Hello world"<<mynamespace::endl;

  15. #15
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    You'd also get problems if you ever used cout in a string... though I wonder how likely that is to happen...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-08-2010, 12:08 AM
  2. Open Source / Semi Open source game idea. Help needed
    By CaptainPatent in forum Projects and Job Recruitment
    Replies: 10
    Last Post: 05-16-2007, 10:44 AM
  3. game engine advice?
    By stien in forum Game Programming
    Replies: 0
    Last Post: 01-23-2007, 03:46 PM
  4. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM