Rule base for graphical editor / simulator
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.
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
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. :o
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.
Originally Posted by copeg
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).
Break the problem down into its individual requirements.
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?
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.
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.
the move validations
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.
You can then plug this into each piece dependent upon what you wish to validate and how you wish to evaluate it.
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?
This will decouple the actual 'piece' object from the behavior. You can then implement the interface/behavior however you wish.
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.
for something like a chessboard different lookup tables for each behavior might do the trick
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.