首页 > 代码库 > CodeCombat多人游戏Greed
CodeCombat多人游戏Greed
题目的意思在于,更高效的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.
CodeCombat多人游戏Greed
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。