Commit 2311a7d8 authored by Matthew Hausknecht's avatar Matthew Hausknecht

Introduced normalization for all of the state features.

parent fe5ddaf2
...@@ -63,6 +63,7 @@ class Trainer(object): ...@@ -63,6 +63,7 @@ class Trainer(object):
self._agentTeam = '' # Name of the team the agent is playing for self._agentTeam = '' # Name of the team the agent is playing for
self._agentNumInt = -1 # Agent's internal team number self._agentNumInt = -1 # Agent's internal team number
self._agentNumExt = -1 # Agent's external team number self._agentNumExt = -1 # Agent's external team number
self._agentServerPort = args.serverPort # Port for agent's server
# =============== MISC =============== # # =============== MISC =============== #
self._offenseTeam = '' # Name of the offensive team self._offenseTeam = '' # Name of the offensive team
self._defenseTeam = '' # Name of the defensive team self._defenseTeam = '' # Name of the defensive team
...@@ -97,12 +98,12 @@ class Trainer(object): ...@@ -97,12 +98,12 @@ class Trainer(object):
self._agentNumExt = self.convertToExtPlayer(self._agentTeam, self._agentNumExt = self.convertToExtPlayer(self._agentTeam,
self._agentNumInt) self._agentNumInt)
agentCmd = 'start_agent.sh -t %s -u %i --numTeammates %i --numOpponents %i'\ agentCmd = 'start_agent.sh -t %s -u %i --numTeammates %i --numOpponents %i'\
' --playingOffense %i'\ ' --playingOffense %i --serverPort %i'\
%(self._agentTeam, self._agentNumExt, numTeammates, numOpponents, %(self._agentTeam, self._agentNumExt, numTeammates, numOpponents,
self._agent_play_offense) self._agent_play_offense, self._agentServerPort)
agentCmd = agentCmd.split(' ') agentCmd = agentCmd.split(' ')
# Ignore stderr because librcsc continually prints to it # Ignore stderr because librcsc continually prints to it
kwargs = {'stderr':open('/dev/null','w')} kwargs = {}#{'stderr':open('/dev/null','w')}
p = subprocess.Popen(agentCmd, **kwargs) p = subprocess.Popen(agentCmd, **kwargs)
p.wait() p.wait()
with open('/tmp/start%i' % p.pid,'r') as f: with open('/tmp/start%i' % p.pid,'r') as f:
......
...@@ -101,6 +101,8 @@ def parseArgs(args=None): ...@@ -101,6 +101,8 @@ def parseArgs(args=None):
help='Don\'t use a learning agent.') help='Don\'t use a learning agent.')
p.add_argument('--no-sync', dest='sync', action='store_false', default=True, p.add_argument('--no-sync', dest='sync', action='store_false', default=True,
help='Run server in non-sync mode') help='Run server in non-sync mode')
p.add_argument('--server-port', dest='serverPort', type=int, default=6008,
help='Port to run agent server on.')
return p.parse_args(args=args) return p.parse_args(args=args)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -77,6 +77,7 @@ usage() ...@@ -77,6 +77,7 @@ usage()
echo " --numTeammates NUM number of teammates" echo " --numTeammates NUM number of teammates"
echo " --numOpponents NUM number of opponents" echo " --numOpponents NUM number of opponents"
echo " --playingOffense [0|1] are we playing offense or defense" echo " --playingOffense [0|1] are we playing offense or defense"
echo " --serverPort NUM port for server to list on"
echo " --seed NUM seed for rng" echo " --seed NUM seed for rng"
echo " --gdb runs with gdb on (default:off)" echo " --gdb runs with gdb on (default:off)"
) 1>&2 ) 1>&2
...@@ -265,6 +266,15 @@ do ...@@ -265,6 +266,15 @@ do
shift 1 shift 1
;; ;;
--serverPort)
if [ $# -lt 2 ]; then
usage
exit 1
fi
opts="${opts} --serverPort ${2}"
shift 1
;;
--seed) --seed)
if [ $# -lt 2 ]; then if [ $# -lt 2 ]; then
usage usage
......
This diff is collapsed.
...@@ -90,28 +90,57 @@ protected: ...@@ -90,28 +90,57 @@ protected:
// Get the current game status // Get the current game status
hfo_status_t getGameStatus(); hfo_status_t getGameStatus();
// Encodes an angle feature as the sin and cosine of that angle,
// effectively transforming a single angle into two features.
void addAngFeature(const rcsc::AngleDeg& ang);
// Encodes a proximity feature which is defined by a distance as
// well as a maximum possible distance, which acts as a
// normalizer. Encodes the distance as [0-far, 1-close]. Ignores
// distances greater than maxDist or less than 0.
void addDistFeature(float dist, float maxDist);
// Add the angle and distance to the landmark to the feature_vec // Add the angle and distance to the landmark to the feature_vec
void addLandmarkFeature(const rcsc::Vector2D& landmark, void addLandmarkFeatures(const rcsc::Vector2D& landmark,
const rcsc::Vector2D& self_pos); const rcsc::Vector2D& self_pos,
const rcsc::AngleDeg& self_ang);
// Add features corresponding to another player.
void addPlayerFeatures(rcsc::PlayerObject& player,
const rcsc::Vector2D& self_pos,
const rcsc::AngleDeg& self_ang);
// Start the server and listen for a connection.
void startServer(int server_port=6008);
int numTeammates; // Transmit information to the client and ensure it can recieve.
int numOpponents; void clientHandshake();
protected:
int numTeammates; // Number of teammates in HFO
int numOpponents; // Number of opponents in HFO
bool playingOffense; // Are we playing offense or defense? bool playingOffense; // Are we playing offense or defense?
int numFeatures; // Total number of features int numFeatures; // Total number of features
// Number of features for non-player objects. Clearly this is the answer. // Number of features for non-player objects.
const static int num_basic_features = 42; const static int num_basic_features = 58;
// Number of features for each player or opponent in game. // Number of features for each player or opponent in game.
const static int features_per_player = 5; const static int features_per_player = 8;
std::vector<float> feature_vec; // Contains the current features
int featIndx; // Feature being populated int featIndx; // Feature being populated
const static int server_port = 6008; std::vector<float> feature_vec; // Contains the current features
long lastTrainerMessageTime; // Last time the trainer sent a message
bool episode_start; // True only in the timestep that the game is starting
// Start the server and listen for a connection. // Observed values of some parameters.
virtual void startServer(); const static float observedSelfSpeedMax = 0.46;
// Transmit information to the client and ensure it can recieve. const static float observedPlayerSpeedMax = 0.75;
virtual void clientHandshake(); const static float observedStaminaMax = 8000.;
const static float observedBallSpeedMax = 3.0;
float maxHFORadius; // Maximum possible distance in HFO playable region
// Useful measures defined by the Server Parameters
float pitchLength, pitchWidth, pitchHalfLength, pitchHalfWidth,
goalHalfWidth, penaltyAreaLength, penaltyAreaWidth;
long lastTrainerMessageTime; // Last time the trainer sent a message
int server_port; // Port to start the server on
bool server_running; // Is the server running?
int sockfd, newsockfd; // Server sockets
private: private:
bool doPreprocess(); bool doPreprocess();
...@@ -122,8 +151,6 @@ protected: ...@@ -122,8 +151,6 @@ protected:
Communication::Ptr M_communication; Communication::Ptr M_communication;
FieldEvaluator::ConstPtr M_field_evaluator; FieldEvaluator::ConstPtr M_field_evaluator;
ActionGenerator::ConstPtr M_action_generator; ActionGenerator::ConstPtr M_action_generator;
bool server_running; // Is the server running?
int sockfd, newsockfd; // Server sockets
}; };
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment