HOG2
RandomUnit.h
Go to the documentation of this file.
1 /*
2  * RandomUnit.h
3  * hog2
4  *
5  * Created by Nathan Sturtevant on 5/14/07.
6  * Copyright 2007 Nathan Sturtevant, University of Alberta. All rights reserved.
7  *
8  */
9 
10 #include "Unit.h"
11 
12 #ifndef RANDOMUNIT_H
13 #define RANDOMUNIT_H
14 
15 template <class state, class action, class environment>
16 class RandomUnit : public Unit<state, action, environment>
17 {
18 public:
19  RandomUnit(state startLoc) :loc(startLoc) {}
20  virtual ~RandomUnit() {}
21  virtual const char *GetName() { return "Random Unit"; }
22  virtual bool MakeMove(environment *theEnv, OccupancyInterface<state, action> *, SimulationInfo<state,action,environment> *, action& a)
23  {
24  std::vector<action> acts;
25  theEnv->GetActions(loc, acts);
26  a = acts[random()%acts.size()];
27  return true;
28  }
29  virtual void UpdateLocation(environment *, state &newloc, bool success, SimulationInfo<state,action,environment> *)
30  {
31  if (success)
32  loc = newloc;
33  }
34  virtual void GetLocation(state &l)
35  { l = loc; }
36  virtual void OpenGLDraw(const environment *theEnv, const SimulationInfo<state,action,environment> *si) const
37  {
39  si->GetPublicUnitInfo(si->GetCurrentUnit(), i);
40  printf("(%f-%f)/(%f-%f)\n",
42  theEnv->OpenGLDraw(i.lastState, i.currentState,
44  }
45  virtual void GetGoal(state &s)
46  { s = loc; }
47 private:
48  state loc;
49 };
50 
51 #endif
52 
RandomUnit::GetGoal
virtual void GetGoal(state &s)
Definition: RandomUnit.h:45
RandomUnit::MakeMove
virtual bool MakeMove(environment *theEnv, OccupancyInterface< state, action > *, SimulationInfo< state, action, environment > *, action &a)
Definition: RandomUnit.h:22
SimulationInfo
Definition: SimulationInfo.h:13
RandomUnit
A unit that moves in random directions changing direction randomly.
Definition: RandomUnit.h:16
SimulationInfo::GetSimulationTime
virtual double GetSimulationTime() const =0
RandomUnit::UpdateLocation
virtual void UpdateLocation(environment *, state &newloc, bool success, SimulationInfo< state, action, environment > *)
Definition: RandomUnit.h:29
PublicUnitInfo::nextTime
double nextTime
Definition: SimulationInfo.h:66
PublicUnitInfo::currentState
state currentState
Definition: SimulationInfo.h:61
RandomUnit::GetLocation
virtual void GetLocation(state &l)
Definition: RandomUnit.h:34
RandomUnit::RandomUnit
RandomUnit(state startLoc)
Definition: RandomUnit.h:19
loc
Definition: MapGenerators.cpp:296
PublicUnitInfo::lastState
state lastState
Definition: SimulationInfo.h:62
RandomUnit::GetName
virtual const char * GetName()
Definition: RandomUnit.h:21
RandomUnit::loc
state loc
Definition: RandomUnit.h:48
RandomUnit::~RandomUnit
virtual ~RandomUnit()
Definition: RandomUnit.h:20
SimulationInfo::GetPublicUnitInfo
virtual void GetPublicUnitInfo(unsigned int unitnum, PublicUnitInfo< state, action, environment > &) const =0
PublicUnitInfo::lastTime
double lastTime
Definition: SimulationInfo.h:65
SimulationInfo::GetCurrentUnit
virtual unsigned int GetCurrentUnit() const =0
RandomUnit::OpenGLDraw
virtual void OpenGLDraw(const environment *theEnv, const SimulationInfo< state, action, environment > *si) const
Definition: RandomUnit.h:36
PublicUnitInfo
Definition: SimulationInfo.h:9
Unit.h
Unit
Definition: Unit.h:23
OccupancyInterface
Definition: OccupancyInterface.h:36