Friday, August 31, 2007

CodeRuler Review

I have reviewed Ben Karsin's code of CodeRuler from http://bkarsin.blogspot.com/2007/08/coderuler-may-best-bot-win.html. His AI strategy and algorithm is fantastic and his code is well written. His score system in direction decision is a very good idea. However, it seems a little bit too intelligent.
The first obvious problem is that his peasant will go up and down in a couple of fields when nearby fields are all claimed. It can be fixed simply by adding a random mechanism when all directions score the same.
The second problem is a bug that when his knight trace chased enemies' peasant to the world's angle, it will stop a block away from the target without attacking it. I don't know what's going wrong in the algorithm. This bug needs to be fixed.
The third one, which I think is most important, is a question about knight strength. In Ben Karsin's Ruler, knight runs away when its strength goes down to a degree. This strategy does protect knight from being killed, but it significant reduces the usable power of knight. Because when a knight runs for live when its strength goes below, for example, 10%, that means only 90% of a knight's power is usable. Although run-away knights can go to capture enemy knight, it makes enemies' knight able to attack anything as they wish, such as castle. In my opinion, warrior is honored to die in the battlefield bravely. So I don't agree in run-away strategy. Maybe let one or two knights go to capture enemies' peasant when strength gets low is OK, but most of the knight should fight to death.

Following is the summary of violations in the code.

Summary of violations

FileLinesViolationComments
MyRuler.java16,29,30,*ICS-SE-Eclipse-2Code indented 3 spaces or tab, not 2 throughout.
MyRuler.java16,29,138,*EJS - 7 Lack of space between operations and parenthesis.
MyRuler.java104,106EJS - 76 Use experssion instead of block statement.
MyRuler.java114,116EJS - 5 '{' in a new line, not in the last of upper line.
MyRuler.java181,182,183EJS - 6 Lines too long.
MyRuler.java142,196,276EJS - 9 Do not use a meaningful name.
MyRuler.java74,81,90,*EJS - 37 Used C-sytle comments to explain implementation, not one-line comments
MyRuler.java250N/AThe first if statement contains a blank expression, though is not prohibited by the rules, it made me somewhat confused.
MyRuler.java224,50,54,*EJS - 7 no blank lines to seperate each member of the class

No comments: