From d80cc5ccac789de81646ad15258d3aa12a1c8f26 Mon Sep 17 00:00:00 2001 From: torcs-ng Date: Mon, 26 Jul 2010 15:49:05 +0000 Subject: [PATCH] add session time for driver hymie git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@2571 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 662f8ade8734b9353578aac39951d5ca2c017360 Former-commit-id: e00285b98ce97d51fe4f26c4ed87b6b6de8bb783 --- src/drivers/hymie/driver.h | 1 + src/drivers/hymie/hymie.xml | 11 +++++++++++ src/drivers/hymie/strategy.cpp | 33 +++++++++++++++++++++++++++++---- src/drivers/hymie/strategy.h | 2 ++ src/interfaces/robot.h | 1 + src/interfaces/simu.h | 10 +++++----- 6 files changed, 49 insertions(+), 9 deletions(-) diff --git a/src/drivers/hymie/driver.h b/src/drivers/hymie/driver.h index 3cfdb390b..7b3f4391f 100644 --- a/src/drivers/hymie/driver.h +++ b/src/drivers/hymie/driver.h @@ -41,6 +41,7 @@ #define HYMIE_SECT_PRIV "hymie" #define HYMIE_ATT_FUELPERLAP "fuelperlap" +#define HYMIE_ATT_FUELPERSECOND "fuelpersecond" #define HYMIE_ATT_MUFACTOR "mufactor" class Opponents; diff --git a/src/drivers/hymie/hymie.xml b/src/drivers/hymie/hymie.xml index 2210efdbd..d1a11607b 100644 --- a/src/drivers/hymie/hymie.xml +++ b/src/drivers/hymie/hymie.xml @@ -28,6 +28,7 @@ +
@@ -40,6 +41,7 @@ +
@@ -52,6 +54,7 @@ +
@@ -64,6 +67,7 @@ +
@@ -76,6 +80,7 @@ +
@@ -88,6 +93,7 @@ +
@@ -100,6 +106,7 @@ +
@@ -112,6 +119,7 @@ +
@@ -124,6 +132,7 @@ +
@@ -136,6 +145,7 @@ +
@@ -146,6 +156,7 @@ +
diff --git a/src/drivers/hymie/strategy.cpp b/src/drivers/hymie/strategy.cpp index 8b9f3f09d..14a8cf619 100644 --- a/src/drivers/hymie/strategy.cpp +++ b/src/drivers/hymie/strategy.cpp @@ -25,7 +25,7 @@ #include "strategy.h" const float SimpleStrategy::MAX_FUEL_PER_METER = 0.0008f; // [kg/m] fuel consumtion. - +const float SimpleStrategy::MAX_FUEL_PER_SECOND = 2.7f/60.0f; // [kg/s] fuel consumtion. SimpleStrategy::SimpleStrategy() : fuelchecked(false), @@ -48,10 +48,13 @@ SimpleStrategy::~SimpleStrategy() void SimpleStrategy::setFuelAtRaceStart(tTrack* t, void **carParmHandle, tSituation *s) { // Load and set parameters. - float fuel = GfParmGetNum(*carParmHandle, HYMIE_SECT_PRIV, HYMIE_ATT_FUELPERLAP, (char*) NULL, t->length*MAX_FUEL_PER_METER); + float fuel = GfParmGetNum(*carParmHandle, HYMIE_SECT_PRIV, HYMIE_ATT_FUELPERSECOND, (char*) NULL, MAX_FUEL_PER_SECOND); + expectedfuelpersecond = fuel; + fuel = GfParmGetNum(*carParmHandle, HYMIE_SECT_PRIV, HYMIE_ATT_FUELPERLAP, (char*) NULL, t->length*MAX_FUEL_PER_METER); expectedfuelperlap = fuel; maxfuel = GfParmGetNum(*carParmHandle, SECT_CAR, PRM_TANK, (char*) NULL, 100.0); fuel *= (s->_totLaps + 1.0); + fuel += expectedfuelpersecond * MAX(s->_totTime,0); lastfuel = MIN(fuel, maxfuel); if (s->_raceType == RM_TYPE_PRACTICE) lastfuel = maxfuel; @@ -180,6 +183,12 @@ bool SimpleStrategy::needPitstop(tCarElt* car, tSituation *s, Opponents *opp) if (laps > 0) { float cmpfuel = (fuelperlap == 0.0) ? expectedfuelperlap : fuelperlap; + if (s->_totTime > s->currentTime) + { + if (car->_laps > 2) + laps += (int)ceil( ( s->_totTime - s->currentTime ) / car->_bestLapTime + 0.3f ); + // For the case car->laps <= 2, the old laps only makes a stronger constraight, so no read to calculate it + } if (car->_fuel < 1.5*cmpfuel && car->_fuel < laps*cmpfuel) { @@ -252,6 +261,18 @@ float SimpleStrategy::pitRefuel(tCarElt* car, tSituation *s) { float fuel; float cmpfuel = (fuelperlap == 0.0) ? expectedfuelperlap : fuelperlap; + int laps = car->_remainingLaps; + if (s->_totTime > s->currentTime) + { + if (car->_laps > 2) + laps += ( s->_totTime - s->currentTime ) / car->_bestLapTime; + } + else + { + // It has a pit stop in the first two laps. Normally we don't want to refuel. + // This will cause for at least sufficient fuel. + laps += 5; + } fuel = MAX(MIN((car->_remainingLaps+1.5)*cmpfuel - car->_fuel, car->_tank - car->_fuel), 0.0); imaxfuel = GfParmGetNum(car->_carHandle, HYMIE_SECT_PRIV, "MaxFuel", (char*) NULL, fuel); if (imaxfuel > 0.0) @@ -268,8 +289,12 @@ int SimpleStrategy::pitRepair(tCarElt* car, tSituation *s, Opponents *opp) pit_damage = 0; if (car->_dammage > PIT_DAMMAGE || car->_remainingLaps-car->_lapsBehindLeader > 40) { - float cmpfuel = (fuelperlap == 0.0) ? expectedfuelperlap : fuelperlap; - float fuel = MAX(MIN((car->_remainingLaps+1.0)*cmpfuel, car->_tank), 0.0); + float laps = car->_remainingLaps + 1.0f; + if (car->_laps > 2 && s->_totTime > s->currentTime) + laps += ceil( ( s->_totTime - s->currentTime ) / car->_bestLapTime + 0.3f ); + float cmpfuel = (fuelperlap == 0.0) ? expectedfuelperlap : fuelperlap; + float fuel = MAX(MIN(laps*cmpfuel - car->_fuel, car->_tank), 0.0); + if (fuel < car->_tank-15.0) dammage = MIN(car->_dammage, dammage); else diff --git a/src/drivers/hymie/strategy.h b/src/drivers/hymie/strategy.h index 3f92aad5e..adf27bcf9 100644 --- a/src/drivers/hymie/strategy.h +++ b/src/drivers/hymie/strategy.h @@ -89,9 +89,11 @@ class SimpleStrategy : public AbstractStrategy { float lastpitfuel; // Amount refueled, special case when we refuel. float lastfuel; // the fuel available when we cross the start lane. float expectedfuelperlap; // Expected fuel per lap (may be very inaccurate). + float expectedfuelpersecond; // Expected fuel per second (may be very inaccurate). float imaxfuel; static const float MAX_FUEL_PER_METER; // [kg/m] fuel consumtion. + static const float MAX_FUEL_PER_SECOND; // [kg/s] fuel consumtion. int PIT_DAMMAGE; // If damage > we request a pit stop. int pit_damage; int min_damage; diff --git a/src/interfaces/robot.h b/src/interfaces/robot.h index 0b2cbc1dd..508461883 100755 --- a/src/interfaces/robot.h +++ b/src/interfaces/robot.h @@ -109,6 +109,7 @@ typedef struct RobotItf { #define ROB_VAL_FEATURE_PENALTIES "penalties" #define ROB_VAL_FEATURE_TIMEDSESSION "timed_session" +#define ROB_VAL_FEATURE_WEATHER "weather" #endif /* _ROBOTV1_H_ */ diff --git a/src/interfaces/simu.h b/src/interfaces/simu.h index f9890eed1..01a2d047d 100755 --- a/src/interfaces/simu.h +++ b/src/interfaces/simu.h @@ -40,12 +40,12 @@ typedef tDynPt* (*tfGetSimCarTable)(int index); typedef struct { - tfSimInit init; - tfSimConfig config; - tfSimReConfig reconfig; - tfSimUpdate update; + tfSimInit init; + tfSimConfig config; + tfSimReConfig reconfig; + tfSimUpdate update; tfSimSingleUpdate singleupdate; - tfSimShutdown shutdown; + tfSimShutdown shutdown; tfUpdateSimCarTable updatesimcartable; tfGetSimCarTable getsimcartable;