Procedural algorithm vs object base algorithm
i'm a student in a hong kong institution. And i'm using java to write a mutiple player card game as my final year project.
My supervisor suggest me to think about using a object base or a database to store the game rules: i.e. the algorithm to store the rules.
However it is really odd to me, becauese when doing some card comparison,let say the player check if his card set is bigger than the other player,i will simply think about a method which receive the other player cardset and do the camparison in the method and then return a true or false value.
With my supervisor suggestion, now i try to think about storing the comparsion in a database or a object call GameRules which embed the algorithm.
For the object base approach i have some idea about it advantage e.g. the GameRules object could be implement or extends for other kinds of game.
But the database approach i really can not imagine.......
I would like to discuss the topic with you, so that i can learn from you all.
[1029 byte] By [
horman_wa] at [2007-9-27 23:20:57]

> the GameRules object could be implement or extends for other kinds of game.
Correct. And you only need to replace the GameRules Object, recompile and run your application.
The idea of the database approach is to be able to change the rules of the game without recompiling, or even on the fly, while running the game.
This gives you the maximum flexibility, but of course you will pay for this with a more complicated application.
> My supervisor suggest me to think about using a object
> base or a database to store the game rules: i.e. the
> algorithm to store the rules.
Isolating the game logic makes sense. Expanding your program to incorporate new games will then be easy. If of course the game logic is sufficiently generalized to begin with. Maybe your supervisor wants you to review your application design. To isolate and generalize the game logic part of the program.
uja at 2007-7-7 15:24:12 >

An algorithm is an algorithm. An object base or a database are just different ways of implementation. While it may be a useful exercise to implement the same algorithm in different ways, I'd suggest differentiating between algorithm and implementation.
However its implemented, the rules to a game ultimately must be a form of code. The code may look like data, but the difference between code and data is a matter of perspective. Perhaps you can create an interpreted language to express your game rules, and snippets of that language can be stored in a database? This may or may not make sense for your project.
To put it technically the Game Rules detail game state legality and game state changes as a result of a "move" in the game.
The Rules are generally detailed individually with references to other Rules.
It should be possible to abstract out a Rule, a State interface, StateChangeEvent and StateChangeListener interface/abstract classes.
A game turn consists of an attempt to change the current State of the game. This change can trigger StateChangeEvents, StateChangeListeners can be used to apply appropriate Rules to those changes. A Rule can result in the change being declared illegal, a further change in the game State being made (leading to further events etc) or both.
A generic way to apply rules is also needed as otherwise (basically which Rules a StateChangeListener should do apply for a given StateChangeEvent. This is more trivial than it sounds fortunately.
An interesting twist to the use of a Database to store the rules is in how you do it.
Python (scripting language) can also run in a Java environment as a Jython Script. Now these Jython scripts are simply text, therefore Strings. Now you can store the rules in a database, query for the script you want to run and run the script on the fly. The integration of Java objects into Jython is trivial as well.
Go look at www.jython.org