for(int i=0; i<10; i++)
{
for(int y=0;y<59;y++)
{
for(int x=0;x<59;x++)
{
int playerx=(objCamera.mPos.x*8)+8;
int playery=(objCamera.mPos.z*8)+8;
int enemyx=enemy.x;
int enemyy=enemy.z;
enemy.potential[playerx][playery]=0;
int d=sqrt((playerx-x)*(playerx-x)+(playery-y)*(playery-y));
enemy.potential[x][y]=d;
if(map[y*59+x]!=0)
{
enemy.potential[x][y]=1000;
}
if(enemy.potential[enemyx][enemyy+1]<enemy.potential[enemyx][enemyy])
{
enemy.z+=0.5;
}
if(enemy.potential[enemyx+1][enemyy+1]<enemy.potential[enemyx][enemyy])
{
enemy.z+=0.5;
enemy.x+=0.5;
}
if(enemy.potential[enemyx+1][enemyy+0]<enemy.potential[enemyx][enemyy])
{
enemy.x+=0.5;
}
if(enemy.potential[enemyx+1][enemyy-1]<enemy.potential[enemyx][enemyy])
{
enemy.z-=0.5;
enemy.x+=0.5;
}
if(enemy.potential[enemyx][enemyy-1]<enemy.potential[enemyx][enemyy])
{
enemy.z-=0.5;
}
if(enemy.potential[enemyx-1][enemyy-1]<enemy.potential[enemyx][enemyy])
{
enemy.z-=0.5;
enemy.x-=0.5;
}
if(enemy.potential[enemyx-1][enemyy]<enemy.potential[enemyx][enemyy])
{
enemy.x-=0.5;
}
if(enemy.potential[enemyx-1][enemyy+1]<enemy.potential[enemyx][enemyy])
{
enemy.x-=0.5;
enemy.z+=0.5;
}
}
}
potential Fields
I recently finished researching potential fields and tried doing an implementation. Didn't work well. Vista gives me "Cataclysm Engine.exe has stopped working" bla bla blah.... It has nothing to do with RAM or CPU usage. I'm missing something here. Need a fresh pair of eyes to look at this. Here's the source for the AI.
When you run it through the debugger, what happens? Does it crash, infinitely loop, etc?
Are you also handling all the exit button events correctly and whatnot?
[EDIT: offhand you're doing a ton of array indexing and never once checking to make sure that your indices are within the bounds of the arrays.]
-me
Are you also handling all the exit button events correctly and whatnot?
[EDIT: offhand you're doing a ton of array indexing and never once checking to make sure that your indices are within the bounds of the arrays.]
-me
I get "an access violation (segmentation fault) raised in your program" at this code.
Yeah... what happens if the [whatever+1] or [whatever-1] is outside the bounds of your array? e.g. if whatever is 0... I would have to assume that your array would not appreciate [-1].
Seriously... trace your code during execution and stick all these values in watch windows.
Alternately, mix in a few assert() commands. There's actually a great implementation of how to really milk your asserts in one of the Gems books (#1 I believe - "Squeezing more out of Assert"). That will save your bacon in that you will get the assert call before the program bails - and if you use those techniques you can have it tell you exactly where it bailed and why.
Seriously... trace your code during execution and stick all these values in watch windows.
Alternately, mix in a few assert() commands. There's actually a great implementation of how to really milk your asserts in one of the Gems books (#1 I believe - "Squeezing more out of Assert"). That will save your bacon in that you will get the assert call before the program bails - and if you use those techniques you can have it tell you exactly where it bailed and why.
Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play
"Reducing the world to mathematical equations!"
Quote:
Original post by brandonman
I get "an access violation (segmentation fault) raised in your program" at this code.
At which code? At which line number? What are the values of the variables at that point?
-me
Quote:This is a good point. Here's a few resources to get you going. Arguably rather heavy weight in their approach concerning your situation, but good from a learning experience point of view.
Original post by InnocuousFoxAlternately, mix in a few assert() commands. There's actually a great implementation of how to really milk your asserts in one of the Gems books (#1 I believe - "Squeezing more out of Assert"). .
Enhancing Assertions by Andrei Alexandrescu and John Torjo.
This article, co-authored with John Torjo, describes John's definition of a full-featured, industrial-strength assertion facility. The package features multiple debug levels, logging and a means for collecting detailed state information.
and Enforcements by Andrei Alexandrescu.
You gotta love writing error-handling code-you know, all the joy of testing conventions and formatting strings and throwing exceptions and...This is no joke. After you read "Enforcements," maybe you'll agree: error handling can be fun. The inimitable duo of ScopeGuard fame hits again, this time to take the boredom away from error-handling code.
---Sudet ulvovat - karavaani kulkee
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement