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 是一个通过玩 ...
随机推荐
- 【python-opencv】17-形态学操作-腐蚀与膨胀
形态学操作其实就是改变物体的形状,比如腐蚀就是"变瘦",膨胀就是"变胖",看下图就明白了: 形态学操作一般作用于二值化图(也可直接作用于原图),来连接相邻的元素 ...
- promise VS future
Future and Promise are the two separate sides of an asynchronous operation. promise is used by the & ...
- socke+epoll
读: #define V5CLI_READ_MSG_LEN 1024 char readMsg[V5CLI_READ_MSG_LEN]; ; ; )) > ){ n += nread; }//读 ...
- gitlab启用https的配置
vim /etc/gitlab/gitlab.rb external_url 'https://101.101.101.63' #启用https,默认是http (改端口:external_ur ...
- 关于微信小程序,你想知道的他们都问了
微信公开课深圳站小程序专场刚刚结束,大家通过"微信公开课+"互动小程序提出了许多问题.我们筛选了后台问得最多的九个问题进行解答,快来看看这里有没有你想要的答案吧! @谢杨:小程序是 ...
- nginx 11个处理阶段 && nginx lua 8个处理阶段
1. nginx 11 个处理阶段 nginx实际把请求处理流程划分为了11个阶段,这样划分的原因是将请求的执行逻辑细分,各阶段按照处理时机定义了清晰的执行语义,开发者可以很容易分辨自己需要开发的模块 ...
- 飞跃平野(sdut1124)
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1124 飞跃原野 Time Limit: 500 ...
- ubuntu开发环境下eclipse的alt+/自动补全功能不能用
解决方法:windows ---preferences---General---keys ,把在搜索框中搜Word Completion,把该快捷键unbind,然后给content assist 绑 ...
- matplotlib--设置线条颜色及形状
一.控制颜色 b--blue c--cyan(青色) g--green k--black m--magenta(紫红色) r--red w--white y--yellow 颜色有三种表示方法,可以用 ...
- numpy排序(sort、argsort、lexsort、partition、sorted)
1.sort numpy.sort(a, axis=1, kind='quicksort', order=None) a :所需排序的数组 axis:数组排序时的基准,axis=0按行排列:axis= ...