1 /***************************************************************************
2 
3     file                 : strategy.h
4     created              : Wed Sep 22 15:31:51 CET 2004
5     copyright            : (C) 2004 Bernhard Wymann
6     email                : berniw@bluewin.ch
7     version              : $Id: strategy.h,v 1.1.2.2 2008/11/09 17:50:19 berniw Exp $
8 
9  ***************************************************************************/
10 
11 /***************************************************************************
12  *                                                                         *
13  *   This program is free software; you can redistribute it and/or modify  *
14  *   it under the terms of the GNU General Public License as published by  *
15  *   the Free Software Foundation; either version 2 of the License, or     *
16  *   (at your option) any later version.                                   *
17  *                                                                         *
18  ***************************************************************************/
19 
20 /*
21 	Pit strategy for drivers. It defines an abstract base class, such that one can easily plug in
22 	different strategies.
23 */
24 
25 #ifndef _STRATEGY_H_
26 #define _STRATEGY_H_
27 
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <cstring>
31 #include <math.h>
32 
33 #include <tgf.h>
34 #include <track.h>
35 #include <car.h>
36 #include <raceman.h>
37 #include <robottools.h>
38 #include <robot.h>
39 
40 #include "driver.h"
41 
42 class AbstractStrategy {
43 	public:
44 
45 		// Need this empty constructor... do not remove.
~AbstractStrategy()46 		virtual ~AbstractStrategy() {}
47 		// Set Initial fuel at race start.
48 		virtual void setFuelAtRaceStart(tTrack* t, void **carParmHandle, tSituation *s, int index) = 0;
49 		// Update internal data at every timestep.
50 		virtual void update(tCarElt* car, tSituation *s) = 0;
51 		// Do we need a pit stop? Can be called less frequently.
52 		virtual bool needPitstop(tCarElt* car, tSituation *s) = 0;
53 		// How much to refuel at pit stop.
54 		virtual float pitRefuel(tCarElt* car, tSituation *s) = 0;
55 		// How much repair at pit stop.
56 		virtual int pitRepair(tCarElt* car, tSituation *s) = 0;
57 		// Pit Free?
58 		virtual bool isPitFree(tCarElt* car) = 0;
59 };
60 
61 
62 class SimpleStrategy : public AbstractStrategy {
63 	public:
64 		SimpleStrategy();
65 		~SimpleStrategy();
66 
67 		void setFuelAtRaceStart(tTrack* t, void **carParmHandle, tSituation *s, int index);
68 		void update(tCarElt* car, tSituation *s);
69 		bool needPitstop(tCarElt* car, tSituation *s);
70 		float pitRefuel(tCarElt* car, tSituation *s);
71 		int pitRepair(tCarElt* car, tSituation *s);
72 		bool isPitFree(tCarElt* car);
73 
74 	protected:
75 		bool m_fuelchecked;				// Fuel statistics updated.
76 		float m_fuelperlap;				// The maximum amount of fuel we needed for a lap.
77 		float m_lastpitfuel;			// Amount refueled, special case when we refuel.
78 		float m_lastfuel;				// the fuel available when we cross the start lane.
79 		float m_expectedfuelperlap;		// Expected fuel per lap (may be very inaccurate).
80 		float m_fuelsum;				// all the fuel used.
81 
82 		static const float MAX_FUEL_PER_METER;	// [kg/m] fuel consumtion.
83 		static const int PIT_DAMMAGE;			// If damage > we request a pit stop.
84 };
85 
86 
87 class SimpleStrategy2 : public SimpleStrategy {
88 	public:
89 		~SimpleStrategy2();
90 		void setFuelAtRaceStart(tTrack* t, void **carParmHandle, tSituation *s, int index);
91 		float pitRefuel(tCarElt* car, tSituation *s);
92 		void update(tCarElt* car, tSituation *s);
93 
94 
95 	protected:
96 		int m_remainingstops;
97 		float m_fuelperstint;
98 		float m_pittime;				// Expected additional time for pit stop.
99 		float m_bestlap;				// Best possible lap, empty tank and alone.
100 		float m_worstlap;				// Worst possible lap, full tank and alone.
101 
102 		virtual void updateFuelStrategy(tCarElt* car, tSituation *s);
103 };
104 
105 
106 #endif // _STRATEGY_H_
107 
108 
109