New version of source code: http://www2.hawaii.edu/~sz/ics613/sz_v3.zip
After studying the score rules and testing codes from UCSD Spring 2004 Programming Contest. I made a lot of changes in my strategy.
Strategy of Knight:
By testing the codes of XXX_420_XXX, the second place of UCSD Spring 2004 Programming Contest, I surprisingly discover how excellent a simple brainless strategy can perform. Its idea is very simple: capture the nearest castle. It doesn't even group up knights when attack or annihilate enemy units when captured all castles. It just let every knight attack the castle that is nearest from it and let them stand still while all castles are captured. However, in most of the test matches, it does succeed to capture all castles! No one can ever beat it in castle capturing, though its stupid stand still method makes it some trouble because it doesn't notice when enemy knights are kill its peasants, as long as they don't capture castle.
Therefore, I decide to switch my strategy to a similar one: capture the nearest castle and annihilate enemy units when all castles are captured. That works pretty good. It acts just like a blitz, and is able to take all the castle within 150 turns when fight with samples! (500 turns per match)
I think one of the reason to its success is that it naturally separates its force in groups that maximum the possibility of surviving in raids and efficiency of capturing castles. The success of such simple idea is amazing.
I have also test the code of champion of UCSD Spring 2004 Programming Contest, its AI is much better. It will score every castle depend on the distance and nearby defence and select the best one to attack. It sounds nice, but it doesn't work so well in my test. One of the reason is its knights seems hesitant when selecting target, and this makes the capture procedure much slower.
Perhaps, to be simple is just a good idea.
Strategy of producing:
By studying the score rules, I found a key of getting high score when winning the match. That is to produce knight rather than peasant when your peasants are enough. The reason is, a knight scores 2 and a peasant only scores 1 at the end of the match. And, you don't need to continue to create peasants in order to claim all land. As I tested, even 40 peasants will be enough to claim more than 4000 land. So I continue to produce knights when I have 50 peasants. It just likes a cheat! I increase my winning score by 400 by just adding such simple expressions! That makes me possible to win the highest score event in case that I lost over a half of matches, and guarantees me the champion as long as I win a half of matches.
Strategy of peasant:
Nothing special. I just extended the searching area when choosing directions to improve the efficiency of claiming land.