码迷,mamicode.com
首页 > 其他好文 > 详细

CodeCombat多人游戏Greed

时间:2014-09-14 11:15:06      阅读:357      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   io   os   ar   for   div   

题目的意思在于,更高效的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 items = base.getItems();
var peasants = base.getByType(‘peasant‘);
for (var peasantIndex = 0; peasantIndex < peasants.length; peasantIndex++) {
    var peasant = peasants[peasantIndex];
    var item=null;
    for(var i=0;i<items.length;i++)
    {
        if(items[i].type==‘gem‘)
        {
            item=items[i];
        }
    }
    if(!item)
    for(i=0;i<items.length;i++)
    {
        if(items[i].type==‘gold-coin‘)
        {
            item=items[i];
        }
    }
     if(!item)
    for(i=0;i<items.length;i++)
    {
        if(items[i].type==‘coin‘)
        {
            item=items[i];
        }
    }
    //var item = base.getNearest(items);
    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‘);
    //type=‘soldier‘;
    if(knights.length>=2&&peasants <=4)
    {
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

标签:des   style   blog   color   io   os   ar   for   div   

原文地址:http://www.cnblogs.com/chucklu/p/3970728.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!