Wednesday, September 5, 2007

08. CodeRulerRedux

Group members: Michal Zielinski & Chiao-Fen Zielinski-Liu

Source Code: Please click here to download

This time we had more time to think about a better strategy for our CodeRuler project. After reading other classmates' code we found a better way to claim land. Jared has an interesting loop in his CodeRuler code that loops through the whole grid starting in the left upper corner. We implemented a similar strategy. However, we divide the grid into four equal squares and assign peasants to each square. Since the fourth square gets less peasants and therefore they cannot finish claiming all the land, once the peasants in the first square finish claiming the land we assign them to help peasants in the fourth square. In the meantime, our knights are instructed to capture all castles that we don't own and anything that is in their way. After that the knights will capture all enemy peasants. When all enemy peasants are captured the knights go on to capture the enemy knights. We instruct our knights to capture all the castles first in order to be able to create more knights when needed in the battle with other knights. Therefore, peasants are only created when we have twice as many knights as other knights or when we don't have any peasants. This strategy works out pretty good against all the sample rulers. We were also able to include Java Documentation and Coding Standards in our CodeRuler source code which makes our code more readable and understandable to another reader.

This are the result runs:


Result 1Result 2Result 3
michalz-chiaofen vs. migrate ruler854 - 0
827 - 1
833 - 0
michalz-chiaofen vs. gang up ruler782 - 184
784 - 140
553 - 399
michalz-chiaofen vs. split up ruler725 - 256
733 - 230
748 - 182

Writing this code gave me a chance to become more familiar with the Java Documentation and Coding Standards which I learned by reading "The Elements of Java Style". I must say that it is not very easy to follow exactly what the book says since it doesn't have enough examples of certain rules. Hopefully, as this class goes along, I will be able to write code with perfect documentations.