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

Thread: Rule base for graphical editor / simulator

  1. #1
    Member
    Join Date
    Nov 2010
    Location
    New Zealand
    Posts
    32
    Thanks
    3
    Thanked 4 Times in 4 Posts

    Lightbulb Rule base for graphical editor / simulator

    Dear friends,


    This is a big question. Please bear with me.


    I'm working on a complex editor / simulator program that allows to manipulate and extend structures of shapes in a two dimentional plane. It's a bit like moving pawns on a checkers board. I'm not writing a checkers game, but it is a convenient way to describe it partly.

    The 'pawns' can be added, deleted and moved between fixed locations on the board: above each other and next to each other. The locations, both absolute on the board, and relative to the other pawns, are important. Spaces between the pawns are too.

    In the model of my MVC-type program, there are several attributes related to the location of the pawns. For instance, there is an attribute that specifies whether a pawn is part of a column of four. Another one if this pawn is the first of a horizontal line. It's really much more complex than that, but this is to give you an idea.

    This program should analyse the validity of a pawn each time it is given a new location. This validity is based on the structure (with some other pawns) it is part of. Let's say for example that pawns may not be placed in diagonal lines, then whenever some pawn is given a new location the program has to color the pawn green if it is part of a horizontal or vertical line, and red if it is part of a diagonal structure. Again, the rules are much more complex than this in reality.

    A second requirement, as if this wasn't enough, is that this program should provide suggestions of structures. As an example, a rule might be that lines are to be 5 pawns log. If there is already a short line of three pawns, the program should, if asked, propose to place two pawns next two the three already on the board. And since nothing is specified where this line is supposed to start, it should propose this solution at each side of the existing line, and a third solution with one pawn on each side.

    I've come up with a simple graphical interface that allows me to manipulate the pawns. The hard part is to create a rule base that tests the validity of these postions, and to fill menu's with valid suggestions. I thought that the attributes ("... is part of a horizontal line", "... is above a pawn", ...) should be represented by classes, or perhaps enumerations. More than one pawn can be part of the same instantiation (example if they are all part of the same line) and a single pawn can be part of several objects (it can be part of a column and of a line). A pawn can be part of more objects of the same type too (if seven pawns sit next to each other in a line, then the center pawns are part of more than one 5-piece row).


    <sigh> How do I set this up? Where do I begin? Is there any type of theory that could tackle this problem? Are there existing game simulators ('go' perhaps) that use a rule base similar to this?

    Unfortunately the real purpose of this program I can not explain. It's an idea that may be original and I don't want to risk someone steeling it. I'm sure a lot of people can write this thing over a long weekend.

    If you have any clue, any piece of information, any url that could help me, please let me know. If you know a colleague who pretends to know everything, or a professor who is exceptionally smart, please show them this post. Any lead that could help me would be tremendously appreciated.


    Thanks,

    Alice


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Rule base for graphical editor / simulator

    I'm not sure I fully understand the problem, and whether this is a design or implementation question. Break the problem down into its individual requirements. I'll give you my thoughts on the design of the move validations: write an interface which provides the ruling. You can then plug this into each piece dependent upon what you wish to validate and how you wish to evaluate it. This will decouple the actual 'piece' object from the behavior. You can then implement the interface/behavior however you wish. How you go about validation is highly dependent upon how things are modeled - for something like a chessboard different lookup tables for each behavior might do the trick

  3. #3
    Member
    Join Date
    Nov 2010
    Location
    New Zealand
    Posts
    32
    Thanks
    3
    Thanked 4 Times in 4 Posts

    Default Re: Rule base for graphical editor / simulator

    Hello copeg, thanks so much for answering this. I've been watching this topic like a mother hen over her chicks.

    Quote Originally Posted by copeg View Post
    I'm not sure (...) whether this is a design or implementation question
    At this point it is design. If you have a solution in another language or in UML, that would be great to start with. On this particular problem I stand nowhere.

    Break the problem down into its individual requirements.
    You mean split up the editor from the simulator? The way I see it the validation system stands over both. It will color the pawns when a new postion is selected, and the combo box or menu of suggestions will be filled by this same validation system. Of course I'll have to start with the coloring, but I would like to build this system so that it can later on be used as is to implement the suggestions generator (simulator).

    I'll give you my thoughts on the design of the move validations: write an interface which provides the ruling. You can then plug this into each piece dependent upon what you wish to validate and how you wish to evaluate it.
    It sounds like you're on to something. Could you elaborate a bit around it, please? I know interfaces like mouse handler interfaces, but more than that it's a bit fuzzy. You wouldn't have a url towards an example by any chance?

    the move validations
    After rereading this, I'd like to clarify something. The 'move' does not need to be validated. Only the new position. It doesn't matter where the pawn comes from that is important. Only the position it occupies. Like I said, it's not a game, like chess or checkers, where you can make illigal moves. It's more a bit like a magnet structure, where opposing poles will not stick together.

    You can then plug this into each piece dependent upon what you wish to validate and how you wish to evaluate it.
    There is only one type of pieces. However, depending where they are located, different rules apply. To use the magnet analogy: if you place a magnet next to another, it will react differently than when you place it by itself.

    This will decouple the actual 'piece' object from the behavior. You can then implement the interface/behavior however you wish.
    A friend of mine, whom I haven't seen in a while, once talked about test case rules. I didn't understand it at the time, but he told me to write rule classes for every normal class in the model. Would that make sense?

    for something like a chessboard different lookup tables for each behavior might do the trick
    Lookup tables would be very interesting actually. There are so many rules, described in lots of different books, that I'd need a convenient way to implement them one after the other and test them thoroughly.

    Is there a (Java) source code available online for a chess game implemented this way?

    Sorry for the many questions. If anyone can answer only one of these, please do. I'm very passionate about this particular subject. Thank you in advance.

    Alice
    Last edited by Alice; December 18th, 2010 at 10:42 AM.

Similar Threads

  1. Java tip Dec 12, 2010: Useful rule tidbits for ANTLR
    By helloworld922 in forum Java Programming Tutorials
    Replies: 1
    Last Post: December 16th, 2010, 12:24 PM
  2. IDE (Visual Editor)
    By bbr201 in forum Java Theory & Questions
    Replies: 5
    Last Post: August 7th, 2010, 12:33 PM
  3. need API for Connection Routing in Interactive Diagram Editor
    By pavan arepu in forum AWT / Java Swing
    Replies: 2
    Last Post: April 21st, 2010, 10:19 AM
  4. Help!how to get a graphical display of this game
    By makarov in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 17th, 2009, 11:15 AM
  5. JAVA simulator
    By YAS218 in forum Java Theory & Questions
    Replies: 8
    Last Post: July 20th, 2009, 09:57 AM

Tags for this Thread