agent.h 3.5 KB
Newer Older
Matthew Hausknecht's avatar
Matthew Hausknecht committed
1 2 3 4 5 6
#ifndef AGENT_H
#define AGENT_H

#include "action_generator.h"
#include "field_evaluator.h"
#include "communication.h"
7
#include "feature_extractor.h"
8
#include "common.hpp"
Matthew Hausknecht's avatar
Matthew Hausknecht committed
9 10 11 12

#include <rcsc/player/player_agent.h>
#include <vector>

13
class Agent : public rcsc::PlayerAgent {
Matthew Hausknecht's avatar
Matthew Hausknecht committed
14
public:
15
  Agent();
16
  virtual ~Agent();
17
  virtual FieldEvaluator::ConstPtr getFieldEvaluator() const;
Matthew Hausknecht's avatar
Matthew Hausknecht committed
18

19
  // Returns the feature extractor corresponding to the feature_set_t
20
  static FeatureExtractor* getFeatureExtractor(hfo::feature_set_t feature_set,
21 22 23 24
                                               int num_teammates,
                                               int num_opponents,
                                               bool playing_offense);

25 26
  inline long statusUpdateTime() { return lastStatusUpdateTime; }

27 28 29 30 31 32 33
  // Process incoming trainer messages. Used to update the game status.
  void ProcessTrainerMessages();
  // Process incoming teammate messages.
  void ProcessTeammateMessages();
  // Update the state features from the world model.
  void UpdateFeatures();

Matthew Hausknecht's avatar
Matthew Hausknecht committed
34
protected:
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
  // You can override this method. But you must call
  // PlayerAgent::initImpl() in this method.
  virtual bool initImpl(rcsc::CmdLineParser& cmd_parser);

  // main decision
  virtual void actionImpl();

  // communication decision
  virtual void communicationImpl();
  virtual void handleActionStart();
  virtual void handleActionEnd();
  virtual void handleServerParam();
  virtual void handlePlayerParam();
  virtual void handlePlayerType();
  virtual FieldEvaluator::ConstPtr createFieldEvaluator() const;
  virtual ActionGenerator::ConstPtr createActionGenerator() const;

52
 protected:
53 54 55 56
  hfo::feature_set_t feature_set;      // Requested feature set
  FeatureExtractor* feature_extractor; // Extracts the features
  long lastTrainerMessageTime;         // Last time the trainer sent a message
  long lastTeammateMessageTime;        // Last time a teammate sent a message
57
  long lastStatusUpdateTime;           // Last time we got a status update
58 59 60 61
  hfo::status_t game_status;           // Current status of the game
  hfo::Player player_on_ball;          // Player in posession of the ball
  std::vector<float> state;            // Vector of current state features
  std::string say_msg, hear_msg;       // Messages to/from teammates
62
  hfo::action_t requested_action;      // Currently requested action
63 64 65 66 67 68 69
  std::vector<float> params;           // Parameters of current action

 public:
  inline const std::vector<float>& getState() { return state; }
  inline hfo::status_t getGameStatus() { return game_status; }
  inline const hfo::Player& getPlayerOnBall() { return player_on_ball; }
  inline const std::string& getHearMsg() { return hear_msg; }
70
  int getUnum(); // Returns the uniform number of the player
71 72 73

  inline void setFeatureSet(hfo::feature_set_t fset) { feature_set = fset; }
  inline std::vector<float>* mutable_params() { return &params; }
74
  inline void setAction(hfo::action_t a) { requested_action = a; }
75
  inline void setSayMsg(const std::string& message) { say_msg = message; }
76 77

 private:
78
  bool doPreprocess();
79
  bool doSmartKick();
80
  bool doShoot();
81
  bool doPass();
82
  bool doPassTo(int receiver);
83 84
  bool doDribble();
  bool doMove();
85 86
  bool doForceKick();
  bool doHeardPassReceive();
87 88 89 90 91 92 93
  bool doMarkPlayer(int unum);
  bool doMarkPlayerNearIndex(int near_index);
  bool doReduceAngleToGoal();
  bool doDefendGoal();
  bool doGoToBall();
  bool doNewAction1();

94 95 96 97

  Communication::Ptr M_communication;
  FieldEvaluator::ConstPtr M_field_evaluator;
  ActionGenerator::ConstPtr M_action_generator;
Matthew Hausknecht's avatar
Matthew Hausknecht committed
98 99 100
};

#endif