Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: Concept and syntax in mancala

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Concept and syntax in mancala

    I've made the majority of the program , however, I've been avoiding the most crucial part of the program. Allowing the user to select the pocket they want to play is something i cant figure out how to do. In the module PlayersTurn I've been trying different things to allow the user enter the number of pocket they want to play and then executing their turn. I've been unsuccessful. I don't know where or how to start can someone help me please? thanks.
    import java.util.Scanner;
    import java.util.Random;
     
    public class Mancala
    {
        public static void main (String[] args)
        {        
          Scanner keyboard = new Scanner(System.in);
          int solidLine;
          int line;
          int partialLine;
          int StartArray;
          final int MAX_VALUE = 97;
          final int step = 1;
          final int partial = 1;
          solidLine( MAX_VALUE);
          line( step,partial);
          solidLine( MAX_VALUE);
        }  
     
        public static void solidLine(int mv)
        {
          for (int s=1;s<=mv;s++)
          {
             System.out.print("*");
          }
          System.out.println();
        }
        public static void GameStarter()
        {
            String Player1;
            String Player2;
            String computerturn;
            int computerInt;
     
            Scanner scan = new Scanner(System.in);
            Random generator = new Random();
     
            computerInt = generator.nextInt(13);
     
            switch (computerInt)
            {
                case 0:
                {
                    computerturn = "1";
                    break;
                }
                case 1:
                {
                    computerturn = "2";
                    break;
                }
                case 2:
                {
                    computerturn = "3";
                    break;
                }
                case 3:
                {
                    computerturn = "4";
                    break;
                }
                case 4:
                {
                    computerturn = "5";
                    break;
                }
                case 5:
                {
                    computerturn = "6";
                    break;
                }
                case 6:
                {
                    computerturn = "7";
                    break;
                }
                case 7:
                {
                    computerturn = "8";
                    break;
                }
                case 8:
                {
                    computerturn = "9";
                    break;
                }
                case 9:
                {
                    computerturn = "10";
                    break;
                }
                case 10:
                {
                    computerturn = "11";
                    break;
                }
                case 11:
                {
                    computerturn = "12";
                    break;
                }
                case 12:
                {
                    computerturn = "13";
                    break;
                }
                case 13:
                {
                    computerturn = "14";
                    break;
                }
                default:
                {
                    computerturn = "Wont happen";
                }
            } 
        }
        public static void PlayersTurn(int[] POCKETS)
        {
     
        }
        public static void GameCalculator(int[] POCKETS)
        {
            POCKETS[0]=POCKETS[1]+POCKETS[2]+POCKETS[3]+POCKETS[4]+POCKETS[5]+POCKETS[6];
            POCKETS[7]=POCKETS[8]+POCKETS[9]+POCKETS[10]+POCKETS[11]+POCKETS[12]+POCKETS[13];
            if (POCKETS[0] < POCKETS[7])
                System.out.println("Player two wins");
            else 
            System.out.println("Player one wins");
        }
        public static void StartArray();
        {
          int beadearray;
          int POCKET = 14;
          int[] POCKETS = {0,4,4,4,4,4,4,//top part of board
                           0,4,4,4,4,4,4};//bottom part of board
        }
        public static void line(int step, int partial)
        {
     
            for (int l=1;l<=step;l++)
          {
              System.out.print("*  " + POCKETS[0]+ " (1)" +"    ");
          }
          for (int l=1;l<=step;l++)
          {
              System.out.print("*  " + POCKETS[1]+ " (2)" +"    ");
          }
          for (int l=1;l<=step;l++)
          {
              System.out.print("*  " + POCKETS[2]+ " (3)" +"    ");
          } 
          for (int l=1;l<=step;l++)
          {
              System.out.print("*  " + POCKETS[3]+ " (4)" +"    ");
          } 
          for (int l=1;l<=step;l++)
          {
              System.out.print("*  " + POCKETS[4]+ " (5)" +"    ");
          } 
          for (int l=1;l<=step;l++)
          {
              System.out.print("*  " + POCKETS[5]+ " (6)" +"    ");
          } 
          for (int l=1;l<=step;l++)
          {
              System.out.print("*  " + POCKETS[6]+ " (7)" +"    ");
          }
             for (int l=1;l<=step;l++)
          {
              System.out.print("*  " + POCKETS[7]+ " (8)" +"    *");
          }
          System.out.println();
          for (int p=1;p<=partial;p++)
            {
                System.out.print("*           *************************************************************************           *");
            } 
            System.out.println();
          for (int l=1;l<=step;l++)
          {
              System.out.print("*" +"           ");
          }   
              for (int l=1;l<=step;l++)
          {
              System.out.print("*  " + POCKETS[8]+ " (9)" +"    ");
          }
           for (int l=1;l<=step;l++)
          {
              System.out.print("*  " + POCKETS[9]+ " (10)"+"   ");
          }
           for (int l=1;l<=step;l++)
          {
              System.out.print("*  " + POCKETS[10]+ " (11)"+"   ");
          }
           for (int l=1;l<=step;l++)
          {
              System.out.print("*  " + POCKETS[11]+ " (12)"+"   ");
          }
           for (int l=1;l<=step;l++)
          {
              System.out.print("*  " + POCKETS[12]+ " (13)"+"   ");
          }
           for (int l=1;l<=step;l++)
          {
              System.out.print("*  " + POCKETS[13]+ " (14)"+"   ");
          }
           for (int l=1;l<=step;l++)
          {
              System.out.print("*  " +"         *");
          }
          System.out.println();
        }
     
     
     }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Concept and syntax in mancala

    Can you describe what the code does now and what is wrong with the way it is working?

    Try debugging the code by adding lots of calls to the println() method to print out messages to show the execution flow and the values of variables as they are set, changed and used.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Concept and syntax in mancala

    Actually now that you mention it, i was having issues with compiling. What the program does is print the board through a series of "*" with POCKETS, holes in the game that hold a certain number of beads, and positions. Originally, the contents of StartArray was part of method Line. however, i figured making a seperate array that holds beadarray, POCKET, and POCKETS would be more efficient. When i compiled i got an error in this part of the program
     line( step,partial);
    The error says "Method line in class Mancala cannot be applied to given types; required: int, int, int" i have no idea what this means. i tried changing it by doing this
    line( step,partial, POCKETS[])
    but then i get ".class expected" ive tried many other changes but cant get it to compile. Am i passing references wrong?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Concept and syntax in mancala

    required: int, int, int
    The compiler thinks that the line method takes 3 int values.
    Is the error message from the posted code? Or do you have another version of the program where the line method has three int args?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Concept and syntax in mancala

    Yes
    public static void line(int step, int partial)
    was changed to
    public static void line(int step, int partial,int[] POCKETS)

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Concept and syntax in mancala

    If you change the definition of the args taken by a method then you need to change the code that calls that method so that the args agree.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Concept and syntax in mancala

    I dont fully understand what you mean. Now that i changed
    public static void line(int step,int partial, int[] POCKETS)
    i have to change the code but how? ive tried
    line( step,partial,POCKETS)
    is it because POCKETS has multiple values the call changes?

  8. #8
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Concept and syntax in mancala

    Read Norm's message ahead. What he said will lead you to the solution.
    Anyone who stops learning is old, whether at twenty or eighty. Anyone who keeps learning stays young. The greatest thing in life is to keep your mind young.

    - Henry Ford

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Concept and syntax in mancala

    If you are now getting compiler errors after your change, please post the full text of the error messages.
    If you don't understand my answer, don't ignore it, ask a question.

  10. #10
    Junior Member
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Concept and syntax in mancala

    Okay so i changed somethings around and finally got it to compile and run here is the new program.
    import java.util.Scanner;
    import java.util.Random;
     
    public class Mancala
    {
        public static void main (String[] args)
        {        
          Scanner keyboard = new Scanner(System.in);
          int solidLine;
          int line;
          int partialLine;
          int StartArray;
          int[] POCKETS = {0,4,4,4,4,4,4,//top part of board
                           0,4,4,4,4,4,4};//bottom part of board
          final int MAX_VALUE = 97;
          final int step = 1;
          final int partial = 1;
          solidLine( MAX_VALUE);
          line( step,partial,POCKETS);
          solidLine( MAX_VALUE);
        }  
     
        public static void solidLine(int mv)
        {
          for (int s=1;s<=mv;s++)
          {
             System.out.print("*");
          }
          System.out.println();
        }
        public static void GameStarter(int[] POCKETS)
        {
            String Player1;
            String Player2;
            String computerturn;
            int computerInt;
     
            Scanner scan = new Scanner(System.in);
            Random generator = new Random();
     
            computerInt = generator.nextInt(13);
     
            switch (computerInt)
            {
                case 0:
                {
                    computerturn ="0";
                    break;
                }
                case 1:
                {
                    computerturn = "1";
                    break;
                }
                case 2:
                {
                    computerturn = "2";
                    break;
                }
                case 3:
                {
                    computerturn = "3";
                    break;
                }
                case 4:
                {
                    computerturn = "4";
                    break;
                }
                case 5:
                {
                    computerturn = "5";
                    break;
                }
                case 6:
                {
                    computerturn = "6";
                    break;
                }
                case 7:
                {
                    computerturn = "7";
                    break;
                }
                case 8:
                {
                    computerturn = "8";
                    break;
                }
                case 9:
                {
                    computerturn = "9";
                    break;
                }
                case 10:
                {
                    computerturn = "10";
                    break;
                }
                case 11:
                {
                    computerturn = "11";
                    break;
                }
                case 12:
                {
                    computerturn = "12";
                    break;
                }
                case 13:
                {
                    computerturn = "13";
                    break;
                }
                case 14:
                {
                    computerturn = "14";
                    break;
                }
                default:
                {
                    computerturn = "Wont happen";
                }
            } 
        }
        public static void PlayersTurn(int[] POCKETS)
        {
     
        }
        public static void GameCalculator(int[] POCKETS)
        {
            if (POCKETS[0] < POCKETS[7])
                System.out.println("Player two wins");
            else 
            System.out.println("Player one wins");
        }
        public static void StartArray(int[] POCKETS)
        {
          int beadarray;
          int POCKET = 14;
        }
        public static void line(int step, int partial,int[] POCKETS)
        {
            for (int l=1;l<=step;l++)
          {
              System.out.print("*  " + POCKETS[0]+ " (1)" +"    ");
          }
          for (int l=1;l<=step;l++)
          {
              System.out.print("*  " + POCKETS[1]+ " (2)" +"    ");
          }
          for (int l=1;l<=step;l++)
          {
              System.out.print("*  " + POCKETS[2]+ " (3)" +"    ");
          } 
          for (int l=1;l<=step;l++)
          {
              System.out.print("*  " + POCKETS[3]+ " (4)" +"    ");
          } 
          for (int l=1;l<=step;l++)
          {
              System.out.print("*  " + POCKETS[4]+ " (5)" +"    ");
          } 
          for (int l=1;l<=step;l++)
          {
              System.out.print("*  " + POCKETS[5]+ " (6)" +"    ");
          } 
          for (int l=1;l<=step;l++)
          {
              System.out.print("*  " + POCKETS[6]+ " (7)" +"    ");
          }
             for (int l=1;l<=step;l++)
          {
              System.out.print("*  " + POCKETS[7]+ " (8)" +"    *");
          }
          System.out.println();
          for (int p=1;p<=partial;p++)
            {
                System.out.print("*           *************************************************************************           *");
            } 
            System.out.println();
          for (int l=1;l<=step;l++)
          {
              System.out.print("*" +"           ");
          }   
              for (int l=1;l<=step;l++)
          {
              System.out.print("*  " + POCKETS[8]+ " (9)" +"    ");
          }
           for (int l=1;l<=step;l++)
          {
              System.out.print("*  " + POCKETS[9]+ " (10)"+"   ");
          }
           for (int l=1;l<=step;l++)
          {
              System.out.print("*  " + POCKETS[10]+ " (11)"+"   ");
          }
           for (int l=1;l<=step;l++)
          {
              System.out.print("*  " + POCKETS[11]+ " (12)"+"   ");
          }
           for (int l=1;l<=step;l++)
          {
              System.out.print("*  " + POCKETS[12]+ " (13)"+"   ");
          }
           for (int l=1;l<=step;l++)
          {
              System.out.print("*  " + POCKETS[13]+ " (14)"+"   ");
          }
           for (int l=1;l<=step;l++)
          {
              System.out.print("*  " +"         *");
          }
          System.out.println();
        }
     
     
     }
    So now we've got that issue out of the way. I still have the problem of setting up a method that allows a user to play the game. The rules of mancala are this. there are two players and the objective of the game is to put the most beads into the players home pocket. Player1's home pocket is "(8)" player2 or computer's home pocket is "(1)".When you pick a pocket the value of that pocket is reduced to 0. Then you drop one bead into each pocket clockwise for as many beads you have. So if i pick pocket 2 and it has 3 beads, the value of pocket 2 is reduced to 0 then i drop one bead into pocket 3,4,&5. How do you suggest I go about this?

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Concept and syntax in mancala

    How do you suggest I go about this?
    What does the program do and what do each of the players do?

    There is a lot of repetitive code in what you posted that should be reduced to something simpler. Too many lines are repeated with only slight changes between them.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. JADE---Sending an Concept including an concept
    By HansDampf in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 25th, 2014, 12:22 AM
  2. In memory concept
    By VaniRathna in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: February 6th, 2012, 06:48 AM
  3. Help with a GUI Concept
    By UnKnown Conceptz in forum AWT / Java Swing
    Replies: 1
    Last Post: January 28th, 2012, 08:53 AM
  4. Need help with a interface concept
    By drakenlord in forum Object Oriented Programming
    Replies: 2
    Last Post: September 13th, 2011, 02:17 PM
  5. [SOLVED] The concept of Server and Client
    By rendy.dev in forum Java Theory & Questions
    Replies: 3
    Last Post: January 18th, 2010, 04:13 AM