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 是一个通过玩 ...
随机推荐
- openssl配置
1.update openssl yum update openssl 2.修改openssl配置 vim /etc/ssh/sshd_config RSAAuthentication yesPubk ...
- mysql 权限管理 针对表的字段 级别 授权 columns_priv表
针对Mike账号 db1库下面的t1表的 id,name字段授予select权限,age字段授予update权限 授权格式 select(要授权的字段,要授权的字段) 用户括号 括起来 .updat ...
- hiredis(Synchronous API)
hiredis是一个小型的client端的c库.它只增加了最小对协议的支持,同时它用一个高级别的printf-alike API为了绑定各种redis命令.除了支持发送和接收命令,它还支持对流的解析. ...
- poj3468A Simple Problem with Integers(线段树的区域更新)
http://poj.org/problem?id=3468 真心觉得这题坑死我了,一直错,怎么改也没戏,最后tjj把q[rt].lz改成了long long 就对了,真心坑啊. 线段树的区域更新. ...
- DNS解析原理和流程
DNS解析原理和流程 DNS解析其实就是将IP地址(202.96.134.133)变成域名(www.xxxxx.com) 网络通讯大部分是基于TCP/IP的,而TCP/IP是基于IP地址的,所 ...
- 用户用户组管理:用户管理命令useradd
添加玩用户后,其实改变的就是几个配置文件. 默认组一般设置成与用户名字,ID相同的.
- 9/24matplotlib简介
Matplotlib是一个在python下实现的类matlib的纯python的三方库,旨在用python实现matlib的功能,是python下最出色的绘图库,功能很完善,其风格根matlib很相似 ...
- Typecho博客让文章列表页只显示摘要的方法
在当前主题的 index.php 文件中找到代码 <?php $this->content('阅读剩余部分...'); ?> 将其替换为 <?php $this->exc ...
- STA分析(二) multi_cycle and false
multicycle path:当FF之间的组合逻辑path propagate delay大于一个时钟cycle时,这条combinational path能被称为multicycle path. ...
- presto 0.166概述
presto是什么 是Facebook开源的,完全基于内存的并⾏计算,分布式SQL交互式查询引擎 是一种Massively parallel processing (MPP)架构,多个节点管道式执⾏ ...