Monster Racer Rush
Select between 5 monster racers, upgrade your monster skill and win the competition!
4.18 / 5.00 3,534 ViewsBuild and Base
Build most powerful forces, unleash hordes of monster and control your soldiers!
3.80 / 5.00 4,200 ViewsIntroduction
I am reviving a competition in which I participated several years ago here in the Flash Forum. The concept behind "AS Wars" is fairly simple: you program the intelligence for a "bot" that competes against bots programmed by other competitors. This time around, the situation for which you will be programming is essentially the same as from 2007. Every player will program one bot that moves, heals, shoots bullets, and plants mines in a confined space, or "arena". The last bot standing wins. Assuming enough people participate, I will develop a tournament bracket and we'll narrow it down to one winner by matches of two to five bots.
Please follow the directions below to get started. These instructions are fairly brief, so if you have any problems or questions, please post and I will try to get back to you as soon as I can.
Deadline
This has not been done in a while, and I want to allow time to fix any problems. Considering these factors bots should be uploaded to dumping grounds by Monday October 29, 2012.
Getting Started
If you don't have the Standalone Flash Player 10.1 or above, I recommend downloading the latest version here:
http://www.adobe.com/support/flashplayer/downloads.html
The first step is to choose which language you want to use. AS Wars is a bit of a misnomer because you can use AS3, AS2, or Haxe. Yes, you can use AS2, but this competition is a good opportunity to try AS3 or Haxe because the languages are similar when it comes to logic code. Also, any battle with an AS2 bot runs at about half speed, but the results are the same; thus, I am not too concerned about this.
Download the appropriate files for your language (if you don't feel comfortable downloading a zip file, I have the individual text/swf files available):
AS3 (.zip)
--arena.swf [Everyone needs this to test their bots]
--BotInfo.as
--PlayerBot.as
--ExampleBot.as
AS2 [There are only two files, so no zip]
--arena.swf
--PlayerBot.as
Haxe (.zip) [Newgrounds does not support .hx so the individual files will be .txt. Just change the extensions or download the zip.]
--arena.swf
--BotInfo.hx
--PlayerBot.hx
--ExampleBot.hx
In order to use the Arena SWF, you must compile your bot into another SWF and then load it into the Arena. So, in general (this will be expanded on for your language), copy the files to your project directory, modify the run function in ExampleBot, instantiate the bot, and compile. Once this is done, open up arena, type in your SWF's name in the upper text box and your bot's class name (eg. ExampleBot) in the lower box, and hit load. If you make a change and compile an updated SWF with the same name, you can just hit reload, so you don't have to close the Arena.
Follow the instructions below for your language.
AS3
If you are using FlashDevelop, create a new AS3 project, copy the AS files to your source directory and arena.swf to your bin. Right-click on the project in the project explorer, go to Properties... > Compiler Options > set Use Network Services to false. Instantiate ExampleBot. For example:
package
{
import flash.display.Sprite;
import flash.events.Event;
public class Main extends Sprite
{
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
var bot:ExampleBot = new ExampleBot();
}
}
}
Now, compile your project. Launch the Arena and load your SWF with the appropriate class name, which should be ExampleBot. If this works, you can just rename ExampleBot and use that as a base for your own bot.
If you are using the Flash IDE, copy all the files to the same directory containing a new FLA file. On the timeline, place this code:
var bot:ExampleBot = new ExampleBot();
Publish the movie. Launch the Arena like we did above for FlashDevelop.
AS2
Copy the files to the same directory containing a new FLA file. Create a circle that is W=40px, H=40px and move to position X=-20 and Y=-20. On the timeline, paste this code:
import flash.geom.Point;
pb = new PlayerBot();
pb.playerName = "My AS2 Bot";
function run(botInfoVector:Array, id:Number, p:Point, health:Number, ammo:Number, mines:Number):Number
{
pb.direction.x = botInfoVector[0].p.x - p.x;
pb.direction.y = botInfoVector[0].p.y - p.y;
return 1;
}
pb.run = run;
pb.init();
Publish the movie. You will need to make sure to open arena.swf in a Flash Player that is 10.1 or newer. If you can load the SWF into Arena without any problems, you can just go ahead and change the run function; you do not have to rename anything except the playerName.
Haxe
If you are using Haxe, you probably know what you're doing, so just instantiate your bot in your main function.
General
IMPORTANT: After making sure everything works, you need to rename ExampleBot.as to [Your User Name]Bot.as. You can use a shortened form of your user name. You will need to change the actual class name in the AS file. Also, change the playerName property to anything you like.
The hit region for each bot is a circle 20px in radius; therefore, your graphics for your bot should not be much larger than that (40x40).
Every frame your run function will be called. From that function, you need to return an integer between 0 and 4 inclusive. This integer represents the choice you make.
0 : heal - regain one point of health
1 : move - move in the direction of direction by a magnitude of 5 px
2 : shoot - shoot a bullet in direction
3 : reload - regain one bullet (ammo)
4 : place mine - place a mine at your current location
--Bullets--
Bullets do 2 points of damage when they hit a bot (are within a 20px radius of the bot's position). You can hold 30 bullets at one time. No limit on reloads.
--Mines--
Mines explode when a bot runs over them. When planted, they have a 10 frame deadtime unless another mine sets it off. They do 20 points of damage within a 50 px radius. Mines explode if they are placed within 30 px of another mine. If a mine is within 50px of another mine when it explodes, that mine will explode too. You only get 5 for the entire battle.
--direction--
The direction property is a point. It represents the direction vector in which you will travel or shoot.
Other Rules
-Do not use random or time functions. The battles should play the same way every time.
This looks really really interesting. I have plenty of free time after tomorrow, so count me in!
It's a guessing game? No reactionary actions at all? Not sure if that is fun.
You can solve pretty much any problem you may have with AS3 by consulting the AS3 Language reference.
At 10/19/12 01:27 AM, ProfessorFlash wrote: It's a guessing game? No reactionary actions at all? Not sure if that is fun.
Each programmer will have their own strategy, but typically you process information about the other bots and decide on an action that way.
That might not be apparent because I did not explain everything very well.
UPDATE for Participants
AS3 run function (it is similar for Haxe and AS2):
function run(id:int, p:Point, health:int, ammo:int, mines:int):int
The 5 (6 in AS2 because the botInfoVector is passed to the function) parameters that are passed to the run function are:
id - a unique integer assigned to your bot for the duration of the battle
p - the current position of your bot in the Arena
health - your bot's current health
ammo - the number of bullets your bot currently possesses
mines - the number of mines your bot has remaining
In order to get information about your opponents (the other bots in the arena), you access the botInfoVector. The properties of each element of the vector (array in AS2) are the same as the 5 parameters passed to run plus one called "name", which is the playerName set by your oppenent.
IMPORTANT UPDATE
In the first version of the engine and files, I omitted the ability to access information on the bullets and mines that are in play. I have remedied this situation.
The position (p) and velocity (v) of all bullets in play may be access through bulletInfoVector.
The position (p) of all mines in play may be access through mineInfoVector.
Here are the updated files required for competing:
AS3 (.zip)
--arena.swf
--BotInfo.as
--BulletInfo.as
--MineInfo.as
--PlayerBot.as
--ExampleBot.as
AS2
--arena.swf
--PlayerBot.as
[There are only two files, so no zip]
Haxe (.zip)
--arena.swf
--BotInfo.hx
--BulletInfo.hx
--MineInfo.hx
--PlayerBot.hx
--ExampleBot.hx
[Newgrounds does not support .hx so the individual files will be .txt. Just change the extensions or download the zip.]
Also, the code on the frame for an AS2 bot should now be:
import flash.geom.Point;
pb = new PlayerBot();
pb.playerName = "My AS2 Bot";
function run(botInfoVector:Array, bulletInfoVector:Array, mineInfoVector:Array, id:Number, p:Point, health:Number, ammo:Number, mines:Number):Number
{
pb.direction.x = botInfoVector[0].p.x - p.x;
pb.direction.y = botInfoVector[0].p.y - p.y;
return 1;
}
pb.run = run;
pb.init();
this sounds like a fun weekend project. Count me in as soon as I get my Java homework done.
Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P
I've created a Go AI once, and I'm only having exams next week so I'll see what I can do.
so what time exactly do these need to be submitted by?
12:00 (00:00) morning on Monday, 12:00 (12:00) noon on Monday, or 11:59 (23:59) evening on Monday?
Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P
Alright I've toyed around with it for a bit and I have the following remarks / questions about it:
Is the load time supposed to be noticeable? I have a delay of about 3 seconds after clicking 'load'. Might be because of ubuntu and the wacky standalone flashplayer I've used to bypass sandbox violation from the browser plugin one. When it eventually starts everything runs smooth though.
Can you make it so that the bot swf and the bot name can be automated? It's tedious to type in the name and file location all the time. Can you make it that the arena.swf looks for a arena_config.txt that contains these 2 Strings? Also it autostarting with these values in config would be nice so I can test it all with only 1 button.
Maybe you can even make it that you can have multiple custom bots go against each other so we can test various versions of the bot against each other.
At 10/19/12 03:29 PM, Sandremss128 wrote: Maybe you can even make it that you can have multiple custom bots go against each other so we can test various versions of the bot against each other.
I was actually thinking the exact same things.
I'll add this: I ran into an "Internal debugger exception" when hitting the load button
Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P
At 10/19/12 03:29 PM, Sandremss128 wrote: Alright I've toyed around with it for a bit and I have the following remarks / questions about it:
That load time issue is odd. It actually has to load the file, so if that is taking a while for some reason, it would cause a delay, but, I am not sure why that would be for local files. I will try to put out an updated Arena tonight with your suggestions about the configuration file and multiple bots.
At 10/19/12 03:43 PM, egg82 wrote: I'll add this: I ran into an "Internal debugger exception" when hitting the load button
I will look into that, but this seems relevant.
As for the specific time, I think 11:59 pm (EDT) Monday should work.
oh, yeah, I can't trace anything :(
Well, there goes my debugging tool.
hmm... My character is now a text field!
At 10/19/12 05:33 PM, Tree-SkyLark-BCE wrote: I will look into that, but this seems relevant.
Yeah, I just ran it in release mode.
As for the specific time, I think 11:59 pm (EDT) Monday should work.
this timer might help.
Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P
another quick thing: A non-cached "load" and "reload" would be nice, so I can make small edits to the bot without having to close and re-open the arena.
Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P
whoa: huge issue, here!
all the bots get removed and re-added when one of them dies. This causes some pretty big problems for my bot :x
Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P
At 10/19/12 10:00 PM, egg82 wrote: whoa: huge issue, here!
all the bots get removed and re-added when one of them dies. This causes some pretty big problems for my bot :x
That actually should not be happening. What information is telling you that?
Update
If you are using AS3 or Haxe (I think), you can place this SWC in you library and instantiate a class called ArenaManager. It take the stage and a vector of bot classes as parameters. In order to see the battle, add the ArenaManager instance to your display list.
var bots:Vector.<Class> = new Vector.<Class>();
bots.push(ExampleBot);
bots.push(Kamikaze);
bots.push(ExampleBot);
bots.push(Kamikaze);
var am:ArenaManager = new ArenaManager(stage, bots);
addChild(am);
At 10/19/12 10:17 PM, Tree-SkyLark-BCE wrote: That actually should not be happening. What information is telling you that?
private var _bots:Vector.<BotInfo>;
public function Egg82Bot() {
super();
playerName = "H.U.N.T.R.";
graphic = new Sprite();
graphic.graphics.beginFill(0x00FF00);
graphic.graphics.drawCircle(0, 0, 20);
graphic.graphics.endFill();
_text.width = 200;
_text.selectable = false;
graphic.addChild(_text);
_bots = botInfoVector;
}
override public function run(id:int, p:Point, health:int, ammo:int, mines:int):int {
_text.text = String(_bots.length);
}
so it means the constructor is being run more than once.
If you are using AS3 or Haxe (I think), you can place this SWC in you library and instantiate a class called ArenaManager. It take the stage and a vector of bot classes as parameters. In order to see the battle, add the ArenaManager instance to your display list.
I love you :D
Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P
At 10/19/12 10:28 PM, egg82 wrote: so it means the constructor is being run more than once.
heraderp. I feel like an idiot. I created a reference to the vector, not a new vector.
whelp, don't mind me.
now that I have trace statements again I can get to some real debugging.
Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P
So what happens in the hypothetical situation where 2 bots are 1v1ing and are out of mines, where one bot simply heals all the time. You heal 1 point per second, and a bullet gives 2 damage on hit and takes 1 turn to reload.
So the healing speed is the same as the damage output with ammo replenishing. The maximum of 30 bullets allows for 30 damage to be dealt before the ammo is depleted. This may not be enough for the bot to win the fight.
With this issue it would be easy for a simple bot to force a tie by just healing all the time, as opposed to more sophisticated strategies.
Will you consider changing the values so the outcome of a battle can be more decisive?
At 10/20/12 10:10 AM, Sandremss128 wrote: So what happens in the hypothetical situation where 2 bots are 1v1ing and are out of mines, where one bot simply heals all the time. You heal 1 point per second, and a bullet gives 2 damage on hit and takes 1 turn to reload.
So the healing speed is the same as the damage output with ammo replenishing. The maximum of 30 bullets allows for 30 damage to be dealt before the ammo is depleted. This may not be enough for the bot to win the fight.
With this issue it would be easy for a simple bot to force a tie by just healing all the time, as opposed to more sophisticated strategies.
Will you consider changing the values so the outcome of a battle can be more decisive?
I recently noticed that problem while testing the example bots. I might need to change the values or introduce a new limit on the current ones. I am not sure of the best balance for everything.
At 10/20/12 12:59 PM, Tree-SkyLark-BCE wrote: I recently noticed that problem while testing the example bots. I might need to change the values or introduce a new limit on the current ones. I am not sure of the best balance for everything.
my first thought was "just make bullets do 3 points of damage" - but that's just me :P
Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P
At 10/20/12 07:29 PM, Tree-SkyLark-BCE wrote: I have updated the SWC and the Arena. Now, bullets do 4 points of damage and each bot can hold 35. This way, if a bot is just in one place constantly healing, the opponent can do 3 total points of damage a frame for 35 frames. Also, I fixed a bug that would break some of the bullets.
you forgot to remove your trace statements :P
Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P
At 10/20/12 07:31 PM, egg82 wrote: you forgot to remove your trace statements :P
Yeah. I just updated the SWC to remove those trace statements.
Awesome! I may give this a go!! do you have to sign up in anyway. or just submit by the deadline?
At 10/20/12 11:22 PM, swishcheese wrote: Awesome! I may give this a go!! do you have to sign up in anyway. or just submit by the deadline?
No sign up is necessary. You just have to upload a SWF with your bot class in it to Dumping Ground and then post here or private message me the link to it by the deadline. A post saying that someone might do it is nice though. It helps to have an idea of the number of participants.
At 10/20/12 11:51 PM, Tree-SkyLark-BCE wrote: No sign up is necessary. You just have to upload a SWF with your bot class in it to Dumping Ground and then post here or private message me the link to it by the deadline. A post saying that someone might do it is nice though. It helps to have an idea of the number of participants.
Okay. sweet!! well, Im in if I have enough time and can get a decent bot put together.
Is there any reason why when there is only 1 bullet on the field, this bullet is not included in the bulletInfo Vector? I've tried this code and I see very clearly 2 bullets on the screen:
package bots {
import flash.display.Sprite;
import flash.geom.Point;
public class ShootSingleBullet extends PlayerBot {
public function ShootSingleBullet() {
super();
playerName = "shoot when 0 bullets";
graphic = new Sprite();
graphic.graphics.beginFill(0xFF0000);
graphic.graphics.drawCircle(0, 0, 20);
graphic.graphics.endFill();
direction = new Point(1, 0);
}
override public function run(id : int, p : Point, health : int, ammo : int, mines : int) : int {
trace("l: " + bulletInfoVector.length);
if (bulletInfoVector.length == 0) return Run.SHOOT;
var a : BulletInfo = bulletInfoVector[0];
trace("p: " + a.p);
trace("v: " + a.v);
trace("our point: " + p);
return Run.HEAL;
}
}
}
I even tried adding a delay to the shooting with the idea that maybe bullets get registered in the vector later but to no avail. Also access to hardcoded Constants like Bullet speed, arena dimensions and movement speed would be nice (or may these values vary in different battles?).
Also are the data structures which are passed to the bot safe? Can a bot screw up the game by modifying the info or accessing the parent and calling stuff? Can a bot use a long time to think about its move and can this screw things over? Other similar programming contests track the time a bot takes to make it moves and disqualifies the bot when it takes too long for instance.
Right now I'm focusing on strategies and collecting as much information about the contest as possible. After Wednesday I only have 2 exams which are easier and I've already learned for in the previous weeks so I'll actually begin on my bot after the first half of this week. Nothing wrong with planning and testing the engine first right?
Hmmm. Was just messed around with this. creating a first version bot just to get a feel for the engine and to plan ideas. I ran all my bots against each other and got this result: lol.
At 10/21/12 01:50 PM, Sandremss128 wrote: Is there any reason why when there is only 1 bullet on the field, this bullet is not included in the bulletInfo Vector?
Yeah. I had forgotten that Vector.slice() does not include the end index. I have uploaded a updated SWC that fixes that problem. Also, the new SWC has a class called ArenaInfo, which has static constants for various values (BOT_SPEED, BULLET_SPEED, BULLET_DAMAGE, MINE_DAMAGE, ARENA_WIDTH, and ARENA_HEIGHT).
The structures I pass to the bot classes are not entirely safe yet. You cannot mess with the values the actual Arena uses, and the vectors themselves may be manipulated without worry, but the elements of bulletInfoVector and mineInfoVector are references; thus adjusting the value of those would adjust what all the other participants see. I am actually going to fix that, and it is fixed for the botInfoVector, but I have yet to patch the other ones.
I do not time the bot's decision. If it takes a long time, it will just slow the down match. If this becomes a problem, I may consider implementing some sort of guard, but I do not think that will be necessary.
Yes, testing the engine is appreciated. I want to get out all the bugs before the matches.
This looks interesting, except that I cannot download the as2 file. :( Wat the heck?
Don't click me. Please.
^ DON'T CLICK IT.
^ DON'T LISTEN TO THAT.