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 14 of 14

Thread: Important need some guidance & tips/tricks!

  1. #1
    Member
    Join Date
    Aug 2013
    Location
    Netherlands
    Posts
    38
    My Mood
    Inspired
    Thanks
    1
    Thanked 1 Time in 1 Post

    Question Important need some guidance & tips/tricks!

    Hi there,

    Let me explain the situation. Hope you have some time to look through this article. I am working on a chess manager programmer this program contains a chessboard with chesspieces and with a FEN-notation you can replace the pieces on the board to get a different result/situation. A FEN-notation looks like this:

    rnbqrbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR

    the small characters represent the black pieces
    r = rook
    n = knight
    b = bishop
    q = queen
    k = king
    p = pawn

    / = break, it means next row.

    8 = Eight empty squares in a row

    the capital characters represents the white pieces.

    pieces.jpg

    the following image shows the chess manager program:
    Screen Shot 2013-08-10 at 1.37.31 PM.jpg

    As you can see it contains a empty board which is only a jpanel with gridbaglayout so no model! I need to place the pieces on the board but they when i change the FEN-notation you get a different result the pieces move on the board

    Like rnbqrbnr/pp1ppppp/2p5/8/8/2N5/PPPPPPPP/R1BQKBNR

    So the letters of the FEN-notation needs to hold a image of the chesspiece i all ready have the images in a map called assets
    I am working with the MVC principal model view controller. The view is separated from the model.

    My question is can you point me in the right direction: which classes do i need, which technique do i use to get a letter r or R to contain a ImageIcon like hashmap or someting, how to display it on the screen. how to make the board work with the FEN-notation if i change the notation press enter the pieces(imageicon) move to the right square(there are 64 squares), shall i name the squares like A1, A2, B1 etc. do i need classes FEN which contains the notation, classes like square and/or board in the model package

    i really need help and hope someone can give me a lot and the right information. Thanks in advance


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,329
    My Mood
    Mellow
    Thanks
    253
    Thanked 781 Times in 766 Posts

    Default Re: Important need some guidance & tips/tricks!

    So the letters of the FEN-notation needs to hold a image of the chesspiece
    What does this mean? Letters don't hold images. They may represent images. In that case . . .

    It seems to me that the FEN notation describes each square of the chessboard. Why not just "read" the FEN notation and draw the chess pieces on the board? Have you ever written a command line parser or similar? It seems something like that would be the answer here.

    But maybe I don't understand the problem.

  3. #3
    Member
    Join Date
    Aug 2013
    Location
    Netherlands
    Posts
    38
    My Mood
    Inspired
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Important need some guidance & tips/tricks!

    Yes i want a letter rnbqkbnr/pppppppp the black pieces and PPPPPPPP/RNBQKBNR the white pieces to represent a image(ImageIcon) the ones you see in link above. So when i start the program you see a default chess position and when i change the FEN-notation to a correct notation and press enter the image moves on the bord to the right square. My question is which techniques do i use and which classes do i need

    additional: 8 stands for 8 empty squares when i change the FEN notation like a move a pawn - rnbqrbnr/pp1ppppp/2p5/8/8/8/PPPPPPPP/RNBQKBNR (correct FEN notation) the p which represent a black pawn image moves to the right square on the board. So i need a board with 64 squares which classes board, square, pieces, fennotation?

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,329
    My Mood
    Mellow
    Thanks
    253
    Thanked 781 Times in 766 Posts

    Default Re: Important need some guidance & tips/tricks!

    Suggestions based on random thoughts:

    Create a ChessPiece class that includes, name/type, color, location, and anything else you want. A chess game includes 32 chess pieces.

    You'll need a FEN parser that accepts, validates, translates, and then creates commands to the class that draws the pieces on the chessboard. In addition to validating each FEN, it will need to validate that one FEN can legally follow another.

    That should keep you busy for a while.

  5. #5
    Member
    Join Date
    Aug 2013
    Location
    Netherlands
    Posts
    38
    My Mood
    Inspired
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Important need some guidance & tips/tricks!

    And a board class? the board drawn on the image above is just a gridlayout with the empty squares. When a piece moves the square the piece was standing on becomes empty. And what do you mean with location? and fen parser class? is that a system.in

  6. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,329
    My Mood
    Mellow
    Thanks
    253
    Thanked 781 Times in 766 Posts

    Default Re: Important need some guidance & tips/tricks!

    Location: Each chess piece may know where it is on the board. The locations on a chessboard are easily represented by a 2D array.

    ChessPiece: You might also want to include a list of possible next moves to help with the FEN parser validation.

    Board class: A board class is a collection of locations on the board and may or may not be necessary. Having a Location class (with a better name) that describes each of the 64 locations on the board may be sufficient. The location instance would include whether there was a chess piece on it, empty, etc.

    FENParser/System.in: It's not clear to me where the FEN exists, but I don't think it would be in a console window read by System.in. If the users enter or read the FEN, then I expect it would be in a JTextField or JTextArea. The FEN parser would be fed the input from wherever it comes and then do its parsing thing.

    I wonder if the users have anything to do with FEN. It's a graphical program. Don't they move the chess pieces around the board with a mouse? The graphical move would then cause the board's state to change which could then be described by FEN.

    These are the kinds of program design considerations you need to think through completely. Write down your initial thoughts and assumptions as completely as you can. As the thoughts and ideas collect, there will be conflicts, unexpected effects on each other, resulting compromises, and new ideas. As the design gels, you should write down the results as specs to work to. You can document them directly in your code or create a separate living document that you can work from while you code.

    At least, that's how I do it. I keep my programming ideas in a location that I can access at any time, no matter where I am, so that I can document new ideas and consider impacts. Depending on what I'm doing or how busy I am, I often think about a new project, documenting my thoughts, for weeks before writing any code. I start coding when I have a spec I think is fairly complete and thought through completely from beginning to end. There are always surprises and things I didn't think of, but they're much easier to deal with.

  7. #7
    Member
    Join Date
    Aug 2013
    Location
    Netherlands
    Posts
    38
    My Mood
    Inspired
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Important need some guidance & tips/tricks!

    At least, that's how I do it. I keep my programming ideas in a location that I can access at any time, no matter where I am, so that I can document new ideas and consider impacts. Depending on what I'm doing or how busy I am, I often think about a new project, documenting my thoughts, for weeks before writing any code. I start coding when I have a spec I think is fairly complete and thought through completely from beginning to end. There are always surprises and things I didn't think of, but they're much easier to deal with.
    Thats very helpfull i use dropbox for that so i can access the code anytime.

    But i dont have to make a interactive chessboard. "Move the pieces around with a cursor". I want the user to type in a FEN-notation rnbqrbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR "default position" this is the position on the bord when the program starts or a new file is made

    For instance the user types in his own FEN-notation and the pieces on the board move so they represent the FEN-Notation. the board is not interactive it just show the pieces on the board. if the FEN-Notation is changed for instance a pawn low p "black pawn" is replaced the graphical board shows the pawn on that position rnbqrbnr/pp1ppppp/2p5/8/8/8/PPPPPPPP/RNBQKBNR (correct FEN notation) what do i need for this.

  8. #8
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,329
    My Mood
    Mellow
    Thanks
    253
    Thanked 781 Times in 766 Posts

    Default Re: Important need some guidance & tips/tricks!

    I think you just need to quit asking, "What do I need?" and get to work.

  9. #9
    Member
    Join Date
    Aug 2013
    Location
    Netherlands
    Posts
    38
    My Mood
    Inspired
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Important need some guidance & tips/tricks!

    Anyone know a good technique to make a chessboard? which contains squares. An array is not possible since it can not contain objects. I need 64 square objects in a collection which one? i also make a different collection for the chesspieces i use a set. Anyone suggestion for the squares dont need more than 64 or has some a different approach? i have also imageicon for the empty squares thats why i make square objects.

  10. #10
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,329
    My Mood
    Mellow
    Thanks
    253
    Thanked 781 Times in 766 Posts

    Default Re: Important need some guidance & tips/tricks!

    Where do you get this stuff?

    Arrays can contain objects. There are other collections, ArrayLists, etc. that can also contain objects.

  11. #11
    Member
    Join Date
    Aug 2013
    Location
    Netherlands
    Posts
    38
    My Mood
    Inspired
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Important need some guidance & tips/tricks!

    Oke! and maybe as you pointed earlier its good to use locations for the chess like a1 b1 c1 etc.. how can i do this the best make an array with these values.

    --- Update ---

    Okay so i want to make an ArrayList<Square> which contains square objects. This square object contains a string which represent the location. Is there a way to make the following easier instead of using the operator new each time i want to add a new square object.

            locations.add(new Square("A1"));
            locations.add(new Square("B1"));
            locations.add(new Square("C1"));
            locations.add(new Square("D1"));
            locations.add(new Square("E1"));
            locations.add(new Square("F1"));
            locations.add(new Square("G1"));
            locations.add(new Square("H1"));
    // this needs to be done 64 times. Is there an easier way?

  12. #12
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,329
    My Mood
    Mellow
    Thanks
    253
    Thanked 781 Times in 766 Posts

    Default Re: Important need some guidance & tips/tricks!

    Of course there is an easier way, and you should know it to be doing this project. You don't seem ready for this project. You're missing basic understanding of foundational things like for loops, nested for loops, multi-dimensional arrays (could be useful), etc. You will be unlikely to find someone who will (try to) teach you all of this stuff and hold your hand while you misapply what you've barely learned to this program.

  13. #13
    Member
    Join Date
    Aug 2013
    Location
    Netherlands
    Posts
    38
    My Mood
    Inspired
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Important need some guidance & tips/tricks!

    Can you be more positive since i am trying to learn.. dont think there are stupid questions only the dumb answer is what make people uncertain

  14. #14
    Member
    Join Date
    Aug 2013
    Location
    Netherlands
    Posts
    38
    My Mood
    Inspired
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Important need some guidance & tips/tricks!

    why do i get this error:

    Exception in thread "main" java.lang.NullPointerException
    at view.ChessBoardView.<init>(ChessBoardView.java:38)
    at controller.Controller.makeFrame(Controller.java:43 )
    at controller.Controller.<init>(Controller.java:24)
    at controller.Main.main(Main.java:9)

    i am really sure i made all the objects
    package view;
     
    import java.awt.*;
     
    import javax.swing.BorderFactory;
    import javax.swing.ImageIcon;
    import javax.swing.JPanel;
    import javax.swing.JLabel;
     
    import controller.Controller;
    import model.ChessBoard;
    import model.Square;
     
    public class ChessBoardView extends JPanel
    {
        private final static ImageIcon DARK_BROWN = new ImageIcon 
        (ChessBoardView.class.getResource("assets/sqb.gif"));
        private final static ImageIcon LIGHT_BROWN = new ImageIcon 
        (ChessBoardView.class.getResource("assets/sqw.gif"));;
     
        private ChessBoard chessboard;
     
    	public ChessBoardView (Controller controller)
        {
     
    		chessboard = new ChessBoard();
            Dimension boardSize = new Dimension(200, 200);
     
            setLayout( new GridLayout(8, 8) );
            setPreferredSize( boardSize );
            setBounds(10, 10, boardSize.width, boardSize.height);
            setBorder(BorderFactory.createLineBorder(Color.BLACK));
     
            JPanel board = new JPanel(new BorderLayout());
        	super.add(board);
     
            for (Square square: chessboard.getAllSquares()){
            	if(square.getColor().equals("BROWN")){
            		board.add(new JLabel (DARK_BROWN));
            	}
            	else if(square.getColor().equals("WHITE")){
            		board.add(new JLabel (LIGHT_BROWN));
            	}
            }
         }   
     }

    the problem is when i run my program i looks for the main, it tries to start the program i see the java icon it quits after 3 sec and in eclipse it shows the error written above

    for (Square square: chessboard.getAllSquares()){
            	if(square.getColor().equals("BROWN")){
            		board.add(new JLabel (DARK_BROWN));
            	}
    in the for-loop the chessboard.getAllSquares() return an ArrayList<Square> with all squares but why is it keep saying
    NullPointerException
    Exception in thread "main" java.lang.NullPointerException
    at view.ChessBoardView.<init>(ChessBoardView.java:38)
    at controller.Controller.makeFrame(Controller.java:43 )
    at controller.Controller.<init>(Controller.java:24)
    at controller.Main.main(Main.java:9)

Similar Threads

  1. HIBERNATE & JPA GUIDANCE NEEDED
    By Rituparna in forum JDBC & Databases
    Replies: 0
    Last Post: September 3rd, 2011, 04:54 AM