Results 1 to 7 of 7
  1. #1
    Poddy is offline Member
    Join Date
    Feb 2009
    Posts
    3
    Rep Power
    0

    Default Problem with an assignment: Backgammon game

    Hi, i currently am a student for java.
    I have been given an assignment to create a backgammon game, although i have encountered a problem.

    I created a function that is supposed to check if a player has all it's checkers in his "away" box(the 6 columns that are the target to reach).
    Returning a boolean if he can "check out".

    Although even when i know the result should be true, it returns false and throws an error message.
    If anyone could assist me on this i would be very grateful.

    Calling to the function
    Java Code:
    System.out.println("Please enter the ending column");
    String input;
    input=in.nextLine();
        if (input.equalsIgnoreCase("end"))
        {
    	current_player.turns=0;
    	continue;
        }
        else if (input.equalsIgnoreCase("out"))
        {
               readyToCheckOut=Utility.readyToCheckOut(readyToCheckOut, column, current_player, player1, player2);
    
               if(readyToCheckOut)
    	         Utility.checkOut(column, input, start, current_player);
               else
               {
                     System.out.println("You are not ready to checkout. please get all your checkers to the away box.");
                     continue;
               }
    							
       }
    the function:
    Java Code:
    // Checks if the user is ready to check out.
    public static boolean readyToCheckOut(boolean readyToCheckOut,Column[] column, Player current_player, Player player1, Player player2)
    	{
    		while(readyToCheckOut)
    		{
    			if(current_player==player2)
    			{
    				for(int i=0;i<18;i++)
    				{
    					if(column[i].checkersCount==0 && column[i].player == player2)
    						continue;
    					else
    						readyToCheckOut=false;
    				}
    			}
    			else
    			{
    				for(int i=23;i>6;i--)
    				{
    					if(column[i].checkersCount==0 && column[i].player == player1)
    						continue;
    					else
    						readyToCheckOut=false;
    				}
    			}
    		}
    		return readyToCheckOut;
    	}

  2. #2
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

    Default

    what is the error that you are getting?

  3. #3
    Poddy is offline Member
    Join Date
    Feb 2009
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by emceenugget View Post
    what is the error that you are getting?
    The error is being:
    Java Code:
     System.out.println("You are not ready to checkout. please get all your checkers to the away box.");
                     continue;

    executed

    which prints the message and goes to the start of the loop, which is triggering by a false check of the boolean statement from the function.

    in short i just need to get the function to return true when it is so.
    Last edited by Poddy; 02-04-2009 at 06:59 PM. Reason: formatting

  4. #4
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

    Default

    Utility.readyToCheckOut loops as long as readyToCheckOut is true... maybe you meant to have it loop as long as it is false?

  5. #5
    Poddy is offline Member
    Join Date
    Feb 2009
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by emceenugget View Post
    Utility.readyToCheckOut loops as long as readyToCheckOut is true... maybe you meant to have it loop as long as it is false?
    It needs to be true, because if i find any non empty checkers in the way it must revert to false and break.
    So being true wouldn't help

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    If you cross-post a question on multiple fora, the polite thing to do would be at least to place links in each thread to all the others. No one likes putting in effort to answer questions that have already been answered elsewhere.

  7. #7
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    if it continue, readyToCheckOut remains true,
    then loop again, and continue, and loop again....
    non-stop looping....
    have you think of how to break the loop?

Similar Threads

  1. Replies: 2
    Last Post: 05-15-2008, 10:15 AM
  2. Problem using buttons to creat a magic square game
    By goldman in forum New To Java
    Replies: 5
    Last Post: 05-05-2008, 04:04 AM
  3. Game of Life assignment
    By javan00b in forum New To Java
    Replies: 4
    Last Post: 04-28-2008, 05:49 AM
  4. assignment problem help needed
    By tiggz1980 in forum New To Java
    Replies: 2
    Last Post: 02-06-2008, 11:14 PM
  5. Cannot solve the coding problem of my assignment
    By elimmom in forum New To Java
    Replies: 3
    Last Post: 08-13-2007, 11:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •