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.
CodeCombat多人游戏Greed的更多相关文章
- Tuning Radio Resource in an Overlay Cognitive Radio Network for TCP: Greed Isn’t Good
好吧,这是09年七月发布在IEEE Communications Magazine的一篇文章. 核心二个词:overlay cognitive radio network,tcp 讲的是,在认知无线网 ...
- UE4 difference between servertravel and openlevel(多人游戏的关卡切换)
多人游戏的关卡切换分为无缝和非无缝.非无缝切换时,客户端将跟服务器断开连接,然后重新连接到同一个服务器,服务器则加载一个新地图.无缝切换不会发生这样的情况. 有三个函数供我们使用:UEngine::B ...
- [Python]Codecombat攻略之远边的森林Forest(1-40关)
首页:https://cn.codecombat.com/play语言:Python 第二界面:远边的森林Forest(40关)时间:2-6小时内容:if/else.关系操作符.对象属性.处理输入网页 ...
- [Python]Codecombat攻略之地牢Kithgard(1-22关)
首页:https://cn.codecombat.com/play语言:Python 第一界面:地牢 Kithgard(22关) 时间:1-3小时 内容:语法.方法.参数.字符串.循环.变量等 网页: ...
- [Python] Codecombat 攻略 Sarven 沙漠 (1-43关)截止至30关
首页:https://cn.codecombat.com/play语言:Python 第二界面:Sarven沙漠(43关)时间:4-11小时内容:算术运算,计数器,while循环,break(跳出循环 ...
- 使用Multiplayer Networking做一个简单的多人游戏例子-3/3(Unity3D开发之二十七)
使用Multiplayer Networking做一个简单的多人游戏例子-1/3 使用Multiplayer Networking做一个简单的多人游戏例子-2/3 使用Multiplayer Netw ...
- 使用Multiplayer Networking做一个简单的多人游戏例子-2/3(Unity3D开发之二十六)
猴子原创,欢迎转载.转载请注明: 转载自Cocos2Der-CSDN,谢谢! 原文地址: http://blog.csdn.net/cocos2der/article/details/51007512 ...
- 使用Multiplayer Networking做一个简单的多人游戏例子-1/3(Unity3D开发之二十五)
猴子原创,欢迎转载.转载请注明: 转载自Cocos2Der-CSDN,谢谢! 原文地址: http://blog.csdn.net/cocos2der/article/details/51006463 ...
- CodeCombat编程游戏
一. 介绍 官方网站:http://cn.codecombat.com/ 项目地址:https://github.com/codecombat/codecombat CodeCombat 是一个通过玩 ...
随机推荐
- TortoiseGit密钥的配置(转)
add by zhj:说到密钥,就不得不提非对称加密.目前使用最广泛的非对称加密算法是rsa,它是美国三位科学家于1977年发明的. 一对密钥对有两个密钥,其中一个为私钥,一个为公钥,两者没有什么区别 ...
- [MySQL5.6] 最近对group commit的小优化
[MySQL5.6] 最近对group commit的小优化 http://www.tuicool.com/articles/rEZr2q 最近花了一些时间在做MySQL Group Commit的优 ...
- 什么是anaconda【转载】
转自:https://zhidao.baidu.com/question/525102108723657245.html https://zhidao.baidu.com/question/62475 ...
- PAT A+B for Polynomials[简单]
1002 A+B for Polynomials (25)(25 分) This time, you are supposed to find A+B where A and B are two po ...
- Twitter OA prepare: K-complementary pair
2sum的夹逼算法,需要sort一下.本身不难,但是tricky的地方在于允许同一个数组元素自己跟自己组成一个pair,比如上例中的[5, 5].而且数组本身就允许值相等的元素存在,在计算pair时, ...
- Bus memory attribute
根据程序的局部性原理,在主存与CPU之间设置的一个高速的容量较小的存储器,叫做cache. ARM cache架构由cache存储器和写缓冲器(write-buffer)组成.其中Write_buff ...
- STA分析(三) cmos模型
CMOS集成电路的基本结构是以P型材料作为衬底(p-substrate),直接生成NMOS, 同时增加N肼(n-well),在其上制造PMOS. 增加两个bulk(P+,N+)防止非MOS管内的PN结 ...
- MyBatis学习笔记(七)——Mybatis缓存
转自孤傲苍狼的博客:http://www.cnblogs.com/xdp-gacl/p/4270403.html 一.MyBatis缓存介绍 正如大多数持久层框架一样,MyBatis 同样提供了一级缓 ...
- 数据仓库基础(十三)Informatica workflow
本文转载自:http://www.cnblogs.com/evencao/p/3154715.html 看了几天的Informatica ,关于infor的资料也比较少,主要的<商业智能深入浅出 ...
- 20165207 2017-2018-2《Java程序设计》课程总结
20165207 2017-2018-2<Java程序设计>课程总结 每周作业链接汇总 预备作业1:我期望的师生关系 预备作业2:学习基础与C语言调查反馈 预备作业3:Linux安装与命令 ...