题目的意思在于,更高效的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. div+css网页标准布局实例教程(三)

    前边两节学完后,前台工作基本上完成了,下边的任务该程序员添加程序了.为什么说是基本完成呢?因为要做的工作还很多,不但要把首页做出来,其它的列表页详细页等页面也得做.还要配合程序员把整个网站完成,这样才 ...

  2. 理解CopyOnWriteArrayList

    CopyOnWriteArrayList,顾名思义,Write的时候总是要Copy,也就是说对于任何可变的操作(add.set.remove)都是伴随复制这个动作的 A thread-safe var ...

  3. windows server r2 搭建 ftp服务器

    1:安装ftp服务器 开始>管理工具>服务器管理器>打开服务器管理器,找到添加角色,然后点击,弹出添加角色对话框,选择下一步>选择Web服务器(IIS),然后选择FTP服务,直 ...

  4. [py]python多态-动态语言的鸭子类型

    弱类型?强类型?动态语言,静态语言 弱类型: 在程序运行过程中,类型可变 还有一种说法: 动态 variables must necessarily be defined before they ar ...

  5. java的redis工具类

    package com.mracale.sell.utils; /** * @Auther: Mracale */ import org.springframework.beans.factory.a ...

  6. hdu2159FATE(二维背包)

    http://acm.hdu.edu.cn/showproblem.php?pid=2159 Problem Description 最近xhd正在玩一款叫做FATE的游戏,为了得到极品装备,xhd在 ...

  7. A + B Problem II(大数加法)

    一直格式错误,不想改了,没A #include <iostream> #include <stdio.h> #include <string.h> #include ...

  8. 算法---数组总结篇2——找丢失的数,找最大最小,前k大,第k小的数

    一.如何找出数组中丢失的数 题目描述:给定一个由n-1个整数组成的未排序的数组序列,其原始都是1到n中的不同的整数,请写出一个寻找数组序列中缺失整数的线性时间算法 方法1:累加求和 时间复杂度是O(N ...

  9. xgb, lgb, Keras, LR(二分类、多分类代码)

    preprocess # 通用的预处理框架 import pandas as pd import numpy as np import scipy as sp # 文件读取 def read_csv_ ...

  10. cordova+Android Studio 1.0+ionic+win7(转)

    转自http://blog.csdn.net/fuyunww/article/details/42216125 目录(?)[-] 在项目目录下执行 a创建工程 b添加平台支持 c添加插件在Androi ...