题目的意思在于,更高效的Collect Gold;然后合理的安排生产出来的士兵;
我对战的是简单的电脑
// This code runs once per frame. Build units and command peasants! // Destroy the ogre base within 180 seconds. // Run over 4000 statements per call and chooseAction will run less often. // Check out the green Guide button at the top for more info. var base = this; /////// 1. Command peasants to grab coins and gems. /////// // You can only command peasants, not fighting units. // You win by gathering gold more efficiently to make a larger army. // Click on a unit to see its API. var items = base.getItems(); var peasants = base.getByType(‘peasant‘); for (var peasantIndex = 0; peasantIndex < peasants.length; peasantIndex++) { var peasant = peasants[peasantIndex]; var item=null; for(var i=0;i<items.length;i++) { if(items[i].type==‘gem‘) { item=items[i]; } } if(!item) for(i=0;i<items.length;i++) { if(items[i].type==‘gold-coin‘) { item=items[i]; } } if(!item) for(i=0;i<items.length;i++) { if(items[i].type==‘coin‘) { item=items[i]; } } //var item = base.getNearest(items); if (item) base.command(peasant, ‘move‘, item.pos); } /////// 2. Decide which unit to build this frame. /////// // Peasants can gather gold; other units auto-attack the enemy base. // You can only build one unit per frame, if you have enough gold. var type; if (base.built.length === 0) type = ‘peasant‘; else type = ‘knight‘; var knights = base.getByType(‘knight‘); //type=‘soldier‘; if(knights.length>=2&&peasants <=4) { type=‘peasant‘; } if (base.gold >= base.buildables[type].goldCost) base.build(type); // ‘peasant‘: Peasants gather gold and do not fight. // ‘soldier‘: Light melee unit. // ‘knight‘: Heavy melee unit. // ‘librarian‘: Support spellcaster. // ‘griffin-rider‘: High-damage ranged attacker. // ‘captain‘: Mythically expensive super melee unit. // See the buildables documentation below for costs and the guide for stats.
时间: 2024-10-05 09:25:38