Putting entities into stacks

Discuss programming in the QuakeC language.
Post Reply
DusterdooSmock
Posts: 170
Joined: Thu Aug 19, 2010 9:58 pm

Putting entities into stacks

Post by DusterdooSmock »

Hey guys, I'm working on coding my own bot from scratch. So far, he's coming along great; he roams the map using waypoints, follows and attacks when he sees you, and goes back to roaming the map if he loses sight of you.

But, unfortunately, I'm having one problem with it.
- Each time he passes a waypoint, the game sets that point to a value that allows him to ignore the waypoint that he just passed, and move on to the next one. But, I'm having an issue with this, as he always "bounces" between the first two waypoints he sees.

I was told to create a system where the bot puts the waypoints into a stack, but to be honest with you, i dont know how to do that.
andrewj
Posts: 133
Joined: Mon Aug 30, 2010 3:29 pm
Location: Australia

Post by andrewj »

I think by stack it means remembering the last 4 (for example) waypoints that the bot visited.

Something like these fields:

Code: Select all

.entity lastway1;
.entity lastway2;
.entity lastway3;
.entity lastway4;
You can check if the bot has visited any of those places before to decide where to go next.

When the bot visits a new waypoint you need to add it to this "stack", something like:

Code: Select all

void() remember_way(entity way)
{
  self.lastway4 = self.lastway3;
  self.lastway3 = self.lastway2;
  self.lastway2 = self.lastway1;
  self.lastway1 = way;
}
DusterdooSmock
Posts: 170
Joined: Thu Aug 19, 2010 9:58 pm

Post by DusterdooSmock »

I tried that, and it still did the same thing; he goes to the first, then to the second, then back to the first. Over and over.

Maybe it was the way i checked it, i dunno..

Code: Select all

float(entity way) WaypointCheck = 
{
	if(way == self.lastway3)
		return FALSE;
	else if(way == self.lastway2)
		return FALSE;
	else if(way == self.lastway1)
		return FALSE;
	else
		return TRUE;
};
Then i have this when he tries to find a new waypoint:

Code: Select all

void() BotFindWaypoint = 
{
	local entity point;
	
	point = findradius(self.origin, 240);
	
	while(point)
	{
		if(WaypointCheck(point) == TRUE)
		{
			if(point.classname == "waypoint")
				self.objective = point;
		}
			
		point = point.chain;
	}
};
Electro
Posts: 312
Joined: Wed Dec 29, 2004 11:25 pm
Location: Brisbane, Australia
Contact:

Post by Electro »

Cool! Someone else is doing bot stuff too :)

Ok first of all, need to get some terminology sorted.

Stack = list of things
Push = add to the stack
Pop = remove from the stack

Usually when you push/pop things from a stack, you do it from either the top or the bottom. eg. Push to the top, pop from the bottom.

Now when someone told you the waypoints should be on a stack, generally that's a good way to go about it. For QuakeC though, with the general lack of arrays (you can however use arrays now thanks to new fancy compilers!), there is another way to go about things.

What Frikbot does, and what I was doing for Shockbot, is instead of having a massive additional list of waypoints that the bot intends to visit... flag each waypoint with the bots unique id. So when you figure out the path you want the bot to take, flag each waypoint that he will take on his path. Make the first waypoint he needs to visit the goal, then when he touches his goal (or gets within a certain distance threshold), remove the flag from that one. Now, check that waypoints list of connections to find which one has the flag on it out of those. Make the new linked one from there the new goal.
Benjamin Darling
http://www.bendarling.net/

Reflex - In development competitive arena fps combining modern tech with the speed, precision and freedom of 90's shooters.
http://www.reflexfps.net/
DusterdooSmock
Posts: 170
Joined: Thu Aug 19, 2010 9:58 pm

Post by DusterdooSmock »

Electro wrote:Cool! Someone else is doing bot stuff too :)

Ok first of all, need to get some terminology sorted.

Stack = list of things
Push = add to the stack
Pop = remove from the stack

Usually when you push/pop things from a stack, you do it from either the top or the bottom. eg. Push to the top, pop from the bottom.

Now when someone told you the waypoints should be on a stack, generally that's a good way to go about it. For QuakeC though, with the general lack of arrays (you can however use arrays now thanks to new fancy compilers!), there is another way to go about things.

What Frikbot does, and what I was doing for Shockbot, is instead of having a massive additional list of waypoints that the bot intends to visit... flag each waypoint with the bots unique id. So when you figure out the path you want the bot to take, flag each waypoint that he will take on his path. Make the first waypoint he needs to visit the goal, then when he touches his goal (or gets within a certain distance threshold), remove the flag from that one. Now, check that waypoints list of connections to find which one has the flag on it out of those. Make the new linked one from there the new goal.
Thanks to your help, and a little help I got from FrikaC earlier today, I have a basic version of my bot up and running.

Here, take a look:
http://www.moddb.com/games/fps/videos/fps-new-ai-test1
Electro
Posts: 312
Joined: Wed Dec 29, 2004 11:25 pm
Location: Brisbane, Australia
Contact:

Post by Electro »

No worries, glad to help out :)

Looks good so far! Can't wait to see it progress.

Feel free to post any other AI ideas/questions etc. Artificial Intelligence is my favourite part of coding, and that section on the forums here is a little dry at the moment.
Benjamin Darling
http://www.bendarling.net/

Reflex - In development competitive arena fps combining modern tech with the speed, precision and freedom of 90's shooters.
http://www.reflexfps.net/
daemonicky
Posts: 185
Joined: Wed Apr 13, 2011 1:34 pm

Post by daemonicky »

What about implementing Collaborative Diffusion?

There is explanation :
http://scalablegamedesign.cs.colorado.e ... _Diffusion

Google has some videos too, this Lagomorph:
http://www.google.com/search?q=collaborative+diffusion
Think, touch, movetype, solid, traceline ...
metlslime
Posts: 316
Joined: Tue Feb 05, 2008 11:03 pm

Post by metlslime »

Electro wrote:Usually when you push/pop things from a stack, you do it from either the top or the bottom. eg. Push to the top, pop from the bottom.
This describes a Queue. A Stack gets popped from the top, not the bottom.
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Post by frag.machine »

LIFO = last in, first out (stack)
FIFO = first in, first out (queue)

Both are useful data structures.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
Electro
Posts: 312
Joined: Wed Dec 29, 2004 11:25 pm
Location: Brisbane, Australia
Contact:

Post by Electro »

Cool, cheers :)
Benjamin Darling
http://www.bendarling.net/

Reflex - In development competitive arena fps combining modern tech with the speed, precision and freedom of 90's shooters.
http://www.reflexfps.net/
Post Reply