本文整理汇总了C++中Agent::GetCoord方法的典型用法代码示例。如果您正苦于以下问题:C++ Agent::GetCoord方法的具体用法?C++ Agent::GetCoord怎么用?C++ Agent::GetCoord使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Agent
的用法示例。
在下文中一共展示了Agent::GetCoord方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Think
Brain::ActionType Brain::Think(Agent &agent) {
Brain::ActionType next_move;
do {
stayAlert(agent);
meditate();
//tellCurrentPath();
if (priorize(agent)) {
in_path = true;
//tellCurrentPath();
}
if (!in_path) {
int x, y, orientation;
agent.GetCoord(y, x, orientation);
pair<int, int> coords = pair<int, int>(x, y);
translateToMoves(coords, orientation, calculateGoalAndPath(agent));
//tellCurrentPath();
in_path = true;
}
if (current_path.empty()) {
in_path = false;
next_move = Brain::ActionType::actIDLE;
} else {
next_move = current_path.front();
current_path.pop();
}
} while (next_move == Brain::ActionType::actIDLE && !endgame);
steps++;
return next_move;
}
示例2: Astar
deque<pair<int, int> > Brain::calculateGoalAndPath(Agent& agent) {
int x, y, orientation;
pair<bool, bool> solved;
getGoal(agent);
deque<pair<int, int> > path;
agent.GetCoord(y, x, orientation);
//cout << "-----------------------------" << endl;
//yellWhatImDoing(agent.getCoord());
Astar astar_alg = Astar(agent.mapa_entorno_, agent.mapa_objetos_, pair<int, int>(x, y), current_goal);
solved = astar_alg.solve();
if (solved.second) {
this->current_goal = astar_alg.getGoal();
}
if (!solved.first) {
//cout << "ERROR: no se me ocurre una forma de descubrir más mapa!" << endl;
cout << "PASOS: " << steps << endl;
if (map_oriented == false) {
cout << "ERROR, mapa no orientado" << endl;
exit(0);
}
cout << "MAP ORIENTATION: " << this->map_orientation << endl;
agent.cropAndStoreSolutionMap();
agent.rotateSolution(this->map_orientation);
agent.isSolved();
this->endgame = true;
//exit(0);
}
//yellWhatImDoing(agent.getCoord());
//cout << "-----------------------------" << endl;
path = deque<pair<int, int> >(astar_alg.getSolution());
//astar_alg.printRoute();
return path;
}
示例3: stayAlert
void Brain::stayAlert(Agent& agent) {
int x, y, orientation;
agent.GetCoord(y, x, orientation);
pair<int, int> coords = pair<int, int>(x, y);
for (int i = 1; i < SIGHT_LENGTH; i++) {
//Check important_surface
pair<int, int> item_coords = translateSensorToCoords(orientation, i, coords);
checkSurface(agent.whatISeeThere(i).first, coords, item_coords);
checkSurface(agent.whatISeeThere(i).second, coords, item_coords);
}
}
示例4: priorize
bool Brain::priorize(Agent& agent) {
bool there_is_something_there = false;
map<pair<int, int>, Memory>::iterator it = objectives.begin();
if (!this->objectives.empty()) {
int x, y, orientation;
pair<bool, bool> solved;
getGoal(agent);
deque<pair<int, int> > path;
agent.GetCoord(y, x, orientation);
pair<int, int> coords = pair<int, int>(x, y);
map<pair<int, int>, Memory>::iterator it = this->objectives.begin();
this->current_goal = (*it).first;
bool iHaveItTouchingMaNose = (current_path.empty() && !this->objectives.empty()
&& (agent.whatISeeThere(1).first == (*it).second.getItem() || agent.whatISeeThere(1).second == (*it).second.getItem()));
bool iAmOnIt = (current_path.empty() && current_goal.first == x && current_goal.second == y);
if (iAmOnIt) {
//cout << "I AM ON IT" << endl;
iAmOnSomething((*it).second.getItem(), agent);
} else if (iHaveItTouchingMaNose) {
//cout << "I HAVE IT IN NOSE" << endl;
iHaveSomethingAhead((*it).second.getItem(), agent);
} else {
//yellWhatImDoing(agent.getCoord());
Astar astar_alg = Astar(agent.mapa_entorno_, agent.mapa_objetos_, coords, current_goal, true); //Cuidado, movimiento forzado
solved = astar_alg.solve();
if (solved.second) {
this->current_goal = astar_alg.getGoal();
}
if (!solved.first) {
cout << "ERROR: no se me ocurre una forma de encontrar lo que buscas, ni puedo encontrar más mapa!" << endl;
cout << "PASOS: " << steps << endl;
//exit(0);
}
while (!current_path.empty()) {
current_path.pop();
}
path = deque<pair<int, int> >(astar_alg.getSolution());
translateToMoves(coords, orientation, path);
}
there_is_something_there = true;
}
return there_is_something_there;
}
示例5: getGoal
void Brain::getGoal(Agent &agent) {
bool goal_found = false;
double current_distance = 1000000;
int goal_x, goal_y;
int x, y, orientacion;
agent.GetCoord(x, y, orientacion);
for (int i = 0; i < 200; i++) {
for (int j = 0; j < 200; j++) {
if (agent.mapa_entorno_[i][j] == '?') {
double d = sqrt(pow(i - x, 2) + pow(j - y, 2));
if (d < current_distance) {
goal_found = true;
goal_x = j;
goal_y = i;
current_distance = d;
}
}
}
}
if (goal_found) {
this->current_goal = make_pair(goal_x, goal_y);
}
//cout << "GOAL: " << current_goal.first << " " << current_goal.second << endl;
}