I''ve been working on this with my cousin for a few days now, and am having trouble getting the bot to avoid the various objects strewn in his path. Mainly, he keeps running into walls and getting stuck in the corner of the map. I''d like to fix that problem first, as it should hopefully allow me to finish getting a decent base for movement, or at least point me in the right direction. Does anyone have input on how they solved this problem (if they had it)? I don''t want the code directly, but I will not complain if that''s what I get

Pseudo-code or the basic idea would be more than I have right now, and is all I can hope for. Any help will be much appreciated! If you''d like to see our code, we have included it below.
A little class we wrote for containment
int numObjects;
class object
{
public:
float distance;
float direction;
int type;
float objDirection;
private:
protected:
};
object objects[20];
Now the Update() function
// Update cycle entry point. Your AI code goes here.
numObjects=g_pCore->GetNumObjectsInSight();
// See all the objects that you can, and store them in an array
for (int i=0; i<numObjects; i++)
{
g_pCore->GetObjectsInSight(i,objects[i].type, objects[i].direction, objects[i].distance, objects[i].objDirection);
}
for (int closest=0, a=0; a<numObjects; a++)
{
if (objects[a].distance <= objects[closest].distance)
closest = a;
}
if(objects[closest].type == OBJ_UNIDENTIFIED)
g_pCore->Taunt("ERROR!");
if(objects[closest].type == OBJ_TREE)
g_pCore->Taunt("Tree");
if(objects[closest].type == OBJ_BIGROCK)
g_pCore->Taunt("Big Rock");
if(objects[closest].type == OBJ_SMALLROCK)
g_pCore->Taunt("Small Rock");
if(objects[closest].type == OBJ_GRENADE)
g_pCore->Taunt("Grenade");
if(objects[closest].type == OBJ_ENEMY)
g_pCore->Taunt("Enemy");
if(objects[closest].type == OBJ_AMMO)
g_pCore->Taunt("Ammo");
if(objects[closest].type == OBJ_WALL)
g_pCore->Taunt("Wall");
g_pCore->SetSpeed(SET_NORMAL_SPEED);
if(objects[closest].distance < 8)
{
if (objects[closest].direction < 0.0f)
{
g_pCore->TurnRight(TURN_FAST);
} else {
g_pCore->TurnLeft(TURN_FAST);
}
} else {
g_pCore->SetSpeed(SET_NORMAL_SPEED);
}