Need help on my Mancala game.

This is a discussion on Need help on my Mancala game. within the Game Programming forums, part of the General Programming Boards category; Code: #include <iostream> using namespace std; int board[14]; void move(int board[], int pos, int turnNum); void update(int board[]); int main() ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    3

    Need help on my Mancala game.

    Code:
    #include <iostream>
    using namespace std;
    
    int board[14];
    void move(int board[], int pos, int turnNum);
    void update(int board[]);
    int main()
    { 
      int pos;
      board[0] = 4;
      board[1] = 4;
      board[2] = 4;
      board[3] = 4;
      board[4] = 4;
      board[5] = 4;
      board[6] = 0;
      board[7] = 4;
      board[8] = 4;
      board[9] = 4;
      board[10] = 4;
      board[11] = 4;
      board[12] = 4;
      board[13] = 0;
      
      cout<<"Welcome to Mancala!\n";
      cout<<"To play select a position on the board.";
      cout<<"\n\n";
      
      cout<<"--------------------------------\n";
      cout<<"|   | 5 | 4 | 3 | 2 | 1 | 0 |   |\n";
      cout<<"| 6 |-----------------------| 13|\n";
      cout<<"|   | 7 | 8 | 9 | 10| 11| 12|   |\n";
      cout<<"--------------------------------\n";
      
      int totalM = board[6] + board[13];
      int turnNum = 1;
    
      while (totalM < 48)
      {
        update(board);
        
        if (turnNum == 1)
        {
          cout<<"\nPlayer 1: Select a postion: ";
          cin>> pos;
          
          if (pos = 7 || 8 || 9 || 10 || 11 || 12)
          {
            move(board, pos, turnNum);
          }
          
          else
          {
            cout<<"Please select another position: ";
            cin>> pos;
          }
        }
      }
      cin.get();
      return 0;
    }
    
    void move(int board[], int pos, int turnNum)
    {
      int initPos = pos;
      for (int i = 0; i < board[pos] + 1; i++)
      {  
        int curPos = pos + i;
        
        if (curPos >= 14)
          curPos -= 14;
        
        else if (curPos >= 28)
          curPos -= 28;
    
        if (turnNum == 1)
        {
          int * current1 = &(board[curPos]);
          if (current1 == &(board[6]))
            current1 = &(board[7]);
          *current1 += 1;
        }    
        
        else if (turnNum == 2)
        {
          int * current2 = &(board[curPos]);
          if (current2 == &(board[13]))
            current2 = &(board[0]);
          *current2 += 1;
        }
      }
      board[initPos] = 0;
    }
    
    void update(int board[])
    {
      cout<<"\n---------------------------------\n";
      cout<<"|   | "<<board[5]<<" | "<<board[4]<<" | "<<board[3]<<" | "<<board[2]<<" | "<<board[1]<<" | "<<board[0]<<" |   |\n";
      cout<<"| "<<board[6]<<" |-----------------------| "<<board[13]<<" |\n";
      cout<<"|   | "<<board[7]<<" | "<<board[8]<<" | "<<board[9]<<" | "<<board[10]<<" | "<<board[11]<<" | "<<board[12]<<" |   |";
      cout<<"\n---------------------------------\n";
    }
    O.K, the problem is that on the part where the board should be updating the marbles, it doesn't do it all. I really need help with this becuase I am loosing sleep because I can't figure it out, everything else I think I got down, so help please on the move function.

  2. #2
    Registered User Osaou's Avatar
    Join Date
    Nov 2004
    Location
    Stockholm, Sweden
    Posts
    69
    The following, which is in your main loop, won't work as you might expect...
    Code:
    if (pos = 7 || 8 || 9 || 10 || 11 || 12)
    First of all, a single equation sign means assignment - not comparison.
    Secondly, you'll have to test all separately, like so:
    Code:
    if (pos == 7 || pos == 8 || pos == 9 .........etc)
    An even "better" way would be like this:
    Code:
    if (pos >= 7 && pos <= 12)

  3. #3
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    498
    Looks like someone didn't read their C++ book very carefully. Using = when you really mean == is a common mistake, and any good C++ book out there will have it documented.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    You could use a for loop or two in update(). And one in main() to initialize board[].
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

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-07-2010, 11:08 PM
  2. game engine advice?
    By stien in forum Game Programming
    Replies: 0
    Last Post: 01-23-2007, 02:46 PM
  3. 2D RPG Online Game Project. 30% Complete. To be released and marketed.
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 10-28-2006, 12:48 AM
  4. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM

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