Advertisement

How can my robots "see" what is next to them?

Started by December 06, 2005 01:53 PM
35 comments, last by GameDev.net 19 years, 2 months ago
Quote:
Original post by Barius
Quote:
Original post by xEricx
Define "physically could"


I just meant that if there are game rules concerning visibility, the robot shouldn't be able to break them.

Quote:

Depending on the "scale" of the simulation, you should use a "radius" within which you can see other items, which should try to resemble a common distance to which you could see in real life (ok, this has to be tweaked for gameplay, so its not really representing real life values, but you get my point).



OK. But what would be a good way to design and code this? Letting the robot access the map array is out of the question.



It seems like it is hard to "get away from" having to code this in a 2D array. I am only doing it because I don't know any other way to code it.

The ideal would be for the 2D array to BE the world...but for the Robot to NOT know about it. The only thing the confines of the array should be doing is keeping the Robot in the "laboratory" so to speak. The Robot would not (necessarily) know that the laboratory is 10 x 10 or 100 x 100. It would know that it could not go any further...and then based on its decision making, would try moving in a new direction or perform some other action.
As I said earlier, the robot should NOT use the 2D array. By doing something similar to:

World->GetObjectsAround(MyPosition, MySightRadius);

You hide the way the world is built, and only return objects of interest. The World is then free to say... multiply the value of MySightRadius by a 1 - fog intensity for example, or clamp MySightRadius to a certain value.

All you need to do is hide the inner workings of your system (the world) to your clients (the robots).

Hope this helps

Eric
Advertisement
Quote:
Original post by xEricx
As I said earlier, the robot should NOT use the 2D array. By doing something similar to:

World->GetObjectsAround(MyPosition, MySightRadius);

You hide the way the world is built, and only return objects of interest. The World is then free to say... multiply the value of MySightRadius by a 1 - fog intensity for example, or clamp MySightRadius to a certain value.

All you need to do is hide the inner workings of your system (the world) to your clients (the robots).

Hope this helps

Eric



Eric:

How do I keep track of the robots in the "world" without using a 2D array?

I want to have some unit of distance in the world.

At first, atleast, I want to have some bounds to the world that cannot be passed...otherwise my poor little robot will be miles and miles into the desert wasteland. :)
Quote:
Original post by Anonymous Poster
You should probably test if other robots are in it's line of sight by using a view frustum.

It's pretty easy, get the vector the robot is facing and get the distance vector to other robots in it's LOS radius. Than, if the dot product between them is in the frustum, than the robot can see the other robot. Unless you want it to be able to detect anything in it's radius (maybe it has some kind of sensors to detect behind it's back) than just sweep a circle and test if anything in the board is in the radius.




but what do I store the robot objects inside of?

It was suggested that a 2D array representation of the world may not be best (and it does seem rather limiting as well as counter-intuitive as far as supporting it in my source code)

Is there some other framework I can set up for my "world" that would be better than a 2D array of "robot" objects?
You DO use a 2D array for your world representation, but the robots do not need to know about it.
In response to your question towards AP:

It should be a 2D array of TILES, not robots... where each tile *can* (you'll have empty ones) hold objects, such as robots. Then, you have a list of robots, which you can use to call their "Update" function. The tiles can hold references to these robots, and when polling the environment around a robot, you simply use tiles which hold an object, and build a list of these objects and send it back to the robot.
Advertisement
Quote:
Original post by Anonymous Poster
Quote:
Original post by xEricx
You DO use a 2D array for your world representation, but the robots do not need to know about it.


It depends on his simulation. If it's discrete tile based, than the array matters.

If it's a continous based, than it doesn't matter, you just use physics and vector math.


I was replying to

"How do I keep track of the robots in the "world" without using a 2D array?"

The world owns an array but does not need to make it public. I know it matters for the bot to know if he's using discrete tiles or not, that's not what I was commenting about.
Quote:
Original post by xEricx
Quote:
Original post by Anonymous Poster
Quote:
Original post by xEricx
You DO use a 2D array for your world representation, but the robots do not need to know about it.


It depends on his simulation. If it's discrete tile based, than the array matters.

If it's a continous based, than it doesn't matter, you just use physics and vector math.


I was replying to

"How do I keep track of the robots in the "world" without using a 2D array?"

The world owns an array but does not need to make it public. I know it matters for the bot to know if he's using discrete tiles or not, that's not what I was commenting about.




I have updated my current code to align it a little bit more with the feedback I have gotten.

I now am using a 2D array of Objects....which can be WALLS, EMPTY, or ROBOT (All of which Inherit from Object).

If anyone cares to compile this and run this in C# I would really love to have some feedback and some advice.


NOTE: My original thought process and my intent was indeed to make this a closed environment...one in which the robot could walk so far in a certain direction before running into the "end of the world" (a wall).


Here is the source:


SIMULATION ZIPPED SOURCE CODE


Quote:
Original post by xEricx
Quote:
Original post by Anonymous Poster
Quote:
Original post by xEricx
You DO use a 2D array for your world representation, but the robots do not need to know about it.


It depends on his simulation. If it's discrete tile based, than the array matters.

If it's a continous based, than it doesn't matter, you just use physics and vector math.


I was replying to

"How do I keep track of the robots in the "world" without using a 2D array?"

The world owns an array but does not need to make it public. I know it matters for the bot to know if he's using discrete tiles or not, that's not what I was commenting about.





I still do not understand how to have the "Robot see the world" versus having to hand the entire world to the Robot so it can look at it.


I guess what I mean is this:


Although I have not BEEN to every country in the world, nor have I seen the world from outer space...other people have and have written about it and / or taken pictures that I can look at.

In essence...the world has been handed to me. I have a good idea about how big it is. I may never be able to travel around the globe, but that is a restriction of many things outside of my control (MONEY, time, hassle, wife, kids, work, etc.).

On the other hand...if I were in the middle of a city and had total memory loss...but I could still walk, communicate and make some basic decisions and had unlimited time, money, etc., I could start walking and come to the edge of the city. Then I could travel through the countryside. Eventually I would get to the ocean...and be sort of stuck...unless I decided to try and swim across or build a boat. I could discover the same world that the other me already knows about but will never travel to.


In one situation I know about the world in advance. I can trust Africa is real without ever going there.

In the other I do not know about the world but can still navigate through it. In time I can know everything the other "me" knows...by brute force.



Given enough time I would catch up to the omniscient version.



I want to get away from doing it this way (HANDING THE WORLD TO THE ROBOT):

public void LookAround(World temp_world)
{
N = temp_world.WhoIsAt(_row - 1, _col);
NE = temp_world.WhoIsAt(_row - 1, _col + 1);
E = temp_world.WhoIsAt(_row, _col + 1);
SE = temp_world.WhoIsAt(_row + 1, _col + 1);
S = temp_world.WhoIsAt(_row + 1, _col);
SW = temp_world.WhoIsAt(_row + 1, _col - 1);
W = temp_world.WhoIsAt(_row, _col - 1);
NW = temp_world.WhoIsAt(_row - 1,_col - 1);
}


WhoIsAt looks like this:


public string WhoIsAt(int temp_row, int temp_col)
{
string def_action = "wall";

if(temp_row < _MIN_ROW)
{
return def_action;
}
else if(temp_row > _MAX_ROW)
{
return def_action;
}
else if(temp_col < _MIN_COL)
{
return def_action;
}
else if(temp_col > _MAX_COL)
{
return def_action;
}
else
{
return obj[temp_row,temp_col].Kind;
}
}

[Edited by - Tom Knowlton on December 9, 2005 3:09:58 PM]
Quote:
Original post by Anonymous Poster
Sorry for this double post, but I think I see your confusion.

In a simulation you have to give the information of the world to the robot.

In a real mobot, you might not have a priori knowledge, and this would than be accumulated by the robot as it moved. This is a rather hard problem. The D* algorithm is one such algorithm which a robot can use to learn pathing in a dynamic range. A mobot might have a camera, and it would use computer vision algorithms to detect objects in it's sight, or it might have other sensors that can detect (maybe vibrations, etc). It depends on the mobot.

For your sim, you have to either give it some knowledge of the world or have it learn as it goes along.



I think I understand.


My code just does not seem to match what is in my head.


My code just seems so clumsy.


What I want is to sort of MIX the two worlds in code. Have a world which functions under a set of rules. Have a robot which functions under a set of rules. Put the robot in the world and set it loose to function according to it's own internal rules. The robot does not know the world is 10 x 10 or 20 x 20 or 100 x 100. All it can do is "look" in all directions once square at a time and based on what it finds it will move in a certain direction or do a certain action, then wait for the next cycle to do the same thing over again.


I keep coming back to the 2D array that is the "world". Even though it NOW supports different TYPES of objects........those objects are still in a 2D array. Everytime I want my robots to do something...I have to loop through the ENTIRE array because part of my simulation is not depending on the robots being in a certain place or having a certain number of robots. I just loop through the ENTIRE 2D array and when a robot is encountered I have it LOOK AROUND and then MOVE. It is sort of like the robot is just sitting there dormant until I reach that particular cell. Then it turns on, looks around, moves, turns off.


I want to put the robot in the world and turn it on. The world would then tell me periodically (ie, show me visually) what the world looks like...and oh, there happens to be a robot at this location.


Sorry...I hope I don't frustrate you with my ignorance. I really am trying to understand.


I am leaning more towards the second scenario...a robot that uses sensors to gather information about the world...keep track of where it has been...make decisions on where it wants to go based on stimuli.


My unspoken goal is to sort of creat something "ORGANIC" for lack of a better way to put it.

The appeal of Object Oriented Programming in my mind is I can have a Robot "instance" that has PUBLIC and PRIVATE data and methods. It can LOOK NORTH and determine WHAT IS NORTH by a SENSOR. It can do this ONE UNIT or ONE SQUARE at a time. The distance it moves happens to be ONE SQUARE...but this is known to the ROBOT only...and just happens to work in the WORLD the Robot has been put into. It just so happens (by sheer coincidence) that the world the Robot is in is also made of ONE SQUARE UNITS (but this is purely coincidence). Thus the Robot can move around the world (the are compatible in the units of movement) but it is the Robot deciding WHEN and HOW to move...and it knows nothing of the world...only ONE UNIT at a time in all directions.


Uuugh.

This topic is closed to new replies.

Advertisement