3/21/10

Limited undo & rule implementation (1)

As mentioned few days ago, it's not a good idea that allow players to undo each move they made. Since Java doesn't support infinite memory allocation neither other languages. Thus, I modified a piece of code, then each player only can undo 10 previous moves from now on.

Here is a link to Wikipedia page that talked about Xiangqi including its rule. I need to make a statement about rule of General. The original text is:

The general starts the game at the midpoint of the back edge (within the palace). The general may move one point either vertically or horizontally, but not diagonally. A general cannot move into a file which is occupied by the enemy general unless there is at least one piece positioned between the generals in the file. The general may not leave the palace.

In fact, in Chinese version of the rule, two generals may face to face. But, in such case, one general can leave the palace and attack another general directly. In other word, a general can move into a file which is occupied by the enemy general. In this case, the enemy general can attack your general directly. So, when you try to make a general move, be careful this case. In my implementation, I'll follow Chinese version of the rule for generals.

Above figure shows possible moves of red general. Since both right and left sides of the red general are red guards. Thus, its possible moves are one point forward and the black general's position.

At this point, rules for general, guard and elephant are done.


No comments:

Post a Comment