hymie_36GP - crash fixes

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@1081 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: e3a5771fae4012dc86f3aeaf51ac14f0cc334cf2
Former-commit-id: af1b8387ff268df70fcc806358c4d8ddb81974c2
This commit is contained in:
andrewsumner 2009-07-09 05:07:38 +00:00
parent f9bcea7df7
commit 823a972609
3 changed files with 18 additions and 11 deletions

View file

@ -79,6 +79,7 @@ LearnedGraph::LearnedGraph( double minX, double maxX, int xSteps, double initial
LearnedGraph::~LearnedGraph()
{
delete [] m_pData;
delete [] m_pAxis;
}
int LearnedGraph::GetNAxes() const
@ -166,7 +167,7 @@ void LearnedGraph::SetBeta( double beta )
double LearnedGraph::CalcValue( int dim, int offs, const Idx* idx ) const
{
if( dim < m_nAxes )
if( dim < m_nAxes && dim >= 0 )
{
int offs_i = offs + m_pAxis[dim].m_itemSize * idx[dim].i;
int offs_j = offs + m_pAxis[dim].m_itemSize * idx[dim].j;
@ -182,7 +183,7 @@ double LearnedGraph::CalcValue( int dim, int offs, const Idx* idx ) const
void LearnedGraph::LearnValue( int dim, int offs, const Idx* idx, double delta )
{
if( dim < m_nAxes )
if( dim < m_nAxes && dim >= 0 )
{
int offs_i = offs + m_pAxis[dim].m_itemSize * idx[dim].i;
int offs_j = offs + m_pAxis[dim].m_itemSize * idx[dim].j;

View file

@ -2132,6 +2132,7 @@ void MyRobot::Drive( int index, tCarElt* car, tSituation* s )
// acc = MN(acc, 0.2);
}
#if 0
if( car->ctrl.accelCmd == 1 && car->ctrl.brakeCmd == 0 )
{
m_maxAccel.Learn( car->_speed_x, car->_accel_x );
@ -2140,6 +2141,7 @@ void MyRobot::Drive( int index, tCarElt* car, tSituation* s )
// GfOut( " %4.1f", m_maxAccel.GetY(i) );
// GfOut( "\n" );
}
#endif
if( fabs(pi.k * spd0 - car->_yaw_rate) < 0.02 )
{
@ -2309,7 +2311,8 @@ void MyRobot::AvoidOtherCars(
{for( int i = 0; i < m_nCars; i++ )
{
m_opp[i].ProcessMyCar( s, &m_pShared->m_teamInfo, car, mySit, *this,
m_maxAccel.CalcY(car->_speed_x), m_aggression, i );
car->_speed_x, m_aggression, i );
//m_maxAccel.CalcY(car->_speed_x), m_aggression, i );
}}
#if defined(USE_NEW_AVOIDANCE)

View file

@ -38,7 +38,7 @@
static const int NBOTS = 20;//2;
static int NBBOTS = 0;
static MyRobot s_robot[NBOTS];
static MyRobot *s_robot[NBOTS];
static Shared s_shared;
static const int BUFSIZE = 256;
static const int MAXNBBOTS = 20;
@ -199,6 +199,8 @@ static int InitFuncPt( int index, void* pt )
tRobotItf* itf = (tRobotItf*)pt;
s_robot[index - indexOffset] = new MyRobot();
// Create robot instance for index.
itf->rbNewTrack = initTrack; // Give the robot the track view called.
itf->rbNewRace = newRace; // Start a new race.
@ -224,41 +226,42 @@ static int InitFuncPt( int index, void* pt )
static void initTrack( int index, tTrack* track, void* carHandle,
void** carParmHandle, tSituation* s )
{
s_robot[index].SetShared( &s_shared );
s_robot[index].InitTrack(index, track, carHandle, carParmHandle, s);
s_robot[index - indexOffset]->SetShared( &s_shared );
s_robot[index - indexOffset]->InitTrack(index - indexOffset, track, carHandle, carParmHandle, s);
}
// Start a new race.
static void newRace( int index, tCarElt* car, tSituation* s )
{
s_robot[index].NewRace( index, car, s );
s_robot[index - indexOffset]->NewRace( index - indexOffset, car, s );
}
// Drive during race.
static void drive( int index, tCarElt* car, tSituation* s )
{
s_robot[index].Drive( index, car, s );
s_robot[index - indexOffset]->Drive( index - indexOffset, car, s );
}
// Pitstop callback.
static int pitcmd( int index, tCarElt* car, tSituation* s )
{
return s_robot[index].PitCmd(index, car, s);
return s_robot[index - indexOffset]->PitCmd(index - indexOffset, car, s);
}
// End of the current race.
static void endRace( int index, tCarElt* car, tSituation* s )
{
s_robot[index].EndRace( index, car, s );
s_robot[index - indexOffset]->EndRace( index - indexOffset, car, s );
}
// Called before the module is unloaded.
static void shutdown( int index )
{
s_robot[index].Shutdown( index );
s_robot[index]->Shutdown( index - indexOffset );
delete s_robot[index - indexOffset];
}