Forum Topic: Tron Ai Flash-off!

(2,161 views • 33 replies)

This topic is 2 pages long. [ 1 | 2 ]

<< < > >>
None

Glaiel-Gamer

Reply To Post Reply & Quote

Posted at: 11/22/08 06:49 PM

Glaiel-Gamer NEUTRAL LEVEL 27

Sign-Up: 12/28/04

Posts: 8,030

Tron Driver FLAs

Time for an AI flash off! ASCHKIN SKRIP 3 POINT OH!

What is it? It is a TRON BATTLE!

It is a 4 player free for all AI challenge!

Now, in order to make a bot, you don't alter the FLA in any bit. Pick a bot.as file from the zip to play with. Any one is fine. When you send me your bots for the battle, you will rename your bot's file to YOURNAMEBOT.as

In the bot's file, you put all the code for your bot. My default bots are STUPID! If you want to really test your bot's skill, pit it against itself, or make more than one and see which one is victorious in the end. If you want to be ballsy and try a 1v1 battle, simply make 2 of the bots move up then down, and they will kill themselves.

====WHAT YOU ARE ALLOWED TO DO====

if(!bot.defined){       //do not modify this
	bot.defined = true; //or this
	setMyColor(0xCC3322); //set your color
	setMyName("Glaiel Bot"); //set your name
	//DECLARE YOUR VARIABLES HERE
	bot.stuff = 12345;
}

This should be at the top of your .as file. Anything in this block will be executed once and once only, meaning if you want to declare variables for your bot, here is where you declare them. ANY DECLARED VARIABLES MUST BE MADE ON THE "bot" OBJECT! Anything else will just be temporary, and you will lose it after the function exits.

Do not worry about potential variable name clashes with other bots. The bot object is a reference to your bot and your bot only. It is different across different .as files, you do not need to worry about this.

Remember to set your color and your name so you can be unique. These have nothing to do with the actual gameplay. You can't set your bot's color to white, it automatically makes it 1 less than white.

You can't name your variables x, y, dead, color, or defined. These names clash with what's already on the bot. Do not reference or change these variables in your code, there are functions to do that for you.

Any variables you declare outside of the bot object must be declared using var, and will be terminated when the function exits. Because of flash's scoping retardedness, these could potentially clash with driver names. Be wary of this, and be safe with your names.

====FUNCTIONS====

These are the only functions you are allowed to call from your file

getMyPos()

getEnemyStatus()

getWallAtPoint(x, y)

randomNumber()

setMyColor(color)

setMyName(name)

getMyPos returns an array, where element 0 is your x position and element 1 is your y position.

getEnemyStatus returns an array with 3 arrays in it, each one representing a lost of statuses about other bots.

[[x, y, dead?]
 [x, y, dead?]
 [x, y, dead?]]

dead is true of the other bot is dead, and false if it isn't. The bots will always be reported in the same order.

getWallAtPoint takes an x and a y and returns true if there is a wall and false if there isn't. Out of bounds points will return true, so don't worry too much about bounds checking. The level is 70x50 by default in case you need to know.

randomNumber returns a psuedo-random number between -2^31 and 2^31.

randomNumber()%N will return a random number between 0 and N (I believe, might want to abs() it also). DO NOT use the built in random() function. This one gives a predictable pattern of random numbers, unlike flash's built in function which really is random.

You can use all the built in math functions besides random() if you think you need to.

setMyColor(color) will change the color of your bot. Do this as often as you want if you want pretty rainbow walls. It's fun.

setMyName(name) will set your name. This shows up when you win, which hopefully you will.

These are the ONLY functions you can reference in your code.

====Making the Decision====

You will return either UP, DOWN, LEFT, or RIGHT from your function.

UP, RIGHT, DOWN, and LEFT represent 0, 1, 2, and 3, respectively. You can use this to your advantage and add or subtract 1 from a name to turn right and left from the direction you're facing, as long as you remember to wrap the value back into 0-3. Any outside bounds values will default to UP, and if you don't return a value it will default to UP.

return UP;
return LEFT;
return RIGHT;
return DOWN;

Anyway, it's time to start battling! Someone can port this to AS2 if they want, bot files should be compatible for both drivers since the AS3-specific stuff is in the driver and not the .as files.

When you are done with your bot, and only when you are REALLY DONE and finally done with your bot, email me the .as file to glaielgamesmail@comcast.net, named YOURNAMEbot.as

WHAT NOW?


None

Glaiel-Gamer

Reply To Post Reply & Quote

Posted at: 11/22/08 06:53 PM

Glaiel-Gamer NEUTRAL LEVEL 27

Sign-Up: 12/28/04

Posts: 8,030

First battle:

http://spamtheweb.com/ul/upload/3308/572 12_tron_driverCS3.php

The goal is to make walls and avoid crashing into walls you or other bots make, just in case you didn't know.


None

Alexman159

Reply To Post Reply & Quote

Posted at: 11/22/08 06:56 PM

Alexman159 DARK LEVEL 15

Sign-Up: 09/19/07

Posts: 1,095

are you going to include a human factor? otherwise the Ai will react the same way each time

BBS Signature

None

Glaiel-Gamer

Reply To Post Reply & Quote

Posted at: 11/22/08 06:59 PM

Glaiel-Gamer NEUTRAL LEVEL 27

Sign-Up: 12/28/04

Posts: 8,030

At 11/22/08 06:56 PM, Alexman159 wrote: are you going to include a human factor? otherwise the Ai will react the same way each time

Um, this is the point. You will be competing against other people's AIs.

It might be fun to compile the AIs all together and let a human control one tron and submit it as a collab, but for now it's just a challenge to see who can write the best AI.

Also there's no due date yet. Try to get it done whenever, you can battle each other in the meantime since you all have the driver., and there's no rule against sharing bot codes.


None

Glaiel-Gamer

Reply To Post Reply & Quote

Posted at: 11/22/08 07:40 PM

Glaiel-Gamer NEUTRAL LEVEL 27

Sign-Up: 12/28/04

Posts: 8,030

CHANGE IN RULES:

You CAN make your own functions as long as their names don't class with any in the fla.

Just put them in your .as file somewhere.

Flash lets you declare functions inside of functions.

I don't think they'll clash with other bots functions either, cause of scoping.


None

Wurmy

Reply To Post Reply & Quote

Posted at: 11/22/08 07:50 PM

Wurmy LIGHT LEVEL 28

Sign-Up: 06/20/06

Posts: 2,307

I will definitely give this a try (:

BBS Signature

None

glomph

Reply To Post Reply & Quote

Posted at: 11/22/08 08:25 PM

glomph NEUTRAL LEVEL 10

Sign-Up: 06/16/05

Posts: 229

Glad you did this, I was going to but then I didn't :( The arena should be square in the interests of fairness but I guess it dosen't matter. Also can you post the code in the Fla file for those not blessed with cs3?
I will definitely try and make a bot.

I have done the deed. Didst thou not hear a noise?

BBS Signature

None

Glaiel-Gamer

Reply To Post Reply & Quote

Posted at: 11/22/08 08:27 PM

Glaiel-Gamer NEUTRAL LEVEL 27

Sign-Up: 12/28/04

Posts: 8,030

At 11/22/08 08:25 PM, glomph wrote: Glad you did this, I was going to but then I didn't :( The arena should be square in the interests of fairness but I guess it dosen't matter. Also can you post the code in the Fla file for those not blessed with cs3?
I will definitely try and make a bot.

I need someone to port it to AS2 for me, otherwise it won't work in lower versions.

You should still be able to read the AS files though


None

glomph

Reply To Post Reply & Quote

Posted at: 11/22/08 09:22 PM

glomph NEUTRAL LEVEL 10

Sign-Up: 06/16/05

Posts: 229

At 11/22/08 08:27 PM, Glaiel-Gamer wrote: it work in lower versions.

No but I can look at how it works without having CS3. Will it work if you return just the number 0 1 2 or 3 not the set things like LEFT and RIGHT and so on?

I have done the deed. Didst thou not hear a noise?

BBS Signature

None

Glaiel-Gamer

Reply To Post Reply & Quote

Posted at: 11/22/08 09:28 PM

Glaiel-Gamer NEUTRAL LEVEL 27

Sign-Up: 12/28/04

Posts: 8,030

At 11/22/08 09:22 PM, glomph wrote:
At 11/22/08 08:27 PM, Glaiel-Gamer wrote: it work in lower versions.
No but I can look at how it works without having CS3. Will it work if you return just the number 0 1 2 or 3 not the set things like LEFT and RIGHT and so on?

liam is porting it to flash 8, but ya it'll work if you return 0, 1, 2, 3 etc, cause UP, DOWN, LEFT, RIGHT are just variables that hold integers


None

Glaiel-Gamer

Reply To Post Reply & Quote

Posted at: 11/22/08 10:25 PM

Glaiel-Gamer NEUTRAL LEVEL 27

Sign-Up: 12/28/04

Posts: 8,030

Anyone who downloaded it, download it again, I just fixed a critical glitch with the getEnemyStatus function.

Also, made my bot. Here's the code:

if(!bot.defined){       //do not modify this
	bot.defined = true; //or this
	setMyColor(0xCC3322); //set your color
	setMyName("Glaiel Bot"); //set your name
	//DECLARE YOUR VARIABLES HERE
	bot.currentDirection = UP;
	bot.currentXSpeed = 0;
	bot.currentYSpeed = -1;
	//
}

function Wall(x:int, y:int){
	if(getWallAtPoint(x, y)){
		return true;
	}
	var bots:Array = getEnemyStatus();
	if((bots[0][0]==x && bots[0][1]==y) ||
	   (bots[1][0]==x && bots[1][1]==y) ||
	   (bots[2][0]==x && bots[2][1]==y)){
		return true;
	}
	return false;
}

function dist():int{
	var x:int = getMyPos()[0];
	var y:int = getMyPos()[1];
	var dista:int = 10;
	var bots:Array = getEnemyStatus();
	if(Math.abs(bots[0][0]-x) + Math.abs(bots[0][1]-y)<dista){
		dista = Math.abs(bots[0][0]-x) + Math.abs(bots[0][1]-y)
	}
	if(Math.abs(bots[1][0]-x) + Math.abs(bots[1][1]-y)<dista){
		dista = Math.abs(bots[1][0]-x) + Math.abs(bots[1][1]-y)
	}
	if(Math.abs(bots[2][0]-x) + Math.abs(bots[2][1]-y)<dista){
		dista = Math.abs(bots[2][0]-x) + Math.abs(bots[2][1]-y)
	}
	return dista;
}

if(!bot.dead){
	var pos:Array = getMyPos();
	var decision = bot.currentDirection;
	
	var groid:Array = new Array()
	for(var i = -2; i<72; i++){
		groid[i] = new Array();
		for(var j = -2; j<52; j++){
			groid[i][j] = false;
		}
	}
	var queue:Array = new Array();
	if((Wall(pos[0]+bot.currentXSpeed*2, pos[1]+bot.currentYSpeed*2) && dist()<=2) || Wall(pos[0]+bot.currentXSpeed, pos[1]+bot.currentYSpeed)){
		var chang:int = 1;
		queue.push(new Array(pos[0]-bot.currentYSpeed, pos[1]+bot.currentXSpeed))
		groid[pos[0]][pos[1]] = true;
		groid[pos[0]+bot.currentXSpeed*2][pos[1]+bot.currentYSpeed*2] = true;
		var count1:int = 0;
		var count2:int = 0;
		for(var i = 0; i<queue.length; i++){
			count1++;
			if(queue[i][0]>=0 && queue[i][0]<70 && queue[i][1]>=0 && queue[i][1]<50 && !Wall(queue[i][0], queue[i][1])){
				if(groid[queue[i][0]+1][queue[i][1]]==false && !Wall(queue[i][0]+1, queue[i][1])){
					queue.push(new Array(queue[i][0]+1, queue[i][1]));
					groid[queue[i][0]+1][queue[i][1]]=true
				}
				if(groid[queue[i][0]-1][queue[i][1]]==false && !Wall(queue[i][0]-1, queue[i][1])){
					queue.push(new Array(queue[i][0]-1, queue[i][1]));
					groid[queue[i][0]-1][queue[i][1]]=true
				}
				if(groid[queue[i][0]][queue[i][1]+1]==false && !Wall(queue[i][0], queue[i][1]+1)){
					queue.push(new Array(queue[i][0], queue[i][1]+1));
					groid[queue[i][0]][queue[i][1]+1]=true
				}
				if(groid[queue[i][0]][queue[i][1]-1]==false && !Wall(queue[i][0], queue[i][1]-1)){
					queue.push(new Array(queue[i][0], queue[i][1]-1));
					groid[queue[i][0]][queue[i][1]-1]=true
				}
			}
		}
		queue.splice(0, queue.length);
		queue.push(new Array(pos[0]+bot.currentYSpeed, pos[1]-bot.currentXSpeed))
		for(var i = 0; i<queue.length; i++){
			count2++;
			if(queue[i][0]>=0 && queue[i][0]<70 && queue[i][1]>=0 && queue[i][1]<50 && !Wall(queue[i][0], queue[i][1])){
				if(groid[queue[i][0]+1][queue[i][1]]==false && !Wall(queue[i][0]+1, queue[i][1])){
					queue.push(new Array(queue[i][0]+1, queue[i][1]));
					groid[queue[i][0]+1][queue[i][1]]=true
				}
				if(groid[queue[i][0]-1][queue[i][1]]==false && !Wall(queue[i][0]-1, queue[i][1])){
					queue.push(new Array(queue[i][0]-1, queue[i][1]));
					groid[queue[i][0]-1][queue[i][1]]=true
				}
				if(groid[queue[i][0]][queue[i][1]+1]==false && !Wall(queue[i][0], queue[i][1]+1)){
					queue.push(new Array(queue[i][0], queue[i][1]+1));
					groid[queue[i][0]][queue[i][1]+1]=true
				}
				if(groid[queue[i][0]][queue[i][1]-1]==false && !Wall(queue[i][0], queue[i][1]-1)){
					queue.push(new Array(queue[i][0], queue[i][1]-1));
					groid[queue[i][0]][queue[i][1]-1]=true
				}
			}
		}
		if(count1>count2){
			decision += 1;
			var oldXS = bot.currentXSpeed;
			var oldYS = bot.currentYSpeed;
			bot.currentXSpeed = -oldYS
			bot.currentYSpeed = oldXS
			if(decision>=4){
				decision -= 4;
			}
		} else if(count1==count2 && !Wall(pos[0]+bot.currentXSpeed, pos[1]+bot.currentYSpeed)){
			
		} else {
			decision -= 1;
			var oldXS = bot.currentXSpeed;
			var oldYS = bot.currentYSpeed;
			bot.currentXSpeed = oldYS
			bot.currentYSpeed = -oldXS
			if(decision<0){
				decision += 4;
			}
		}
	}
	
	//
	bot.currentDirection = decision;
	
	return decision;
}

None

SpamBurger

Reply To Post Reply & Quote

Posted at: 11/22/08 10:48 PM

SpamBurger NEUTRAL LEVEL 15

Sign-Up: 07/12/05

Posts: 4,747

You should have titled it "Tron AI AS War". With this title, it just doesn't feel like a good old AS War :(

"However, the game received only two orders, one of which Molyneux speculated was from his mother." -Peter Molyneux's first game The Entrepreneur


None

Glaiel-Gamer

Reply To Post Reply & Quote

Posted at: 11/22/08 11:45 PM

Glaiel-Gamer NEUTRAL LEVEL 27

Sign-Up: 12/28/04

Posts: 8,030

Details on competitions:

My competition driver will run each free for all 24 times (one per possible starting combination) and add up scores:

+1 point for a win, +(1/number of people in the tie) points for a tie

at the end, whoever has the most points is the winner


None

Glaiel-Gamer

Reply To Post Reply & Quote

Posted at: 11/23/08 12:56 AM

Glaiel-Gamer NEUTRAL LEVEL 27

Sign-Up: 12/28/04

Posts: 8,030

http://spamtheweb.com/ul/upload/3308/788 34_battles.php

Here is a demo of what a battle will look like. Think of it as a screen saver. Just watch it, cause it does 24 complete games with 4 different versions of my bots.

Each round 12 points are given away, evenly distributed amongst the winner or the ones who tie for win.


None

Glaiel-Gamer

Reply To Post Reply & Quote

Posted at: 11/23/08 01:56 AM

Glaiel-Gamer NEUTRAL LEVEL 27

Sign-Up: 12/28/04

Posts: 8,030

My bot file if people want a "good" bot to practice against

http://www.glaielgames.com/glaielbot.as


None

TrueDarkness

Reply To Post Reply & Quote

Posted at: 11/23/08 04:48 PM

TrueDarkness EVIL LEVEL 27

Sign-Up: 08/31/04

Posts: 4,718

Sounds awesomee


None

SpamBurger

Reply To Post Reply & Quote

Posted at: 11/23/08 04:58 PM

SpamBurger NEUTRAL LEVEL 15

Sign-Up: 07/12/05

Posts: 4,747

At 11/23/08 04:48 PM, TrueDarkness wrote: Sounds awesomee

Haven't seen you in a while.

"However, the game received only two orders, one of which Molyneux speculated was from his mother." -Peter Molyneux's first game The Entrepreneur


None

Starogre

Reply To Post Reply & Quote

Posted at: 11/24/08 01:29 AM

Starogre NEUTRAL LEVEL 18

Sign-Up: 05/08/04

Posts: 1,684

thanks for the offer but i'll just spectate :)

BBS Signature

Thinking

EntropicOrder

Reply To Post Reply & Quote

Posted at: 11/24/08 03:27 PM

EntropicOrder NEUTRAL LEVEL 10

Sign-Up: 04/21/00

Posts: 1,328

This sounds fun. I might give it a try.

My original game site: EntropicOrder.net
My kid friendly animal themed game site: PlushQuest.com
Our large stuffed animal online store: MyBigPlush.com


None

Smith

Reply To Post Reply & Quote

Posted at: 11/24/08 06:13 PM

Smith EVIL LEVEL 25

Sign-Up: 10/13/04

Posts: 135

what about the random function? if people use that in their bot they wont get the same outcome each time.

or should we not use that for the AI


None

dELtaluca

Reply To Post Reply & Quote

Posted at: 11/24/08 06:28 PM

dELtaluca LIGHT LEVEL 20

Sign-Up: 04/16/04

Posts: 5,541

He has supplied a pseudo random number generator that will generate the same sequence of numbers.

My social worker says im special!

BBS Signature

None

Smith

Reply To Post Reply & Quote

Posted at: 11/24/08 08:22 PM

Smith EVIL LEVEL 25

Sign-Up: 10/13/04

Posts: 135

sorry re-read the bit about random numbers and I get it now. Also all random numbers generated by computer software are psuedo-random to a degree (this is what confused me), yours is just the same every time but erratic so it serves the purpose needed here.


None

GustTheASGuy

Reply To Post Reply & Quote

Posted at: 11/25/08 04:12 AM

GustTheASGuy LIGHT LEVEL 08

Sign-Up: 11/02/05

Posts: 11,326

At 11/24/08 08:22 PM, Smith wrote: yours is just the same every time but erratic so it serves the purpose needed here.

Erratic? It's a constant seed.

#ngprogramming at irc.freenode.net
haXe | Keel imperative | Spyro! | Thru you


None

Smith

Reply To Post Reply & Quote

Posted at: 11/25/08 07:40 AM

Smith EVIL LEVEL 25

Sign-Up: 10/13/04

Posts: 135

Erratic is a better word then random I think. Its predictable, but its all over the place aka erratic


None

EntropicOrder

Reply To Post Reply & Quote

Posted at: 11/25/08 09:32 AM

EntropicOrder NEUTRAL LEVEL 10

Sign-Up: 04/21/00

Posts: 1,328

At 11/24/08 08:22 PM, Smith wrote: sorry re-read the bit about random numbers and I get it now. Also all random numbers generated by computer software are psuedo-random to a degree (this is what confused me), yours is just the same every time but erratic so it serves the purpose needed here.

True randomness does not exist. All events are causal, and "randomness" merely signfies a high degree of unpredictability.

My original game site: EntropicOrder.net
My kid friendly animal themed game site: PlushQuest.com
Our large stuffed animal online store: MyBigPlush.com


None

GustTheASGuy

Reply To Post Reply & Quote

Posted at: 11/25/08 09:58 AM

GustTheASGuy LIGHT LEVEL 08

Sign-Up: 11/02/05

Posts: 11,326

At 11/25/08 09:32 AM, EntropicOrder wrote: True randomness does not exist.

It does in quantum theory. Anyway shut up and make AIs you noobcakes!

#ngprogramming at irc.freenode.net
haXe | Keel imperative | Spyro! | Thru you


None

EntropicOrder

Reply To Post Reply & Quote

Posted at: 11/25/08 10:38 AM

EntropicOrder NEUTRAL LEVEL 10

Sign-Up: 04/21/00

Posts: 1,328

Quantum theory is a decent pragmatic model but not an accurate depiction of reality IMO. I subscribe to the hidden variable idea (absence of evidence is not evidence of absence). Anyway, I'M WORKING ON MY BOT SHEESH!

My original game site: EntropicOrder.net
My kid friendly animal themed game site: PlushQuest.com
Our large stuffed animal online store: MyBigPlush.com


None

Smith

Reply To Post Reply & Quote

Posted at: 11/25/08 06:30 PM

Smith EVIL LEVEL 25

Sign-Up: 10/13/04

Posts: 135

Started on my AI, It sux not having another good one to test it on. I think it needs a bit more work, also I didn't really have much foresight so its really messy code with loads of repeated stuff that could be compacted with a few functions


None

GustTheASGuy

Reply To Post Reply & Quote

Posted at: 11/26/08 05:24 AM

GustTheASGuy LIGHT LEVEL 08

Sign-Up: 11/02/05

Posts: 11,326

At 11/25/08 06:30 PM, Smith wrote: Started on my AI, It sux not having another good one to test it on.

Glaiel's bot isn't good enough?

#ngprogramming at irc.freenode.net
haXe | Keel imperative | Spyro! | Thru you


None

Smith

Reply To Post Reply & Quote

Posted at: 11/26/08 07:56 PM

Smith EVIL LEVEL 25

Sign-Up: 10/13/04

Posts: 135

At 11/26/08 05:24 AM, GustTheASGuy wrote:
At 11/25/08 06:30 PM, Smith wrote: Started on my AI, It sux not having another good one to test it on.
Glaiel's bot isn't good enough?

Its good but other people might have a completely different approach that i hasn't thought of and my bot won't be prepared for.

More bots would be nice but I cant see anyone wanting to show others their code and give them the chance to steal it :D

anyway nine still needs alot of work so i shouldn't relly worry about harder bots


All times are Eastern Standard Time (GMT -5) | Current Time: 10:49 PM

<< Back

This topic is 2 pages long. [ 1 | 2 ]

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!