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):
self._agentTeam = '' # Name of the team the agent is playing for
self._agentNumInt = -1 # Agent's internal team number
self._agentNumExt = -1 # Agent's external team number
self._agentServerPort = args.serverPort # Port for agent's server
# =============== MISC =============== #
self._offenseTeam = '' # Name of the offensive team
self._defenseTeam = '' # Name of the defensive team
......@@ -97,12 +98,12 @@ class Trainer(object):
self._agentNumExt = self.convertToExtPlayer(self._agentTeam,
self._agentNumInt)
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._agent_play_offense)
self._agent_play_offense, self._agentServerPort)
agentCmd = agentCmd.split(' ')
# 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.wait()
with open('/tmp/start%i' % p.pid,'r') as f:
......
......@@ -101,6 +101,8 @@ def parseArgs(args=None):
help='Don\'t use a learning agent.')
p.add_argument('--no-sync', dest='sync', action='store_false', default=True,
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)
if __name__ == '__main__':
......
......@@ -77,6 +77,7 @@ usage()
echo " --numTeammates NUM number of teammates"
echo " --numOpponents NUM number of opponents"
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 " --gdb runs with gdb on (default:off)"
) 1>&2
......@@ -265,6 +266,15 @@ do
shift 1
;;
--serverPort)
if [ $# -lt 2 ]; then
usage
exit 1
fi
opts="${opts} --serverPort ${2}"
shift 1
;;
--seed)
if [ $# -lt 2 ]; then
usage
......
This diff is collapsed.
......@@ -90,28 +90,57 @@ protected:
// Get the current game status
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
void addLandmarkFeature(const rcsc::Vector2D& landmark,
const rcsc::Vector2D& self_pos);
void addLandmarkFeatures(const rcsc::Vector2D& landmark,
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;
int numOpponents;
// Transmit information to the client and ensure it can recieve.
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?
int numFeatures; // Total number of features
// Number of features for non-player objects. Clearly this is the answer.
const static int num_basic_features = 42;
// Number of features for non-player objects.
const static int num_basic_features = 58;
// Number of features for each player or opponent in game.
const static int features_per_player = 5;
std::vector<float> feature_vec; // Contains the current features
const static int features_per_player = 8;
int featIndx; // Feature being populated
const static int server_port = 6008;
long lastTrainerMessageTime; // Last time the trainer sent a message
bool episode_start; // True only in the timestep that the game is starting
std::vector<float> feature_vec; // Contains the current features
// Start the server and listen for a connection.
virtual void startServer();
// Transmit information to the client and ensure it can recieve.
virtual void clientHandshake();
// Observed values of some parameters.
const static float observedSelfSpeedMax = 0.46;
const static float observedPlayerSpeedMax = 0.75;
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:
bool doPreprocess();
......@@ -122,8 +151,6 @@ protected:
Communication::Ptr M_communication;
FieldEvaluator::ConstPtr M_field_evaluator;
ActionGenerator::ConstPtr M_action_generator;
bool server_running; // Is the server running?
int sockfd, newsockfd; // Server sockets
};
#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