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 i1=0,i2=0,i3=0,i4=0;var n; var j=0;//对所有的钱分类排序的时候使用的 var items = base.getItems(); var item=null; var peasants = base.getByType('peasant'); var tempItems=items;//缓存,用来记录宝石和金银币铜币 for(var i=0;i<items.length;i++)//宝石放在最前面 { if(items[i].type=='gem') { i1++; tempItems[j++]=items[i]; } } for(i=0;i<items.length;i++)//金币第二 { if(items[i].type=='gold-coin') { i2++; tempItems[j++]=items[i]; } } for(i=0;i<items.length;i++)//银币第三 { if(items[i].type=='coin') { if(items[i].value===2) { i3++; tempItems[j++]=items[i]; } } } for(i=0;i<items.length;i++)//铜币第三 { if(items[i].type=='coin') { if(items[i].value===1) { i4++; tempItems[j++]=items[i]; } } } items=[];//清空数组 if(i1>=peasants.length)//宝石的数量>=捡钱兵种的数量 { for(i=0;i<i1;i++) { items[i]=tempItems[i]; } } else//宝石的数量<捡钱兵种的数量 { if(i1+i2>=peasants.length)//宝石的数量+金币的数量>=捡钱兵种的数量 { for(i=0;i<i1+i2;i++) { items[i]=tempItems[i]; } } else//宝石的数量+金币的数量<捡钱兵种的数量 { if(i1+i2+i3>=peasants.length)//宝石、金币、银币的数量>=捡钱兵种的数量 { for(i=0;i<i1+i2+i3;i++) { items[i]=tempItems[i]; } } else//宝石、金币、银币的数量<捡钱兵种的数量 { for(i=0;i<i1+i2+i3+i4;i++) { items[i]=tempItems[i]; } } } } for (var peasantIndex = 0; peasantIndex < peasants.length; peasantIndex++) { var peasant = peasants[peasantIndex]; item = peasant.getNearest(items); for(i=0,n=0;i<items.length;i++) { if(item!==items[i]) { items[n++]=items[i]; } } 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'); if(peasants.length<=2) { 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.
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了