Making Board Games...

This is a discussion on Making Board Games... within the Game Programming forums, part of the General Programming Boards category; Hello all! I have been programming in C++ for about a year now and am still working in the console ...

  1. #1
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434

    Making Board Games...

    Hello all!

    I have been programming in C++ for about a year now and am still working in the console programming department Oh well, i like it, i have been working mostly on simple programs dealing with mathematics and encryption as some of you may know. I would like to expand that knowledge into game programming a bit because i feel some of the things i will need to learn will help me out in the long run What i really want to do is make a simple, console based chess game. I was fascinated tonight after getting an Electronic Chess board for Christmas from one of my relatives. It amazed me how smart it was, i am good at chess but the first game i played against it it caught me up in a stale mate, i was shocked! How could a chess set plan, manuever and 'think' so well, i am now very interested in doing some game AI programming like this. Now maybe this belongs in the AI forum, if you moderators/administrators out there feel it does please move it to the appropriate forum (i am a Mod on one forum and an Admin on another so i know what its like )

    Ok so what i want to know is: how can i make a chess game? More specifically what steps do i have to take to get to that skill level of programming? I am sure i will need to know trees (minimax i believe) and other things that come into play in the realm of AI/Game programming. I also understand that i will not be able to jump right into Chess programming, i will probably need to make a few stops along the way. So if anyone can point me in the right direction of good tutorials, books, etc. It would be greatly apprecaited. Although i still love Encryption and security at heart i really want to try my hand at this type of programming. Thanks again for any help you may be able to provide!

  2. #2
    lv.42 Berserker Drake's Avatar
    Join Date
    Jun 2005
    Posts
    67
    A great book i recommend is "Beginning C++ Game Programming" by Michael Dawson(Gamedev). I've been using this book for a couple of months and it really helped. Although, it is for n00bs to C++ like myself. Check it out at and retail book store(ex: Borders).

    p.s. here is a link from this website for AI programming-->http://www.aihorizon.com/

  3. #3
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    Thanks for the recommendation, ill check it out. I know about AIHorizon and ive checked it out but its not really helping alot, advanced ideas and priniciples and such. No real beginner stuff. But once again thanks for the recommendation ill go on amazon and take a look.

  4. #4
    ---
    Join Date
    May 2004
    Posts
    1,379
    AFAIK the AI used in Chess games is far from a being a begginer subject.

  5. #5
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    The client I use uses a minimax algorithm - that's probably about as simple as you're going to get, and IIRC it's included in the "advanced" ideas at AIHorizon.com.

  6. #6
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    Ok guys, here's how i understand it:

    games like chess and tic-tac-toe use a Minimax tree as Sean said.

    I decided that because chess is merely a ridiculously more complex form of tic-tac-toe (if you can say merely). My point is that they seem to be very similar yet one is much more complex than the other. So i decided to make a tic-tac-toe game.

    I have just finished programming all of the program except for the AI. I have win parameters coded in and everything else. In fact here is my code. The only 2 things i need are the AI and i have to get the computer to randomly pick who goes first (i have a program or a tut around here somewhere where it shows you how to do that). So heres the code for the tic-tac-toe game:

    Code:
    #include <iostream>
    #include <windows.h>
    
    using namespace std;
    
    void dispboard(char board[3][3]);
    
    int main()
    {
        //tic-tac-toe game
        //infinite loop
        while(1)
        {
            //clear screen;
            system("cls");
            //title
            cout<<"##########################\n";
            cout<<"##########################\n";
            cout<<"##    TIC - TAC - TOE   ##\n";
            cout<<"##      VERSION 1.0     ##\n";
            cout<<"##########################\n";
            cout<<"##########################\n\n";
            //menu
            cout<<"(1) Play\n";
            cout<<"(2) Exit\n";
            //get choice
            int mchoice;
            cout<<"Choice: ";
            cin>>mchoice;
            cin.ignore();
            //evaluate
            if(mchoice==2)
            {
                //exit
                cout<<"Exitting...";
                Sleep(1000);
                break;
            }
            if(mchoice!=1)
            {
                cout<<"Incorrect Choice";
                cin.ignore();
                continue;
            }
            //play game
            //initialize vairiables***************
            //init board
            char board[3][3];
            //fill board
            int bfi;
            int bf;
            for(bfi=1; bfi<4; bfi++)
            {
                for(bf=1; bf<4; bf++)
                {
                    board[bfi][bf]='\0';
                }
            }
                    
            //init piece vars
            char player;
            char computer;
            //************************************
            //get which the player wants
            cout<<"\n\nWhich Piece would you like to be?\n";
            cout<<"(1) X 's\n";
            cout<<"(2) O 's\n\n";
            //get
            int piecechoice;
            cout<<"Choice: ";
            cin>>piecechoice;
            cin.ignore();
            //evaluate
            if(piecechoice==1)
            {
                player='X';
                computer='O';
            }
            else if(piecechoice==2)
            {
                player='O';
                computer='X';
            }else{
                cout<<"Incorrect Choice!";
                cin.ignore();
                continue;
            }
            //begin game
            //vars
            int column;
            int row;
            int win;
            win=0;
            while(win==0)
            {
                system("cls");
                column=0;
                row=0;
                dispboard(board);
                //check for winner
                char checkletter;
                for(bf=1; bf<4; bf++)
                {
                    for(bfi=1; bfi<3; bfi++)
                    {
                        if(bfi==1)
                        {
                            checkletter=player;
                        }else if(bfi==2)
                        {
                            checkletter=computer;
                        }        
                        if((board[bf][1]==checkletter && board[bf][2]==checkletter && board[bf][3]==checkletter) ||
                           (board[1][bf]==checkletter && board[2][bf]==checkletter && board[3][bf]==checkletter) ||
                           (board[1][1]==checkletter && board[2][2]==checkletter && board[3][3]==checkletter) ||
                           (board[3][1]==checkletter && board[2][2]==checkletter && board[1][3]==checkletter))
                        {
                            //winner
                            if(checkletter==player)
                            {
                                //human won
                                win=1;
                            }
                            else if(checkletter==computer)
                            {
                                //computer won
                                win==2;
                            }    
                        }
                    }    
                }
                if(win!=0)
                {
                    break;
                }    
                cout<<"\n\n\n";
                cout<<"Where would You Like To Move?\n";
                cout<<"Column: ";
                cin>>column;
                cin.ignore();
                cout<<"Row: ";
                cin>>row;
                cin.ignore();
                board[column][row]=player;
            }
            //write winner
            if(win==1)
            {
                //human won
                cout<<"\n\nCongratulations You Won!\n\n";
                cin.ignore();
                continue;
            }
            if(win==2)
            {
                cout<<"Sorry You Lost!\n\n";
                cin.ignore();
                continue;
            }            
        }
        return 0;
    }                
    
    void dispboard(char board[3][3])
    {
        cout<<"  1    2    3  \n";
        cout<<"     |    |     \n";
        cout<<"1 "<<board[1][1]<<"  | "<<board[2][1]<<"  | "<<board[3][1]<<"  \n";
        cout<<" ____|____|____\n";
        cout<<"     |    |    \n";
        cout<<"2 "<<board[1][2]<<"  | "<<board[2][2]<<"  | "<<board[3][2]<<"  \n";
        cout<<" ____|____|____\n";
        cout<<"     |    |    \n";
        cout<<"3 "<<board[1][3]<<"  | "<<board[2][3]<<"  | "<<board[3][3]<<"  \n";
        cout<<"     |    |    \n";
    }
    So anyone who can help me out/ point me in the right direction it would be greatly appreciated. Thanks!

  7. #7
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    The first thing you need for a minimax tree is the data structure - you need objects to represent the board after every possible move as far as your program is intended to think (for Tic-Tac-Toe it's feasible to go all the way). So you need to write the class definition, and then you need to put these objects into a searchable tree (some of the tutorials Prelude has written should help you considerably with this part).

    Then you need to write code that will analyze your odds of a winning outcome for each possible next move - and then make that move.

  8. #8
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    Ok, after reading your post a few times i think i need to do something like this:

    [x _ _]
    [_ _ _]
    [_ _ _]
    | \
    [X O _] [X _ _]
    [_ _ _] [O _ _]
    [_ _ _] [_ _ _]

    etc. etc. etc. Thats a minimax tree right?

    So what would the best way to approach the problem be? I mean as far as storing that information as you said? If() statements? Switch statements? Or something entirely different like a bunch of board[3][3] arrays and say
    Code:
    if(board1[3][3]=board[3][3]) {}...
    Seems like tedious work, if you could perhaps tell me how you think the best way to approach it is? Or if you already did above perhaps you could clarify it for me. Thanks alot Sean!

  9. #9
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    I can't really tell what that diagram is. But basically this tree should be like a linked-list where each node can have multiple children. Your class therefore, should consist of a null-terminated array of pointers to nodes (the children nodes), possibly a pointer to the parent node (optional - it's possible to do without), and a 2d array representing the board.

    If you don't understand all of that, you need to do some serious reading up on data structures before proceeding with this project.

    The best approach is to take it step by step. Learn about data structures. Design the data structure. Learn about searching algorithms. Write the searching algorithm. It will be tedious work. If it isn't, you're probably not doing it right.

  10. #10
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    sorry the diagram was better but forums like these dont let you put too many spaces between words. My diagram was supposed to show the X where the user goes. Than the possible places where the computer can place an O, of course there are 8 possible places i only showed 2. Hopefully you understand the diagram now. I saw one like it when i read up on Minimax trees last night.

    Ok so ill start trying to do some research on data structures (like arrays and such?) and linked lists (theres a chapter in my Learn C++ in 21 Days Book, but it wasn't represented good. Ok ill do that. If you or anyone else can point me in the right direction of some tutorials online or articles or websites etc. that can help me out please post them up. Thanks again Sean.

  11. #11
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    sorry the diagram was better but forums like these dont let you put too many spaces between words
    Code tags are useful for that kind of thing - they preserve spacing and all the characters are the same width.

    You'll want to be familiar with the syntax for working with 2d arrays and pointers. Linked-lists will help you understand the concept a bit, but you'll really want to read some of the articles on other types of data trees (seriously - Prelude's articles are good. Check out her website @ eternallyconfuzzled.com). Binary search trees aren't terribly relevant, but you'll learn concepts you need to know.

  12. #12
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    ok thanks

  13. #13
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913

  14. #14
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    Wow thanks, it has the tree right there! Thanks alot ill read it all. Thanks Sean for finding me that, i really appreciate it. Hopefully i will find a way to implement it into my code.

    EDIT: Ok after reading that great article i think now im going to draw out the full minimax tree, and get that out of the way. Then ill evaluate the outcomes. After that ill figure out a way to integrate that into my code. Thanks again Sean. I cant imagine how big the tree is for chess!
    Last edited by Junior89; 12-26-2005 at 06:33 PM.

  15. #15
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    > for(bfi=1; bfi<4; bfi++)
    Perhaps learning C++ before going onto more advanced stuff would be a better idea.
    Like for example the fact that arrays start at 0, not 1.

    It's all very well looking at all these advanced things, but if you're always going to be shooting yourself in the foot over the basics, you're not going to make progress.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Biggest problem when making games?
    By Yarin in forum Game Programming
    Replies: 15
    Last Post: 09-29-2007, 01:53 PM
  2. starting making games like warcraft 3
    By Mythic Fr0st in forum Game Programming
    Replies: 13
    Last Post: 01-22-2007, 08:31 PM
  3. making games
    By Unregistered in forum Game Programming
    Replies: 2
    Last Post: 02-23-2002, 01:23 PM
  4. best language for making games?
    By Unregistered in forum Game Programming
    Replies: 9
    Last Post: 11-09-2001, 04:37 AM
  5. making money and playing games...
    By Aran in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 09-10-2001, 07:13 PM

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