Results 1 to 8 of 8
  1. #1
    javaprogr is offline Member
    Join Date
    Nov 2013
    Posts
    6
    Rep Power
    0

    Default n-puzzle help program

    deletee
    Last edited by javaprogr; 11-16-2013 at 07:19 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: n-puzzle help program

    If you have questions about your code, please paste it here in the forum along with your questions. No links.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    javaprogr is offline Member
    Join Date
    Nov 2013
    Posts
    6
    Rep Power
    0

    Default java exercise help please

    Hi please can you see this code and tell me if it is okay with this ex ? if there are wrongs or there are parts that are not included in the code please tell me it to add them

    how i can write this differently because i have only stdin library and not that
    KeyboardInputClass PuzzleInput = new KeyboardInputClass();
    int PuzzleSize;
    PuzzleSize = PuzzleInput.getInteger(false, 8, 0, 36, "What size puzzle do you want to solve(ex: 8...15...24...35)");


    the code is
    Java Code:
    import java.util.*;
     
    public class ex
    {
        public static void main(String[] args)
        {
            //This asks the user for what size puzzle do they want to solve. 
            KeyboardInputClass PuzzleInput = new KeyboardInputClass();
            int PuzzleSize;
            PuzzleSize = PuzzleInput.getInteger(false, 8, 0, 36, "What size puzzle do you want to solve(ex: 8...15...24...35)");
     
            //This Ask the user how many times they want to shuffle the board.
            KeyboardInputClass ShuffleBoard = new KeyboardInputClass();
            int NumberOfShuffles;
            NumberOfShuffles = ShuffleBoard.getInteger(false, 0, 0, 1000, "How many times do you want to shuffle the board?");
     
            //This creates a starting puzzle and goal board (dependent on size of puzzle) in a single array then converst both to a double array.
            int[] Board = PuzzleSingleArray(PuzzleSize, NumberOfShuffles);
            int[] GoalBoard = GoalState(PuzzleSize);
            int[][] Board2D = PuzzleDoubleArray(PuzzleSize, Board);
            int[][] GoalBoard2D = PuzzleDoubleArray(PuzzleSize, GoalBoard);
     
            //This is the staring puzzle configration
            PrintPuzzle(Board2D);
             
     
            //This ask the user what algotithum they want to preform. 
            KeyboardInputClass TestInput = new KeyboardInputClass();
            char TestMethod;
            TestMethod = TestInput.getCharacter(true, 'b', "a" + "b", 0, "What Algoritum do you want to preform b = breadth-first or a = A*");
     
            PrintPuzzle(GoalBoard2D);
        }
     
        public static int[] PuzzleSingleArray(int Size, int Shuffle)
        {
            int puzzle[] = new int[Size+1];  //this makes the size of the single array
            int index;
            int Shuffles = Shuffle;  //This is the input for number of shuffles
     
            // Put all numbers into the array
            for (index = 0; index <= Size; index++)
                puzzle[index] = index;
     
            // Make random numbers
            for (int i = 0; i < Shuffles; i++)  //this for loop runs for the amount of times the user wanted to shuffle
            {
                for (index = 0; index < Size; index++)
                {
                    int randomIndex = (int)Math.floor(Math.random() * Size);
                    int temp = puzzle[index];
                    puzzle[index] = puzzle[randomIndex];
                    puzzle[randomIndex] = temp;
                }
            }
            return puzzle;
        }
     
        //load single aray into double array
        public static int[][] PuzzleDoubleArray(int Size, int[] puzzle)
        {
            int[][] board = new int[1][1];
            if (Size == 8)
            {
                board = new int[3][3];
                int k = 0;
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        board[i][j] = puzzle[k];
                        k++;
                    }
                }
                return board;
            }
            else if (Size == 15)
            {
                board = new int[4][4];
                int k = 0;
                for (int i = 0; i < 4; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        board[i][j] = puzzle[k];
                        k++;
                    }
                }
                return board;
            }
            else if (Size == 24)
            {
                board = new int[5][5];
                int k = 0;
                for (int i = 0; i < 5; i++)
                {
                    for (int j = 0; j < 5; j++)
                    {
                        board[i][j] = puzzle[k];
                        k++;
                    }
                }
                return board;
            }
            else if (Size == 35)
            {
                board = new int[6][6];
                int k = 0;
                for (int i = 0; i < 6; i++)
                {
                    for (int j = 0; j < 6; j++)
                    {
                        board[i][j] = puzzle[k];
                        k++;
                    }
                }
                return board;
            }
            return board;
        }
     
        public static int[] GoalState(int Size)
        {
            int[] Goal = new int[1];
            if (Size == 8)
            {
                Goal = new int[9];
                for (int i = 0; i < 9 - 1; i++)
                    Goal[i] = i + 1;
                Goal[9 - 1] = 0;
                return Goal;
            }
            else if (Size == 15)
            {
                Goal = new int[16];
                for (int i = 0; i < 16 - 1; i++)
                    Goal[i] = i + 1;
                Goal[16 - 1] = 0;
                return Goal;
            }
            else if (Size == 24)
            {
                Goal = new int[25];
                for (int i = 0; i < 25 - 1; i++)
                    Goal[i] = i + 1;
                Goal[25 - 1] = 0;
                return Goal;
            }
            else if (Size == 35)
            {
                Goal = new int[36];
                for (int i = 0; i < 36 - 1; i++)
                    Goal[i] = i + 1;
                Goal[36 - 1] = 0;
                return Goal;
            }
            return Goal;
        }
     
        public static void PrintPuzzle(int[][] Board)
        {
            for (int i = 0; i < Board.length; i++)
            {
                for (int j = 0; j < Board[0].length; j++)
                {
                    System.out.print(" " + Board[i][j]);
                }
                System.out.println();
            }
        }
    the exercise
    In this excercise we will deal with loops, controls
    two-dimensional tables, functions,
    formatted input / output on the
    screen. The exercise consists of multiple parts. Implement all
    parties at least two files Java, a library and a client, using
    functions. will
    start with a description of the N-Puzzle game and
    then we will present the
    requested
    Whether or not
    the game 8-puzzle, where the goal is to find a sequence movements so that from
    a
    given initial configuration of tiles on the dashboard of the
    game to reach a predetermined
    final provision. The figure below
    shows such a problem.


    note
    that the final provision the gap is always in the bottom right-hand corner of
    the dashboard (table)
    of the game. The solution of the problem can
    be described as a sequence of movements
    vacancy (i.e. replacement
    of one of the adjoining tiles). In particular, a solution to the
    above
    problem is the following:

    left, top, right, bottom,
    bottom, right

    , stating that the vacant position
    was moved six times, first to the left, then upwards etc.
    please
    note that the movement of vacancy arises essentially from the movement of a
    plate in the opposite direction. For example, when we say that the
    vacant position is moved to the left
    what is really happening is
    that the plate that was left the vacancy
    has been moved to the
    right. Similar to the problem 8-puzzle, can be used to define the problem
    15-puzzle, 24-puzzle etc. In General can be assigned a (N2
    -1)
    jigsaw puzzle, where n specifies the size of the game
    .
    is
    about this exercise is to implement a program in Java programming language
    that allows the user to play a puzzle game. N determines the size of
    the table
    N-puzzle. The program you will need to take N as a
    parameter program. We must also
    take as a parameter a number, d,
    which is a number that is associated with the presentation of the puzzle
    on
    the screen, 1 for text-based, 2 for graphics, and 0 for any of the two.
    Your
    program should implement the following functions:


    Mode 1: O user, the first step should be chosen from a menu. With the first
    option
    the menu, the user chooses the degree of difficulty k. The
    number k of times (in
    number of feasible moves) the program must
    randomly shuffle (Math.random ()) the puzzle .

    When
    mixing the puzzle , the priority of feasible movements are : left, top ,
    right
    , down, depending on the values ​​given by the random. Eg if feasible movements
    is 3 , then for
    values ​​the random [0, 0.3] move will be left for
    prices ] 0.3, 0.6 ] above, and prices ] 0.6,
    1 [right .
    After
    the program should continue implementing its functions 2 and 3, ie
    program will interact with the user , expecting him to move command
    .

    If the user selects 2, then the program
    will have to play this game
    randomly moving the tiles trying to
    find a solution. Before doing this , the program
    should ask the
    user four values:
    1. a range of values ​​for the degree of
    difficulty k, ie two values ​​kmin and kmax
    Two . Then asks him
    how many times , p, must play game for all k. In this
    case, each
    time starting a new game for the same k, the initial configuration of
    game
    should be the same . The initialization of the puzzle in the starting line to
    become
    means of a function initializePuzzleK (your parameters).
    Hint: save the original table and redo initialization this table
    before every game for the same k.
    Three . And finally ,
    apply a maximum displacements , q, for each game. If the puzzle does not
    solved
    with fewer movements than the limit q, we have failed , and begins a new
    game
    if the number of games played so far is less than p.
    4. At this
    level, we can count : the success rate of individual games for k
    e
    [kmin ... kmax]. Also , they should calculate and average movement for each
    k e [kmin ... kmax] only in case of success. With these data to
    produce two
    graphs , one showing the success rate ( in y axis )
    versus
    of k ( the x axis ) , and the other the average ( in y axis
    ) movements in
    function of k ( in y axis ) . Note : for every k e
    [kmin ... kmax], must
    using the same p , and the same q.
    5.
    Run the program , select values ​​for kmin and kmax and different values ​​for p
    and q,
    and produce the two graphs. You can do it in Excel, or
    using StdStats.java. Will announce later what values ​​will
    run
    to generate the graphs that will deliver in the end
    The menu will
    be as follows:
    1. Interactive play
    Two .
    Automatic play
    Three . Exit
    The original layout of
    the tiles before the start of an interactive game should
    represents a solved puzzle. This will produce the function
    initializePuzzle
    (your_parameters). After option 1. from the menu , the order
    changing the tiles with a function shufflePuzzle (your_parameters) (
    where
    your_parameters can be as many parameters considered
    necessary ) that will stir a
    solve
    For option
    2 . from the menu , it suffices shufflePuzzle to call once for each k, and

    then save the table to use for each k, as in Hint
    you
    give above.

    Mode 2 (
    Showing N-puzzle): The puzzle loaded in memory is shown in
    screen
    in the form of two-dimensional array . To use the graphics library
    StdDraw.java. Use your imagination for a better graphical
    presentation of the puzzle .
    In case the selected text-based,
    integrate your program a function
    displayPuzzle (your_parameters)
    that displays on the screen an N -puzzle with
    format given below
    graphically .

    + ----- + ----- + ----- +
    | 0 | 1
    | 5 |
    + ----- + ----- + ----- +
    | 2 |
    7 | 6 |
    + ----- + ----- + ----- +
    | 4 |
    8 | 3 |
    +
    ----- + ----- + ----- +

    After two movements :
    right - down the puzzle will have the form :

    + ----- + ----- + ----- +
    | 1 | 7 | 5 |
    +
    ----- + ----- + ----- +
    | 2 | 0 | 6 |
    + ----- +
    ----- + ----- +
    | 4 | 8 | 3 |
    + ----- + ----- +
    ----- +

    For the case presentation graphics
    program you enroll in a function
    displayPuzzleGraph
    (your_parameters) that displays on the screen an N -puzzle.
    For
    automatic selection of the game, the most appropriate choice would be any of the
    two ,
    unless , for purposes of debugging, you can view the status
    of the puzzle , and select a
    presentation format , text-based or
    graphics.

    Mode 3 ( Solution N -puzzle): The
    user has the ability to play or terminate
    operation of the game in
    INTERACTIVE game selection . Enroll in your program
    a function
    play (your_parameters) which will be called recursively and produce
    the
    next move of the game, under the regulations of the game, until the problem is
    N-
    puzzle. More specifically, when start the execution of your
    game , then the user is asked
    to enter some commands in the form :
    l (left), r (right), u (up), d (down) or
    e (exit) i.e. characters
    (l, r, u, d, e). These commands corresponding to movement
    the
    empty tile , left, right, up or down respectively. The introduction of a mandate
    to become
    means of a function getUserCommand (your parameters).

    The game should support their habits cases:
    a. Import command : If the user gives a command : l (left) then
    states that he wants to
    move the tile 0 left. Then it is checked
    if the command given by
    user is valid under the rules of the game
    ( hint: you can make a
    separate function isValidMove (your
    parameters) to do this check,
    which we call the play ()). If the
    import completes the game then the user
    must take the appropriate
    message and print the resolved N -puzzle in
    screen . If not
    completed the game then simply re- presents the N -puzzle in
    screen and the user is asked to give his next introduction .
    The
    function play () should give appropriate error messages if:
    o The
    user instructs another form or gives an invalid command eg for
    following puzzle, the command l (left) held invalid command.
    ---------------
    | 0 | 1 | 5 |
    ---------------
    | 2 |
    7 | 6 |
    ---------------
    | 4 | 8 | 3 |
    ---------------

    b. Game Stop ( command : exit): If the user
    gives a command input e (exit) then
    states that he wants to stop
    carrying the game. In this case
    interrupted the game.
    c.
    Checking Solution: One solution is correct, if the tile 0 in the lower right
    position
    the puzzle and all the tiles are arranged in ascending
    order based on the series
    the N-puzzle. eg for the above N-puzzle,
    solution would be the following N-puzzle:
    ---------------
    | 1 | 2 | 3 |
    ---------------
    | 4 |
    5 | 6 |
    ---------------
    | 7 | 8 | 0 |
    ---------------
    This control is done through a function isSolution (your_parameters)
    in
    schedule.

    d. After finding a
    solution and printed on the screen , print and other information
    eg the crowd the movements needed for the solution, the other you
    consider useful.

    Use as many
    functions as you can, apart from the ones you
    requested by the
    pronunciation . Try to use the same functions for
    The interactive
    and automatic play, to the maximum extent possible.

    it will be two java files one library and the other client.

    thank you!

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: java exercise help please

    Quote Originally Posted by javaprogr View Post
    Hi please can you see this code and tell me if it is okay with this ex ? if there are wrongs or there are parts that are not included in the code please tell me it to add them

    how i can write this differently because i have only stdin library and not that
    KeyboardInputClass PuzzleInput = new KeyboardInputClass();
    int PuzzleSize;
    PuzzleSize = PuzzleInput.getInteger(false, 8, 0, 36, "What size puzzle do you want to solve(ex: 8...15...24...35)");


    the code is
    Java Code:
    import java.util.*;
     
    public class ex
    {
        public static void main(String[] args)
        {
            //This asks the user for what size puzzle do they want to solve. 
            KeyboardInputClass PuzzleInput = new KeyboardInputClass();
            int PuzzleSize;
            PuzzleSize = PuzzleInput.getInteger(false, 8, 0, 36, "What size puzzle do you want to solve(ex: 8...15...24...35)");
     
            //This Ask the user how many times they want to shuffle the board.
            KeyboardInputClass ShuffleBoard = new KeyboardInputClass();
            int NumberOfShuffles;
            NumberOfShuffles = ShuffleBoard.getInteger(false, 0, 0, 1000, "How many times do you want to shuffle the board?");
     
            //This creates a starting puzzle and goal board (dependent on size of puzzle) in a single array then converst both to a double array.
            int[] Board = PuzzleSingleArray(PuzzleSize, NumberOfShuffles);
            int[] GoalBoard = GoalState(PuzzleSize);
            int[][] Board2D = PuzzleDoubleArray(PuzzleSize, Board);
            int[][] GoalBoard2D = PuzzleDoubleArray(PuzzleSize, GoalBoard);
     
            //This is the staring puzzle configration
            PrintPuzzle(Board2D);
             
     
            //This ask the user what algotithum they want to preform. 
            KeyboardInputClass TestInput = new KeyboardInputClass();
            char TestMethod;
            TestMethod = TestInput.getCharacter(true, 'b', "a" + "b", 0, "What Algoritum do you want to preform b = breadth-first or a = A*");
     
            PrintPuzzle(GoalBoard2D);
        }
     
        public static int[] PuzzleSingleArray(int Size, int Shuffle)
        {
            int puzzle[] = new int[Size+1];  //this makes the size of the single array
            int index;
            int Shuffles = Shuffle;  //This is the input for number of shuffles
     
            // Put all numbers into the array
            for (index = 0; index <= Size; index++)
                puzzle[index] = index;
     
            // Make random numbers
            for (int i = 0; i < Shuffles; i++)  //this for loop runs for the amount of times the user wanted to shuffle
            {
                for (index = 0; index < Size; index++)
                {
                    int randomIndex = (int)Math.floor(Math.random() * Size);
                    int temp = puzzle[index];
                    puzzle[index] = puzzle[randomIndex];
                    puzzle[randomIndex] = temp;
                }
            }
            return puzzle;
        }
     
        //load single aray into double array
        public static int[][] PuzzleDoubleArray(int Size, int[] puzzle)
        {
            int[][] board = new int[1][1];
            if (Size == 8)
            {
                board = new int[3][3];
                int k = 0;
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        board[i][j] = puzzle[k];
                        k++;
                    }
                }
                return board;
            }
            else if (Size == 15)
            {
                board = new int[4][4];
                int k = 0;
                for (int i = 0; i < 4; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        board[i][j] = puzzle[k];
                        k++;
                    }
                }
                return board;
            }
            else if (Size == 24)
            {
                board = new int[5][5];
                int k = 0;
                for (int i = 0; i < 5; i++)
                {
                    for (int j = 0; j < 5; j++)
                    {
                        board[i][j] = puzzle[k];
                        k++;
                    }
                }
                return board;
            }
            else if (Size == 35)
            {
                board = new int[6][6];
                int k = 0;
                for (int i = 0; i < 6; i++)
                {
                    for (int j = 0; j < 6; j++)
                    {
                        board[i][j] = puzzle[k];
                        k++;
                    }
                }
                return board;
            }
            return board;
        }
     
        public static int[] GoalState(int Size)
        {
            int[] Goal = new int[1];
            if (Size == 8)
            {
                Goal = new int[9];
                for (int i = 0; i < 9 - 1; i++)
                    Goal[i] = i + 1;
                Goal[9 - 1] = 0;
                return Goal;
            }
            else if (Size == 15)
            {
                Goal = new int[16];
                for (int i = 0; i < 16 - 1; i++)
                    Goal[i] = i + 1;
                Goal[16 - 1] = 0;
                return Goal;
            }
            else if (Size == 24)
            {
                Goal = new int[25];
                for (int i = 0; i < 25 - 1; i++)
                    Goal[i] = i + 1;
                Goal[25 - 1] = 0;
                return Goal;
            }
            else if (Size == 35)
            {
                Goal = new int[36];
                for (int i = 0; i < 36 - 1; i++)
                    Goal[i] = i + 1;
                Goal[36 - 1] = 0;
                return Goal;
            }
            return Goal;
        }
     
        public static void PrintPuzzle(int[][] Board)
        {
            for (int i = 0; i < Board.length; i++)
            {
                for (int j = 0; j < Board[0].length; j++)
                {
                    System.out.print(" " + Board[i][j]);
                }
                System.out.println();
            }
        }
    the exercise
    In this excercise we will deal with loops, controls
    two-dimensional tables, functions,
    formatted input / output on the
    screen. The exercise consists of multiple parts. Implement all
    parties at least two files Java, a library and a client, using
    functions. will
    start with a description of the N-Puzzle game and
    then we will present the
    requested
    Whether or not
    the game 8-puzzle, where the goal is to find a sequence movements so that from
    a
    given initial configuration of tiles on the dashboard of the
    game to reach a predetermined
    final provision. The figure below
    shows such a problem.


    note
    that the final provision the gap is always in the bottom right-hand corner of
    the dashboard (table)
    of the game. The solution of the problem can
    be described as a sequence of movements
    vacancy (i.e. replacement
    of one of the adjoining tiles). In particular, a solution to the
    above
    problem is the following:

    left, top, right, bottom,
    bottom, right

    , stating that the vacant position
    was moved six times, first to the left, then upwards etc.
    please
    note that the movement of vacancy arises essentially from the movement of a
    plate in the opposite direction. For example, when we say that the
    vacant position is moved to the left
    what is really happening is
    that the plate that was left the vacancy
    has been moved to the
    right. Similar to the problem 8-puzzle, can be used to define the problem
    15-puzzle, 24-puzzle etc. In General can be assigned a (N2
    -1)
    jigsaw puzzle, where n specifies the size of the game
    .
    is
    about this exercise is to implement a program in Java programming language
    that allows the user to play a puzzle game. N determines the size of
    the table
    N-puzzle. The program you will need to take N as a
    parameter program. We must also
    take as a parameter a number, d,
    which is a number that is associated with the presentation of the puzzle
    on
    the screen, 1 for text-based, 2 for graphics, and 0 for any of the two.
    Your
    program should implement the following functions:


    Mode 1: O user, the first step should be chosen from a menu. With the first
    option
    the menu, the user chooses the degree of difficulty k. The
    number k of times (in
    number of feasible moves) the program must
    randomly shuffle (Math.random ()) the puzzle .

    When
    mixing the puzzle , the priority of feasible movements are : left, top ,
    right
    , down, depending on the values ​​given by the random. Eg if feasible movements
    is 3 , then for
    values ​​the random [0, 0.3] move will be left for
    prices ] 0.3, 0.6 ] above, and prices ] 0.6,
    1 [right .
    After
    the program should continue implementing its functions 2 and 3, ie
    program will interact with the user , expecting him to move command
    .

    If the user selects 2, then the program
    will have to play this game
    randomly moving the tiles trying to
    find a solution. Before doing this , the program
    should ask the
    user four values:
    1. a range of values ​​for the degree of
    difficulty k, ie two values ​​kmin and kmax
    Two . Then asks him
    how many times , p, must play game for all k. In this
    case, each
    time starting a new game for the same k, the initial configuration of
    game
    should be the same . The initialization of the puzzle in the starting line to
    become
    means of a function initializePuzzleK (your parameters).
    Hint: save the original table and redo initialization this table
    before every game for the same k.
    Three . And finally ,
    apply a maximum displacements , q, for each game. If the puzzle does not
    solved
    with fewer movements than the limit q, we have failed , and begins a new
    game
    if the number of games played so far is less than p.
    4. At this
    level, we can count : the success rate of individual games for k
    e
    [kmin ... kmax]. Also , they should calculate and average movement for each
    k e [kmin ... kmax] only in case of success. With these data to
    produce two
    graphs , one showing the success rate ( in y axis )
    versus
    of k ( the x axis ) , and the other the average ( in y axis
    ) movements in
    function of k ( in y axis ) . Note : for every k e
    [kmin ... kmax], must
    using the same p , and the same q.
    5.
    Run the program , select values ​​for kmin and kmax and different values ​​for p
    and q,
    and produce the two graphs. You can do it in Excel, or
    using StdStats.java. Will announce later what values ​​will
    run
    to generate the graphs that will deliver in the end
    The menu will
    be as follows:
    1. Interactive play
    Two .
    Automatic play
    Three . Exit
    The original layout of
    the tiles before the start of an interactive game should
    represents a solved puzzle. This will produce the function
    initializePuzzle
    (your_parameters). After option 1. from the menu , the order
    changing the tiles with a function shufflePuzzle (your_parameters) (
    where
    your_parameters can be as many parameters considered
    necessary ) that will stir a
    solve
    For option
    2 . from the menu , it suffices shufflePuzzle to call once for each k, and

    then save the table to use for each k, as in Hint
    you
    give above.

    • Mode 2 (
    Showing N-puzzle): The puzzle loaded in memory is shown in
    screen
    in the form of two-dimensional array . To use the graphics library
    StdDraw.java. Use your imagination for a better graphical
    presentation of the puzzle .
    In case the selected text-based,
    integrate your program a function
    displayPuzzle (your_parameters)
    that displays on the screen an N -puzzle with
    format given below
    graphically .

    + ----- + ----- + ----- +
    | 0 | 1
    | 5 |
    + ----- + ----- + ----- +
    | 2 |
    7 | 6 |
    + ----- + ----- + ----- +
    | 4 |
    8 | 3 |
    +
    ----- + ----- + ----- +

    After two movements :
    right - down the puzzle will have the form :

    + ----- + ----- + ----- +
    | 1 | 7 | 5 |
    +
    ----- + ----- + ----- +
    | 2 | 0 | 6 |
    + ----- +
    ----- + ----- +
    | 4 | 8 | 3 |
    + ----- + ----- +
    ----- +

    For the case presentation graphics
    program you enroll in a function
    displayPuzzleGraph
    (your_parameters) that displays on the screen an N -puzzle.
    For
    automatic selection of the game, the most appropriate choice would be any of the
    two ,
    unless , for purposes of debugging, you can view the status
    of the puzzle , and select a
    presentation format , text-based or
    graphics.

    • Mode 3 ( Solution N -puzzle): The
    user has the ability to play or terminate
    operation of the game in
    INTERACTIVE game selection . Enroll in your program
    a function
    play (your_parameters) which will be called recursively and produce
    the
    next move of the game, under the regulations of the game, until the problem is
    N-
    puzzle. More specifically, when start the execution of your
    game , then the user is asked
    to enter some commands in the form :
    l (left), r (right), u (up), d (down) or
    e (exit) i.e. characters
    (l, r, u, d, e). These commands corresponding to movement
    the
    empty tile , left, right, up or down respectively. The introduction of a mandate
    to become
    means of a function getUserCommand (your parameters).

    The game should support their habits cases:
    a. Import command : If the user gives a command : l (left) then
    states that he wants to
    move the tile 0 left. Then it is checked
    if the command given by
    user is valid under the rules of the game
    ( hint: you can make a
    separate function isValidMove (your
    parameters) to do this check,
    which we call the play ()). If the
    import completes the game then the user
    must take the appropriate
    message and print the resolved N -puzzle in
    screen . If not
    completed the game then simply re- presents the N -puzzle in
    screen and the user is asked to give his next introduction .
    The
    function play () should give appropriate error messages if:
    o The
    user instructs another form or gives an invalid command eg for
    following puzzle, the command l (left) held invalid command.
    ---------------
    | 0 | 1 | 5 |
    ---------------
    | 2 |
    7 | 6 |
    ---------------
    | 4 | 8 | 3 |
    ---------------

    b. Game Stop ( command : exit): If the user
    gives a command input e (exit) then
    states that he wants to stop
    carrying the game. In this case
    interrupted the game.
    c.
    Checking Solution: One solution is correct, if the tile 0 in the lower right
    position
    the puzzle and all the tiles are arranged in ascending
    order based on the series
    the N-puzzle. eg for the above N-puzzle,
    solution would be the following N-puzzle:
    ---------------
    | 1 | 2 | 3 |
    ---------------
    | 4 |
    5 | 6 |
    ---------------
    | 7 | 8 | 0 |
    ---------------
    This control is done through a function isSolution (your_parameters)
    in
    schedule.

    d. After finding a
    solution and printed on the screen , print and other information
    eg the crowd the movements needed for the solution, the other you
    consider useful.

    • Use as many
    functions as you can, apart from the ones you
    requested by the
    pronunciation . Try to use the same functions for
    The interactive
    and automatic play, to the maximum extent possible.

    it will be two java files one library and the other client.

    thank you!
    how i can write this differently because i have only stdin library and not that
    KeyboardInputClass PuzzleInput = new KeyboardInputClass();
    int PuzzleSize;
    PuzzleSize = PuzzleInput.getInteger(false, 8, 0, 36, "What size puzzle do you want to solve(ex: 8...15...24...35)");
    Do you have the API doc for the KeyboardInputClass? For example what does the getInteger() method return?
    Last edited by Norm; 11-16-2013 at 07:32 PM.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    javaprogr is offline Member
    Join Date
    Nov 2013
    Posts
    6
    Rep Power
    0

    Default Re: n-puzzle help program

    Yes how i can do that automatic play of computer and how i can write this differently because i have only stdin library and not that
    KeyboardInputClass PuzzleInput = new KeyboardInputClass();
    int PuzzleSize;
    PuzzleSize = PuzzleInput.getInteger(false, 8, 0, 36, "What size puzzle do you want to solve(ex: 8...15...24...35)");

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: n-puzzle help program

    It looks like the getInteger() method asks a question of the user, gets his response and returns its int value.
    The println() method could show the question and the Scanner class has methods to read the response.
    Or you could use one of the JOptionPane class's methods to do that.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    javaprogr is offline Member
    Join Date
    Nov 2013
    Posts
    6
    Rep Power
    0

    Default Re: n-puzzle help program

    Quote Originally Posted by Norm View Post
    It looks like the getInteger() method asks a question of the user, gets his response and returns its int value.
    The println() method could show the question and the Scanner class has methods to read the response.
    Or you could use one of the JOptionPane class's methods to do that.

    hi what do you mean change the getinteger() to println() okay but the scanner where to put that?
    i have the scanner library

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: n-puzzle help program

    Write your own getInteger() method in your class to ask the user a question, get his response, convert it to int and return it.
    Use println() to ask the question.
    Use a Scanner class method to read the response and convert to an int
    return the int.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Peg Puzzle Solver GUI
    By Harlow777 in forum SWT / JFace
    Replies: 2
    Last Post: 11-11-2013, 04:48 PM
  2. Puzzle Program
    By CG9892 in forum New To Java
    Replies: 13
    Last Post: 11-28-2012, 05:00 PM
  3. Crossword PUzzle Help Please
    By Sapana in forum New To Java
    Replies: 3
    Last Post: 11-16-2011, 10:24 PM
  4. N-Puzzle Help!
    By evan42781 in forum New To Java
    Replies: 12
    Last Post: 04-30-2009, 12:34 AM
  5. Need help with Trees...(8-puzzle)
    By ventrue in forum New To Java
    Replies: 2
    Last Post: 03-24-2009, 12:04 AM

Tags for this Thread

Posting Permissions

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