题目的意思在于,更高效的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的更多相关文章

  1. Tuning Radio Resource in an Overlay Cognitive Radio Network for TCP: Greed Isn’t Good

    好吧,这是09年七月发布在IEEE Communications Magazine的一篇文章. 核心二个词:overlay cognitive radio network,tcp 讲的是,在认知无线网 ...

  2. UE4 difference between servertravel and openlevel(多人游戏的关卡切换)

    多人游戏的关卡切换分为无缝和非无缝.非无缝切换时,客户端将跟服务器断开连接,然后重新连接到同一个服务器,服务器则加载一个新地图.无缝切换不会发生这样的情况. 有三个函数供我们使用:UEngine::B ...

  3. [Python]Codecombat攻略之远边的森林Forest(1-40关)

    首页:https://cn.codecombat.com/play语言:Python 第二界面:远边的森林Forest(40关)时间:2-6小时内容:if/else.关系操作符.对象属性.处理输入网页 ...

  4. [Python]Codecombat攻略之地牢Kithgard(1-22关)

    首页:https://cn.codecombat.com/play语言:Python 第一界面:地牢 Kithgard(22关) 时间:1-3小时 内容:语法.方法.参数.字符串.循环.变量等 网页: ...

  5. [Python] Codecombat 攻略 Sarven 沙漠 (1-43关)截止至30关

    首页:https://cn.codecombat.com/play语言:Python 第二界面:Sarven沙漠(43关)时间:4-11小时内容:算术运算,计数器,while循环,break(跳出循环 ...

  6. 使用Multiplayer Networking做一个简单的多人游戏例子-3/3(Unity3D开发之二十七)

    使用Multiplayer Networking做一个简单的多人游戏例子-1/3 使用Multiplayer Networking做一个简单的多人游戏例子-2/3 使用Multiplayer Netw ...

  7. 使用Multiplayer Networking做一个简单的多人游戏例子-2/3(Unity3D开发之二十六)

    猴子原创,欢迎转载.转载请注明: 转载自Cocos2Der-CSDN,谢谢! 原文地址: http://blog.csdn.net/cocos2der/article/details/51007512 ...

  8. 使用Multiplayer Networking做一个简单的多人游戏例子-1/3(Unity3D开发之二十五)

    猴子原创,欢迎转载.转载请注明: 转载自Cocos2Der-CSDN,谢谢! 原文地址: http://blog.csdn.net/cocos2der/article/details/51006463 ...

  9. CodeCombat编程游戏

    一. 介绍 官方网站:http://cn.codecombat.com/ 项目地址:https://github.com/codecombat/codecombat CodeCombat 是一个通过玩 ...

随机推荐

  1. crawlspider爬虫:定义url规则

    spider爬虫,适合meta传参的爬虫(列表页,详情页都有数据要爬取的时候) crawlspider爬虫,适合不用meta传参的爬虫 scrapy genspider -t crawl it it. ...

  2. mysql python pymysql模块 增删改查 查询 fetchone

    import pymysql mysql_host = '192.168.0.106' port = 3306 mysql_user = 'root' mysql_pwd = ' encoding = ...

  3. iOS开发-url包括中文报错解决的方法

    常常, 我们用通过这个方案调用API. NSString* urlString = [NSString stringWithFormat:@"http://api.douban.com/v2 ...

  4. semi-consistent简介

    semi-consistent简介 http://hedengcheng.com/?p=220 semi-consistent简介    1 semi-consistent实现    2 MySQL ...

  5. (c++) int 转 string,char*,const char*和string的相互转换

    一.int 和string的相互转换 1 int 转化为 string c++ //char *itoa( int value, char *string,int radix); // 原型说明: / ...

  6. 搭建基于HTTP协议内网yum仓库

    目录 1. 前言 2. 把rpm包下载到本地 3. 配置nginx对外提供服务 4. 配置本地repo文件 5. 生成repodata信息 6. 检查及使用 7. 对管理机器上的仓库进行更新 参考资料 ...

  7. PAT 1070 Mooncake[一般]

    1070 Mooncake (25)(25 分) Mooncake is a Chinese bakery product traditionally eaten during the Mid-Aut ...

  8. PAT 1045 Favorite Color Stripe[dp][难]

    1045 Favorite Color Stripe (30)(30 分) Eva is trying to make her own color stripe out of a given one. ...

  9. oracle实例内存(SGA和PGA)调整

    修改oracle内存占用 >show parameter sga; (查看内存占用情况) NAME                                   TYPE          ...

  10. 一款优秀的OA办公系统有哪些功能?

    OA办公系统解决企业的日常管理规范化.增加企业的可控性.提高企业运转的效率的基本问题,范围涉及日常行政管理.各种事项的审批.办公资源的管理.多人多部门的协同办公.以及各种信息的沟通与传递.可以概括的说 ...