Commit 2a7f23b1 authored by Matthew Hausknecht's avatar Matthew Hausknecht

Added start script for agent. Refactored state variables.

parent 8ad9a9e7
......@@ -85,14 +85,19 @@ class Trainer(object):
self._agentTeam = self._offenseTeam
self._agentNumInt = 1 if self._numOffense == 1 \
else self._rng.randint(1, self._numOffense)
numTeammates = self._numOffense - 1
numOpponents = self._numDefense
else:
assert self._numDefense > 0
self._agentTeam = self._defenseTeam
self._agentNumInt = 0 if self._numDefense == 1 \
else self._rng.randint(0, self._numDefense)
numTeammates = self._numOffense
numOpponents = self._numDefense - 1
self._agentNumExt = self.convertToExtPlayer(self._agentTeam,
self._agentNumInt)
agentCmd = 'start_agent.sh -t %s -u %i'%(self._agentTeam, self._agentNumExt)
agentCmd = 'start_agent.sh -t %s -u %i --numTeammates %i --numOpponents %i'\
%(self._agentTeam, self._agentNumExt, numTeammates, numOpponents)
agentCmd = agentCmd.split(' ')
# Ignore stderr because librcsc continually prints to it
kwargs = {'stderr':open('/dev/null','w')}
......@@ -475,22 +480,23 @@ class Trainer(object):
def getOffensiveResetPosition(self):
""" Returns a random position for an offensive player. """
offsets = [
[-1,-1],
[-1,1],
[1,1],
[1,-1],
[0,2],
[0,-2],
[-2,-2],
[-2,2],
[2,2],
[2,-2],
]
offset = offsets[self._rng.randint(len(offsets))]
offset_from_ball = 0.1 * self.PITCH_LENGTH * self._rng.rand(2) + \
0.1 * self.PITCH_LENGTH * numpy.array(offset)
return self.boundPoint(self._ballPosition + offset_from_ball)
# offsets = [
# [-1,-1],
# [-1,1],
# [1,1],
# [1,-1],
# [0,2],
# [0,-2],
# [-2,-2],
# [-2,2],
# [2,2],
# [2,-2],
# ]
# offset = offsets[self._rng.randint(len(offsets))]
# offset_from_ball = 0.1 * self.PITCH_LENGTH * self._rng.rand(2) + \
# 0.1 * self.PITCH_LENGTH * numpy.array(offset)
# return self.boundPoint(self._ballPosition + offset_from_ball)
return self._ballPosition
def getDefensiveResetPosition(self):
""" Returns a random position for a defensive player. """
......
This diff is collapsed.
This diff is collapsed.
......@@ -37,8 +37,7 @@
class Agent : public rcsc::PlayerAgent {
public:
Agent();
virtual ~Agent();
std::vector<float> getState();
virtual ~Agent() {};
virtual FieldEvaluator::ConstPtr getFieldEvaluator() const;
protected:
......@@ -59,11 +58,24 @@ protected:
virtual FieldEvaluator::ConstPtr createFieldEvaluator() const;
virtual ActionGenerator::ConstPtr createActionGenerator() const;
private:
// Updated the state features stored in feature_vec
void updateStateFeatures();
// Add the angle and distance to the landmark to the feature_vec
void addLandmarkFeature(const rcsc::Vector2D& landmark,
const rcsc::Vector2D& self_pos,
std::vector<float>& feature_vec);
const rcsc::Vector2D& self_pos);
int numTeammates;
int numOpponents;
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 each player or opponent in game.
const static int features_per_player = 5;
std::vector<float> feature_vec; // Contains the current features
int featIndx; // Feature being populated
private:
bool doPreprocess();
bool doShoot();
bool doForceKick();
......
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