Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var base = this;
- var enemyBase = base.getEnemies()[ 0 ];
- if( typeof base.init === "undefined" )
- {
- this.startTime = this.now();
- base.enemyUnits =
- {
- "soldier" : 0,
- "knight" : 1,
- "librarian" : 2,
- "griffin-rider" : 3,
- "captain" : 4,
- "peasant" : 5
- };
- base.friendlyUnits =
- [
- "munchkin",
- "ogre",
- "shaman",
- "fangrider",
- "brawler",
- "peon"
- ];
- base.init = new function()
- {
- base.say( "Base initted!" );
- };
- base.frame = function ()
- {
- base.slavesUpdate();
- if( ( base.getByType( "peon" ).length ) < 2 )
- {
- base.build( "peon" );
- return;
- }
- base.mirrorEnemy();
- base.buildSlaveIfCan();
- if( ( base.now() - base.startTime ) > 100 )
- base.charge();
- else
- {
- base.say( base.now() - base.startTime );
- base.mirrorEnemy();
- base.buildSlaveIfCan();
- }
- };
- base.chargeToggle = false;
- base.charge = function()
- {
- base.say( "CHAAAARGE!" );
- if( !base.chargeToggle )
- base.build( "ogre" );
- else
- base.build( "shaman" );
- base.chargeToggle = !base.chargeToggle;
- };
- base.slavesUpdate = function()
- {
- var peons = base.getByType( "peon" );
- var peasants = base.getByType( "peasant" );
- var allSlaves = peons.concat( peasants );
- for( var slaveIndex in allSlaves )
- {
- var slave = allSlaves[ slaveIndex ];
- if( typeof slave.init === "undefined" )
- base.initSlave( slave );
- else
- slave.frame();
- }
- };
- base.getNearestSlave = function( coin )
- {
- var peons = base.getByType( "peon" );
- var peasants = base.getByType( "peasant" );
- var slaves = peons.concat( peasants );
- var nearestSlave = slaves[ 0 ];
- for( var slaveIndex in slaves )
- {
- var slave = slaves[ slaveIndex ];
- if( coin.pos.distance( slave.pos ) < coin.pos.distance( nearestSlave.pos ) )
- {
- nearestSlave = slave;
- }
- }
- return nearestSlave;
- };
- base.initSlave = function (pawn)
- {
- pawn.init = new function()
- {
- base.say(
- "Initting pawn: " +
- pawn.id +
- " (" + pawn.team + ")"
- );
- pawn.targetCoin = null;
- pawn.frame = function()
- {
- if( pawn.team == "humans" )
- pawn.enemyFrame();
- else
- pawn.myFrame();
- };
- pawn.myFrame = function()
- {
- pawn.pickCoin();
- if( pawn.targetCoin === null )
- {
- pawn.pickCoin();
- }
- else
- {
- pawn.wasCoinCollected();
- }
- };
- pawn.wasCoinCollected = function()
- {
- if( pawn.pos.distance( pawn.targetCoin.pos ) < 2.0 )
- {
- pawn.targetCoin = null;
- }
- };
- pawn.enemyFrame = function()
- {
- };
- pawn.pickCoin = function()
- {
- pawn.targetCoin = pawn.getClosestFreeCoin();
- base.command( pawn, "move", pawn.targetCoin.pos );
- };
- pawn.getClosestFreeCoin = function()
- {
- var coins = base.getItems();
- for( var coinIndex in coins )
- {
- var coin = coins[ coinIndex ];
- if( pawn == base.getNearestSlave( coin ) )
- {
- return coin;
- }
- }
- return coins[
- Math.floor( Math.random() * coins.length )
- ];
- };
- }();
- };
- base.mirroredEnemies = [];
- base.mirrorEnemy = function()
- {
- var enemies = base.getEnemies();
- for( var i = 1; i < enemies.length; i++ )
- {
- var enemy = enemies[ i ];
- if( base.mirroredEnemies.indexOf( enemy.id ) == -1 )
- {
- base.mirroredEnemies.push( enemy.id );
- var mirrorType = base.getMyTypeById( enemy.id );
- base.say( "Trying to mirror: " + mirrorType );
- base.build( mirrorType );
- }
- }
- };
- base.buildSlaveIfCan = function()
- {
- if( ( base.gold - enemyBase.gold ) > 100 )
- {
- if( ( base.now() - base.startTime ) < 80 )
- base.build( "peon" );
- }
- };
- base.getMyTypeById = function( id )
- {
- var enemies = base.getEnemies();
- for( var i = 0; i < enemies.length; i++ )
- {
- var enemy = enemies[ i ];
- if( enemy.id == id )
- {
- var index = base.enemyUnits[ enemy.type ];
- return base.friendlyUnits[ index ];
- }
- }
- };
- }
- else
- {
- base.frame();
- }
- ยดvar base = this;
- var enemyBase = this.getEnemies()[ 0 ];
- if( typeof base.init === "undefined" )
- {
- base.init = function()
- {
- base.coins = base.getItems();
- base.peons = base.getByType( "peon" );
- }();
- base.getCoinRadiusValue = function( coin, coinRadius )
- {
- var radiusValue = coin.bountyGold;
- for( var coinIndex in base.coins )
- {
- var otherCoin = base.coins[ coinIndex ];
- if( otherCoin.pos.distance( coin.pos ) < coinRadius )
- {
- radiusValue += otherCoin.bountyGold;
- }
- }
- return radiusValue;
- };
- base.findCoinsInRadius = function( peon, radius )
- {
- var coinsInRadius = [];
- for( var coinIndex in base.coins )
- {
- var coin = base.coins[ coinIndex ];
- if( coin.pos.distance( peon.pos ) < radius )
- {
- coinsInRadius.push( coin );
- }
- }
- return coinsInRadius;
- };
- base.findBestCoin = function( peon, inRadius, radiusValue )
- {
- var coins = base.findCoinsInRadius( peon, inRadius );
- var coinWithBestValue = null;
- for( var coinIndex in coins )
- {
- var coin = coins[ coinIndex ];
- if( coinWithBestValue === null )
- {
- coinWithBestValue = coin;
- }
- else
- {
- var coinRadiusValue = radiusValue;
- if( base.getCoinRadiusValue( coin, coinRadiusValue ) > base.getCoinRadiusValue( coinWithBestValue, coinRadiusValue ) )
- {
- coinWithBestValue = coin;
- }
- }
- }
- return coinWithBestValue;
- };
- base.peonsFindGold = function()
- {
- for( var peonIndex in base.peons )
- {
- var peon = base.peons[ peonIndex ];
- var coin = base.findBestCoin( peon, 25, 10 );
- }
- };
- }
- if( base.built.length === 0 )
- {
- base.build( "peon" );
- }
- if( ( base.built.length - base.peons.length ) + 1 < enemyBase.built.length )
- {
- base.build( "ogre" );
- }
- else
- {
- if( base.gold >= 75 )
- {
- base.build( "peon" );
- }
- }
- base.peonsFindGold();
- var base = this;
- var enemyBase = base.getEnemies()[ 0 ];
- if( typeof base.init === "undefined" )
- {
- this.startTime = this.now();
- base.enemyUnits =
- {
- "soldier" : 0,
- "knight" : 1,
- "librarian" : 2,
- "griffin-rider" : 3,
- "captain" : 4,
- "peasant" : 5
- };
- base.friendlyUnits =
- [
- "munchkin",
- "ogre",
- "shaman",
- "fangrider",
- "brawler",
- "peon"
- ];
- base.init = new function()
- {
- base.say( "Base initted!" );
- };
- base.frame = function ()
- {
- base.slavesUpdate();
- base.mirrorEnemy();
- base.buildSlaveIfCan();
- if( ( base.now() - base.startTime ) > 100 )
- base.charge();
- else
- {
- base.say( base.now() - base.startTime );
- base.mirrorEnemy();
- base.buildSlaveIfCan();
- }
- };
- base.chargeToggle = false;
- base.charge = function()
- {
- base.say( "CHAAAARGE!" );
- if( !base.chargeToggle )
- base.build( "ogre" );
- else
- base.build( "shaman" );
- base.chargeToggle = !base.chargeToggle;
- };
- base.slavesUpdate = function()
- {
- var peons = base.getByType( "peon" );
- var peasants = base.getByType( "peasant" );
- var allSlaves = peons.concat( peasants );
- for( var slaveIndex in allSlaves )
- {
- var slave = allSlaves[ slaveIndex ];
- if( typeof slave.init === "undefined" )
- base.initSlave( slave );
- else
- slave.frame();
- }
- };
- base.getNearestSlave = function( coin )
- {
- var peons = base.getByType( "peon" );
- var peasants = base.getByType( "peasant" );
- var slaves = peons.concat( peasants );
- var nearestSlave = slaves[ 0 ];
- for( var slaveIndex in slaves )
- {
- var slave = slaves[ slaveIndex ];
- if( coin.pos.distance( slave.pos ) < coin.pos.distance( nearestSlave.pos ) )
- {
- nearestSlave = slave;
- }
- }
- return nearestSlave;
- };
- base.initSlave = function (pawn)
- {
- pawn.init = new function()
- {
- base.say(
- "Initting pawn: " +
- pawn.id +
- " (" + pawn.team + ")"
- );
- pawn.targetCoin = null;
- pawn.frame = function()
- {
- if( pawn.team == "humans" )
- pawn.enemyFrame();
- else
- pawn.myFrame();
- };
- pawn.myFrame = function()
- {
- if( pawn.targetCoin === null )
- {
- pawn.pickCoin();
- }
- else
- {
- pawn.wasCoinCollected();
- }
- };
- pawn.wasCoinCollected = function()
- {
- if( pawn.pos.distance( pawn.targetCoin.pos ) < 2.0 )
- {
- pawn.targetCoin = null;
- }
- };
- pawn.enemyFrame = function()
- {
- };
- pawn.pickCoin = function()
- {
- pawn.targetCoin = pawn.getClosestFreeCoin();
- base.command( pawn, "move", pawn.targetCoin.pos );
- };
- pawn.getClosestFreeCoin = function()
- {
- var coins = base.getItems();
- for( var coinIndex in coins )
- {
- var coin = coins[ coinIndex ];
- if( pawn == base.getNearestSlave( coin ) )
- {
- return coin;
- }
- }
- return coins[
- Math.floor( Math.random() * coins.length )
- ];
- };
- }();
- };
- base.mirroredEnemies = [];
- base.mirrorEnemy = function()
- {
- var enemies = base.getEnemies();
- for( var i = 1; i < enemies.length; i++ )
- {
- var enemy = enemies[ i ];
- if( base.mirroredEnemies.indexOf( enemy.id ) == -1 )
- {
- base.mirroredEnemies.push( enemy.id );
- var mirrorType = base.getMyTypeById( enemy.id );
- base.say( "Trying to mirror: " + mirrorType );
- base.build( mirrorType );
- }
- }
- };
- base.buildSlaveIfCan = function()
- {
- var enemySoldiers = base.getEnemies().length;
- enemySoldiers -= base.getByType( "peasant" ).length;
- var mySoldiers = base.getFriends().length;
- mySoldiers -= base.getByType( "peon" ).length;
- if( enemySoldiers > mySoldiers + 1 )
- {
- base.build( "ogre" );
- }
- else if( ( base.gold - enemyBase.gold ) > 100 )
- {
- if( ( base.now() - base.startTime ) < 80 )
- base.build( "peon" );
- };
- base.getMyTypeById = function( id )
- {
- var enemies = base.getEnemies();
- for( var i = 0; i < enemies.length; i++ )
- {
- var enemy = enemies[ i ];
- if( enemy.id == id )
- {
- var index = base.enemyUnits[ enemy.type ];
- return base.friendlyUnits[ index ];
- }
- }
- };
- }
- else
- {
- base.frame();
- }
- var base = this;
- var enemyBase = this.getEnemies()[ 0 ];
- var peons = base.getByType( "peon" );
- var coins = base.getItems();
- var sectors = [];
- sectors[ 0 ] = new Vector( 17, 49 );
- sectors[ 1 ] = new Vector( 47, 68 );
- sectors[ 2 ] = new Vector( 46, 11 );
- sectors[ 3 ] = new Vector( 73, 32 );
- var sectorDistance = 20;
- var sectorsWithCoins = [];
- function sectorCoins()
- {
- sectorsWithCoins[ 0 ] = [];
- sectorsWithCoins[ 1 ] = [];
- sectorsWithCoins[ 2 ] = [];
- sectorsWithCoins[ 3 ] = [];
- for( var coinIndex in coins )
- {
- var coin = coins[ coinIndex ];
- var closestSector = 0;
- for( var i = 0; i < sectors.length; i++ )
- {
- var secPos = sectors[ i ];
- if(
- coin.pos.distance( secPos ) <
- coin.pos.distance( sectors[ closestSector ] )
- )
- {
- closestSector = i;
- }
- }
- sectorsWithCoins[ closestSector ].push( coin );
- }
- }
- sectorCoins();
- for( var peonIndex in peons )
- {
- var peon = peons[ peonIndex ];
- if( peons.length < 4 )
- {
- var coin = peon.getNearest( coins );
- base.command( peon, "move", coin.pos );
- break;
- }
- if( peonIndex > 3 )
- {
- var enemySlave = base.getByType( "peasant" )[ 0 ];
- if( peon.pos.distance( enemySlave.pos ) > 5 )
- base.command( peon, "move", enemySlave.pos );
- else
- {
- var coin = peon.getNearest( coins );
- base.command( peon, "move", coin.pos );
- }
- }
- var coin = peon.getNearest( coins );
- if( coin )
- {
- var go = true;
- for( var peonIndex2 in peons )
- {
- var secondPeon = peons[ peonIndex2 ];
- if( secondPeon.target !== null )
- {
- if( secondPeon.target == coin )
- {
- go = false;
- }
- }
- }
- if( go )
- {
- if( typeof peon.sector !== "undefined" )
- {
- if( peon.pos.distance( sectors[ peon.sector ] ) > sectorDistance )
- {
- base.command( peon, "move", sectors[ peon.sector ] );
- return;
- }
- }
- peon.target = coin;
- base.command( peon, "move", coin.pos );
- }
- }
- }
- if( base.built.length === 0 )
- {
- base.build( "peon" );
- }
- if( peons.length < 5 )
- {
- for( var i = 0; i < peons.length; i++ )
- {
- peons[ i ].sector = i;
- }
- }
- if( ( base.built.length - peons.length ) + 1 < enemyBase.built.length )
- {
- base.build( "ogre" );
- }
- else
- {
- if( base.gold >= 75 )
- {
- base.build( "peon" );
- }
- }
- var base = this;
- var enemyBase = this.getEnemies()[ 0 ];
- if( typeof base.init === "undefined" )
- {
- /*
- BASE CODE ***
- */
- base.init = function()
- {
- base.createSector( new Vector( 20, 20 ) );
- };
- base.frame = function()
- {
- base.coins = base.getItems();
- base.peons = base.getByType( "peon" );
- base.sectorCoins();
- };
- /*
- SECTOR SPECIFIC CODE ***
- */
- base.sectorRadius = 20; //In what radius has the coin have to be to be in a sector
- base.sectors = [];
- /*
- Each sector contains source position
- and, well, coins (derp)
- */
- base.Sector = function()
- {
- this.pos = null;
- this.coins = [];
- };
- /*
- Create sector with source position
- */
- base.createSector = function( sourcePos )
- {
- var newSector = new base.Sector();
- newSector.pos = sourcePos;
- base.sectors.push( newSector );
- };
- /*
- Give each coin a sector
- */
- base.sectorCoins = function()
- {
- /*
- Loop through all the coins and determine their sector
- */
- for( var coinIndex in base.coins ) //for #1
- {
- var coin = base.coins[ coinIndex ];
- /*
- Loop through all the sectors and
- determine if coin is in sectors radius
- if so, push that coin into that sector
- */
- for( var i = 0; i < base.sectors.length; i++ ) //for #2
- {
- var sector = base.sectors[ i ];
- if( coin.pos.distance( sector.pos ) < base.sectorRadius )
- {
- sector.coins.push( coin );
- break; //Found sector for coin, lets break out of "for #2"
- }
- }
- }
- };
- base.init();
- }
- base.frame();
- var main = this;
- /*
- Global settings
- */
- _SECTOR_UPDATE_RATE = 5;
- _SECTOR_RADIUS = 20;
- var ObjectType =
- {
- SLAVE : 0,
- SECTOR : 1,
- SECTOR_MANAGER : 2
- };
- var SectorManager = function()
- {
- var core = {};
- core.type = ObjectType.SECTOR_MANAGER;
- core.counter = 0;
- core.sectors = [];
- core.createSector = function( centerPos )
- {
- core.sectors.push( new Sector( centerPos ) );
- };
- core.frame = function()
- {
- /*
- Update sectors if needed
- or increment counter.
- */
- core.counter++;
- if( core.counter == _SECTOR_UPDATE_RATE )
- {
- core.counter = 0;
- core.updateSectors();
- }
- };
- /*
- Designate coins into their sectors
- */
- core.updateSectors = function()
- {
- /*
- Clean sectors
- */
- for( var sectorIndex in core.sectors )
- {
- var sector = core.sectors[ sectorIndex ];
- sector.coins = [];
- sector.value = 0;
- }
- /*
- Push coins into proper sectors
- */
- for( var coinIndex in main.coins )
- {
- var coin = main.coins[ coinIndex ];
- core.pushCoinIntoSector( coin );
- }
- };
- /*
- Helper function for ^
- */
- core.pushCoinIntoSector = function( coin )
- {
- var closestSector = null;
- for( var i = 0; i < core.sectors.length; i++ )
- {
- var sector = core.sectors[ i ];
- if( closestSector === null )
- closestSector = sector;
- else
- {
- if(
- coin.pos.distance( sector.pos.distance ) <
- coin.pos.distance( closestSector.pos.distance )
- )
- {
- closestSector = sector;
- }
- }
- }
- coin.sector = closestSector;
- //closestSector.value += coin.bountyGold;
- //closestSector.coins.push( coin );
- };
- core.init = function()
- {
- }();
- main.objects.push( core );
- return core;
- };
- var Sector = function( centerPos )
- {
- var core = {};
- core.type = ObjectType.SECTOR;
- core.value = 0;
- core.coins = [];
- core.init = function( centerPos )
- {
- core.pos = centerPos;
- }();
- main.objects.push( core );
- return core;
- };
- var Slave = function( pawn, sector )
- {
- var core = {};
- core.type = ObjectType.SLAVE;
- core.pawn = pawn;
- core.frame = function()
- {
- main.say( "Doing frame: " + main.frameCount );
- var coin = main.coins[ Math.floor( Math.random() * main.coins.length ) ];
- main.command( core.pawn, "move", coin.pos );
- };
- core.init = function()
- {
- }();
- main.objects.push( core );
- return core;
- };
- if( typeof main.init === "undefined" )
- {
- main.objects = [];
- main.init = true;
- main.frameCount = 0;
- main.coins = null;
- main.pawns = null;
- main.sectorManager = new SectorManager();
- main.frame = function()
- {
- main.frameCount++;
- /*
- Update basic shit
- */
- main.coins = main.getItems();
- main.pawns = main.getByType( "peon" );
- /*
- Loop objects
- #1 Call frame function on these functions
- */
- for( var o = 0; o < main.objects.length; o++ )
- {
- var obj = main.objects[ o ];
- if( typeof obj.frame !== "undefined" )
- obj.frame();
- }
- /*
- Loop peon pawns
- #1 Init slaves if need to
- */
- for( var p = 0; p < main.pawns.length; p++ )
- {
- var pawn = main.pawns[ p ];
- if( typeof pawn.init === "undefined" )
- {
- pawn.init = true;
- new Slave( pawn );
- }
- }
- /*
- Increment frame count
- */
- };
- main.build( "peon" );
- }
- else
- {
- main.frame();
- }
- var _ = this;
- var coins = _.getItems();
- var d1 = "";
- var d2 = "";
- var d3 = "";
- var d4 = "";
- var d5 = "";
- var d6 = "";
- var d7 = "";
- var d8 = "";
- var d9 = "";
- /*
- Init game
- */
- if( typeof _.init === "undefined" )
- {
- _.init = true;
- _.slaves = [];
- _.pwns = [];
- _.say( "Game initted: " + Math.random() );
- _.getNearestSlave = function( coin )
- {
- var nearestSlave = _.slaves[ 0 ];
- for( var slaveIndex in _.slaves )
- {
- var slave = _.slaves[ slaveIndex ];
- if( coin.pos.distance( slave.pos ) < coin.pos.distance( nearestSlave.pawn.pos ) )
- {
- nearestSlave = slave;
- }
- }
- return nearestSlave;
- };
- _.initSlaves = function()
- {
- var enemySlaves = _.getByType( "peasant" );
- var mySlaves = _.getByType( "peon" );
- var allSlaves = enemySlaves.concat( mySlaves );
- for( var slaveIndex in allSlaves )
- {
- var slavePawn = allSlaves[ slaveIndex ];
- if( typeof _.pwns[ slavePawn.id ] === "undefined" )
- {
- var newSlave = new _.Slave( slavePawn );
- _.pwns[ slavePawn.id ] = true;
- _.say( "Got slave: " + newSlave );
- }
- }
- };
- _.mySlaveFrames = function()
- {
- for( var i = 0; i < _.slaves.length; i++ )
- {
- var slav = _.slaves[ i ];
- slav.frame();
- }
- };
- _.frame = function()
- {
- _.initSlaves();
- _.mySlaveFrames();
- };
- _.Slave = function( pawn )
- {
- var parent = this;
- parent.init = function()
- {
- _.slaves.push( this );
- parent.pawn = pawn;
- parent.targetCoin = null;
- _.say( "New slave created, id is: " + parent.pawn.id + " - " + Math.random() * 10 );
- };
- this.frame = function()
- {
- _.say( "Hey hoo!" );
- if( parent.targetcoin === null )
- {
- parent.pickCoin();
- }
- };
- parent.pickCoin = function()
- {
- parent.targetCoin = parent.closestFreecoin();
- _.command( pawn, "move", parent.targetCoin.pos );
- };
- parent.closestFreeCoin = function()
- {
- var coins = _.getItems();
- for( var coinIndex in coins )
- {
- var coin = coins[ coinIndex ];
- if( parent == _.getNearestSlave( coin ) )
- {
- return coin;
- }
- }
- };
- parent.init();
- };
- }
- _.frame();
- if( _.built.length < 5 )
- {
- _.build( "peon" );
- }
- else
- {
- _.build( "ogre" );
- }
- if( true )
- {
- for( var i = 0; i < _.getByType( "peon" ).length; i++ )
- {
- var peon = _.getByType( "peon" )[ i ];
- var item = peon.getNearest( _.getItems() );
- if( item )
- _.command( peon, "move", item.pos );
- }
- }
- var base = this;
- if( typeof base.init === "undefined" )
- {
- base.init = new function()
- {
- base.say( "sup" );
- };
- }
- var base = this;
- var items = base.getItems();
- var peons = base.getByType( "peon" );
- if( typeof this.frame === "undefined" )
- {
- this.frame = 0;
- this.enemyBase = this.getEnemies()[ 0 ];
- this.startTime = this.now();
- }
- if( base.frame === 0 )
- {
- base.frames = [];
- base.registerFrame = function( frameCount, frameFunc )
- {
- base.frames[ frameCount ] = frameFunc;
- };
- base.initPeons = function()
- {
- for( var i = 0; i < base.built.length; i++ )
- {
- if( base.built[ i ].type != "peon" )
- continue;
- var peon = base.built[ i ];
- if( typeof peon.init === "undefined" )
- {
- peon.init = true;
- base.initPeon( i );
- }
- }
- };
- base.initPeon = function( count )
- {
- base.say( "Initted peon!" );
- var peon = base.built[ count ];
- peon.init = true;
- peon.targetArrived = false;
- peon.randomCoin = null;
- peon.lastPos = new Vector( 0, 0 );
- peon.goToCamp = function()
- {
- base.command( peon, "move", peon.campPos );
- };
- peon.frame = function()
- {
- if( peon.lastPos == peon.pos )
- peon.targetArrived = true;
- peon.lastPos = peon.pos;
- if( peon.targetArrived )
- peon.getClosestCoin();
- };
- peon.getClosestCoin = function()
- {
- base.say( "Getting new coin! " + base.frame );
- peon.targetArrived = false;
- var item = peon.getNearest( base.getItems() );
- var random = Math.floor( Math.random() * 5 );
- if( random >= 4 )
- {
- item = items[ Math.floor( Math.random() * items.length ) ];
- peon.randomCoin = item;
- }
- if( item )
- {
- base.command( peon, "move", item.pos );
- }
- };
- peon.getClosestCoin();
- };
- base.doFrame = function()
- {
- if( typeof base.frames[ base.frame ] !== "undefined" )
- {
- base.frames[ base.frame ]();
- }
- base.initPeons();
- for( var a = 0; a < base.built.length; a++ )
- {
- if( typeof base.built[ a ].frame !== "undefined" )
- {
- base.built[ a ].frame();
- }
- }
- base.frame++;
- };
- }
- if( base.built.length < 1 )
- base.build( "peon" );
- else
- {
- var enemySoldiers = base.getEnemies().length;
- enemySoldiers -= base.getByType( "peasant" ).length;
- var mySoldiers = base.getFriends().length;
- mySoldiers -= base.getByType( "peon" ).length;
- if( enemySoldiers > mySoldiers )
- {
- base.build( "munchkin" );
- }
- else
- {
- if( ( this.now() - this.startTime ) < 120 )
- {
- if( peons.length < 10 )
- base.build( "peon" );
- }
- else
- {
- var random = Math.floor( Math.random() * 5 );
- if( random >= 2 )
- base.build( "shaman" );
- else
- base.build( "munchkin" );
- }
- }
- }
- base.doFrame();
- var base = this;
- var enemyBase = this.getEnemies()[ 0 ];
- if( typeof base.init === "undefined" )
- {
- base.init = function()
- {
- base.coins = base.getItems();
- base.peons = base.getByType( "peon" );
- }();
- base.getCoinRadiusValue = function( coin, coinRadius )
- {
- var radiusValue = coin.bountyGold;
- for( var coinIndex in base.coins )
- {
- var otherCoin = base.coins[ coinIndex ];
- if( otherCoin.pos.distance( coin.pos ) < coinRadius )
- {
- radiusValue += otherCoin.bountyGold;
- }
- }
- return radiusValue;
- };
- base.findCoinsInRadius = function( peon, radius )
- {
- var coinsInRadius = [];
- for( var coinIndex in base.coins )
- {
- var coin = base.coins[ coinIndex ];
- if( coin.pos.distance( peon.pos ) < radius )
- {
- coinsInRadius.push( coin );
- }
- }
- return coinsInRadius;
- };
- base.findBestCoin = function( peon, inRadius, radiusValue )
- {
- var coins = base.findCoinsInRadius( peon, inRadius );
- var coinWithBestValue = null;
- for( var coinIndex in coins )
- {
- var coin = coins[ coinIndex ];
- if( coinWithBestValue === null )
- {
- coinWithBestValue = coin;
- }
- else
- {
- var coinRadiusValue = radiusValue;
- if( base.getCoinRadiusValue( coin, coinRadiusValue ) > base.getCoinRadiusValue( coinWithBestValue, coinRadiusValue ) )
- {
- coinWithBestValue = coin;
- }
- }
- }
- return coinWithBestValue;
- };
- base.peonsFindGold = function()
- {
- for( var peonIndex in base.peons )
- {
- var peon = base.peons[ peonIndex ];
- var coin = null;
- var iterator = 1;
- while( coin === null )
- {
- coin = base.findBestCoin( peon, 25 * iterator, 10 * iterator );
- for( var peonIndex2 in base.peons )
- {
- var secondPeon = base.peons[ peonIndex2 ];
- if( secondPeon == peon )
- continue;
- if( secondPeon.target === null )
- continue;
- if( coin == secondPeon.target )
- {
- coin = null;
- }
- }
- if( iterator > 100 )
- {
- coin = base.findBestRandomCoin();
- }
- iterator++;
- }
- peon.target = coin;
- base.command( peon, "move", coin.pos );
- }
- };
- base.findBestRandomCoin = function()
- {
- return base.coins[ Math.floor( Math.random() * base.coins.length ) ];
- };
- }
- if( base.built.length === 0 )
- {
- base.build( "peon" );
- }
- if( ( base.built.length - base.peons.length ) + 1 < enemyBase.built.length )
- {
- base.build( "ogre" );
- }
- else
- {
- if( base.gold >= 75 )
- {
- base.build( "peon" );
- }
- }
- base.peonsFindGold();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement