Basic bot Maze walker
- package {
- import flash.display.Sprite;
- import flash.text.TextField;
- import flash.system.Security;
- dynamic public class MazeWalker extends Sprite {
- /**
- * Simple maze walker for http://tinyurl.com/aibattle
- * @see http://makc3d.wordpress.com/2009/10/31/ai-battle-again/
- */
- public function MazeWalker () {
- Security.allowDomain ("http://makc.googlecode.com/");
- if (stage != null) {
- var tf:TextField = new TextField;
- tf.autoSize = "left";
- tf.text = stage.loaderInfo.url;
- addChild (tf);
- }
- }
- private var lastAngle:int = -1;
- public function behavior ():void {
- // find closest wall
- var i:int, d:Number = 1e6, a:Number = 0;
- for (i=0; i< this.inColors.length; i++) {
- if (this.inColors [i] == 0) {
- if (this.inDistances [i] < d) {
- a = i; d = this.inDistances [i];
- }
- }
- }
- if (d > 20) {
- if (lastAngle < 0) {
- // get closer
- this.outMoveAngle = a;
- } else {
- // maintain direction
- this.outMoveAngle = lastAngle;
- }
- } else {
- // move along the wall
- lastAngle = (a + 9) % 36;
- this.outMoveAngle = lastAngle;
- }
- this.outMoveSpeed = this.inMaxSpeed;
- }
- }
- }
Basic bot scooby56 bot
- package {
- import flash.display.Sprite;
- import flash.text.TextField;
- import flash.system.Security;
- dynamic public class scooby56 extends Sprite {
- /**
- * scooby56 bot for http://tinyurl.com/aibattle
- * @scooby56
- * @see http://makc3d.wordpress.com/2009/10/31/ai-battle-again/
- */
- public function scooby56 () {
- Security.allowDomain ("http://makc.googlecode.com/");
- if (stage != null) {
- var tf:TextField = new TextField;
- tf.autoSize = "left";
- tf.text = stage.loaderInfo.url;
- addChild (tf);
- }
- this.objective = 2;
- this.danger = false;
- }
- private function search ():int {
- var d:scooby56 = this;
- //loop through all angles return direction to items in the following priority
- for (var i:int=0; i< d.inColors.length; i++){
- //1. check theres no danger
- if (d.inColors[i] == 3 && d.inDistances[i] < 100){
- //make a desision on direction to evade
- var evadeDirection:Array = new Array();
- evadeDirection[1] = i - 9;
- evadeDirection[2] = i - 18;
- evadeDirection[3] = i + 9;
- var bestDirection:int = 0
- for (var j:int=0;j<3;j++){
- if (evadeDirection[j] < 0)
- evadeDirection[j] += 36;
- if (evadeDirection[j] > 36)
- evadeDirection[j] -= 36;
- if (d.inDistances[evadeDirection[j]] > bestDirection)
- bestDirection = evadeDirection[j];
- }
- //d.trace('retreat bestDirection:' + bestDirection)
- d.danger = true;
- return bestDirection;
- }
- d.danger = false;
- //2. current objective location
- if (d.inColors[i] == d.objective)
- return i;
- }
- // next line was not part of scooby56 script
- return -1;
- }
- private function changeDirection ():void {
- var d:scooby56 = this;
- var i:int, arrOptions:Array = new Array();
- //look in all 4 directions
- for (i=0;i<37;i+=9){
- //over 100 px = possible option
- if(d.inDistances[i] > 100)
- arrOptions.push(i)
- }
- //if cornered, (ie all options < 100) loop all angles for exit, take most open option
- if(arrOptions.length < 1){
- var intLargest:Number = 0;
- for (i=0;i<37;i++){
- if(d.inDistances[i] > intLargest)
- intLargest = d.inDistances[i]
- }
- arrOptions.push(intLargest)
- };
- //pick one direction from available at random
- var rand:int = Math.floor(Math.random() * 2)
- d.outMoveAngle = arrOptions[rand]
- d.outMoveSpeed = d.inMaxSpeed;
- }
- public function behavior ():void {
- this.outThrowBullet = false;
- //set away if not moving
- if(!this.outMoveSpeed || this.outMoveAngle == undefined || this.inDistances[this.outMoveAngle] == undefined){
- this.changeDirection();
- };
- //set objective
- this.objective = (this.inHasBullet) ? 1: 2;
- //this.trace("objective: " + this.objective)
- //look for objects
- var dir:int = this.search();
- if (dir > -1){
- //this.trace("dir @ " + dir)
- this.outMoveSpeed = this.inMaxSpeed;
- this.outMoveAngle = dir;
- if(this.objective == 1){
- if(!this.danger){
- if(this.inHasBullet){
- if(this.inDistances[dir] < 120){
- //this.trace("firing at " + dir + " danger: " + this.danger)
- this.outThrowAngle = dir;
- this.outThrowBullet = true;
- this.objective = 2;
- }
- };
- };
- };
- } else {
- //if heading towards a wall
- if(this.inColors[this.outMoveAngle] == 0 ){
- if(this.inDistances[this.outMoveAngle] < 50){
- this.changeDirection();
- //this.trace("angle: " + this.outMoveAngle + " distance: " + this.inDistances[this.outMoveAngle])
- }
- }
- }
- }
- }
- }
Basic bot hohoho bot
- // forked from makc3d's Basic bot
- package {
- import flash.display.Sprite;
- import flash.text.TextField;
- import flash.system.Security;
- dynamic public class hohoho extends Sprite {
- /**
- * hohoho bot for http://tinyurl.com/aibattle
- * @author hohoho
- * @see http://makc3d.wordpress.com/2009/10/31/ai-battle-again/
- */
- public function hohoho () {
- Security.allowDomain ("http://makc.googlecode.com/");
- if (stage != null) {
- var tf:TextField = new TextField;
- tf.autoSize = "left";
- tf.text = stage.loaderInfo.url;
- addChild (tf);
- }
- this.dodging=false;
- }
- public function behavior ():void {
- var lookang:int, theta:int, bestangle:int;
- this.outMoveSpeed = this.inMaxSpeed;
- this.outThrowBullet = false;
- // Find a bullet
- var closestbullet:Number = 1000;
- if(!this.inHasBullet){
- for(lookang=0;lookang<36;lookang++){
- if (this.inColors[lookang] == 2){
- if(this.inDistances[lookang] < closestbullet){
- bestangle = lookang;
- closestbullet = this.inDistances[lookang];
- }
- }
- }
- }
- // Find open spaces
- var maxdist:Number = 0;
- if (closestbullet == 1000){
- for(theta=-8;theta<=8;theta++){
- lookang = this.outMoveAngle + theta;
- if (lookang > 35) lookang = lookang - 36;
- if (lookang < 0) lookang = 36 + lookang;
- if ((this.inDistances[lookang] > maxdist) && (this.inColors[lookang] == 0)){
- maxdist = this.inDistances[lookang];
- if(theta>1)
- bestangle = this.outMoveAngle + 2;
- else if(theta<-1)
- bestangle = this.outMoveAngle - 2;
- else bestangle = lookang;
- }
- if(maxdist < 15){
- bestangle = bestangle - 18;
- }
- }
- //Randomize when it's aimless.
- if(Math.random() < 0.4){
- bestangle = bestangle + 1
- }
- if(bestangle < 0) bestangle = bestangle + 36;
- if(bestangle > 35) bestangle = bestangle - 36;
- }
- // Find enemy
- var foundenemy:Boolean = false;
- if (this.inHasBullet){
- for(lookang=0;lookang<36;lookang++){
- if (this.inColors[lookang] == 1){
- bestangle = lookang;
- this.outThrowAngle = lookang;
- foundenemy = true;
- }
- }
- }
- // Dodge bullets
- if((this.dodging==false) && this.inMaxSpeed >= 3){
- for(lookang=0; lookang<36; lookang++){
- if(this.inColors[lookang] == 3){
- this.dodging = true;
- theta = lookang + 11;
- if (theta > 35) theta = theta - 36;
- maxdist = this.inDistances[theta];
- bestangle = lookang - 11;
- if (bestangle < 0) bestangle = bestangle + 36;
- if(this.inDistances[bestangle] < maxdist) bestangle = theta;
- this.outMoveAngle = bestangle;
- }
- }
- }
- // Finish dodging bullets
- if(this.inMaxSpeed >= 3){
- this.dodging = false;
- for(lookang=0; lookang<36; lookang++){
- if(this.inColors[lookang] == 3)
- this.dodging = true;
- }
- }
- else this.dodging = false;
- if (!this.dodging) this.outMoveAngle = bestangle;
- if (foundenemy && (this.inDistances[this.outMoveAngle] < 80)) this.outThrowBullet = true;
- }
- }
- }
Basic bot parad0xl0g bot
- package {
- import flash.display.Sprite;
- import flash.text.TextField;
- import flash.system.Security;
- dynamic public class parad0xl0g extends Sprite {
- /**
- * parad0xl0g bot for http://tinyurl.com/aibattle
- * @author parad0xl0g
- * @see http://makc3d.wordpress.com/2009/10/31/ai-battle-again/
- */
- public function parad0xl0g () {
- Security.allowDomain ("http://makc.googlecode.com/");
- if (stage != null) {
- var tf:TextField = new TextField;
- tf.autoSize = "left";
- tf.text = stage.loaderInfo.url;
- addChild (tf);
- }
- this.curAngle = 27;
- }
- public function behavior ():void {
- var i:int, wallAt:int = -1, enemyAt:int = -1;
- for (i=0; i< this.inColors.length; i++) {
- if (this.inColors[i] == 0 && this.inDistances[i]<20) {
- wallAt = i; break;
- }
- }
- if ( wallAt > -1 ){
- var minAngle:int = wallAt + 18;
- var maxAngle:int = minAngle + 9;
- var temp:int = Math.floor( Math.random()*(maxAngle-minAngle)+minAngle );
- this.curAngle = (temp >35)?(temp%35):temp;
- }
- this.outMoveAngle = this.curAngle;
- this.outMoveSpeed = this.inMaxSpeed;
- if (this.inHasBullet){
- var dangerAt:int = -1;
- enemyAt = -1;
- for (i=0; i< this.inColors.length; i++) {
- if (this.inColors[i] == 3) {
- dangerAt = i; break;
- }
- if (this.inColors[i] == 1) {
- enemyAt = i; break;
- }
- }
- if ( dangerAt > -1) {
- this.outMoveAngle = ( dangerAt >26 ) ? ( 35-(dangerAt+9) ) : ( dangerAt-9 );
- this.outMoveSpeed = this.inMaxSpeed;
- if( this.inDistances[dangerAt]<50 ){
- enemyAt = -1;
- for (i=0; i< this.inColors.length; i++) {
- if (this.inColors[i] == 1) {
- enemyAt = i; break;
- }
- }
- if ( enemyAt > -1){
- this.outMoveSpeed = 0;
- this.outThrowBullet = true;
- this.outThrowAngle = enemyAt;
- }
- }
- }
- else if (enemyAt > -1 && this.inDistances[enemyAt]<250) {
- this.outMoveSpeed = 0;
- this.outThrowBullet = true;
- this.outThrowAngle = enemyAt;
- }
- else{
- this.outThrowBullet = false;
- }
- }
- else
- {
- var bulletAt:int = -1;
- for (i=0; i< this.inColors.length; i++) {
- if (this.inColors[i] == 2) {
- bulletAt = i; break;
- }
- }
- if( bulletAt>-1 ){
- this.outMoveAngle = bulletAt ;
- this.outMoveSpeed = this.inMaxSpeed;
- }
- }
- }
- }
- }
notice:





