本文整理汇总了C++中Direction::get_from_integer方法的典型用法代码示例。如果您正苦于以下问题:C++ Direction::get_from_integer方法的具体用法?C++ Direction::get_from_integer怎么用?C++ Direction::get_from_integer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Direction
的用法示例。
在下文中一共展示了Direction::get_from_integer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update_shoot_variables
bool Info::update_shoot_variables (MapClass &Map)
{
int xdiff, ydiff;
char m_symbol;
Direction d;
can_shoot_at_enemy_falcon = false;
can_shoot_at_enemy_tank = false;
Position my_posn, f_posn, e_posn;
f_posn = this->opp_falcon.posn;
e_posn = this->opp_tank.posn;
xdiff = f_posn.x - curr_posn.x;
ydiff = f_posn.y - curr_posn.y;
if ((xdiff == 0) || (ydiff == 0))
{
if (xdiff == 0){
if (ydiff < 0){
d.get_from_integer (LEFT);
}
else
d.get_from_integer (RIGHT);
}
else if (ydiff == 0) {
if (xdiff < 0){
d.get_from_integer (UP);
}
else
d.get_from_integer (DOWN);
}
my_posn = curr_posn;
my_posn.go_in_direction (d);
while (!(my_posn == f_posn)){
m_symbol = Map.get_element (my_posn);
if (m_symbol == WALL || m_symbol == GOLD || m_symbol == MACHINE_GUN){
can_shoot_at_enemy_falcon = false;
break;
}
my_posn.go_in_direction (d);
}
if (my_posn == f_posn){
shoot_falcon_dirn = d;
can_shoot_at_enemy_falcon = true;
}
}
xdiff = e_posn.x - curr_posn.x;
ydiff = e_posn.y - curr_posn.y;
if (xdiff != 0 && ydiff != 0){
return 1;
}
if (xdiff == 0){
if (ydiff < 0){
d.get_from_integer (LEFT);
}
else
d.get_from_integer (RIGHT);
}
else if (ydiff == 0) {
if (xdiff < 0){
d.get_from_integer (UP);
}
else
{
d.get_from_integer (DOWN);
}
}
my_posn = curr_posn;
my_posn.go_in_direction (d);
while (!(my_posn == e_posn)){
m_symbol = Map.get_element (my_posn);
if (m_symbol == WALL || m_symbol == GOLD || m_symbol == MACHINE_GUN){
can_shoot_at_enemy_tank = false;
break;
}
my_posn.go_in_direction (d);
}
if (my_posn == e_posn){
shoot_enemy_tank_dirn = d;
can_shoot_at_enemy_tank = true;
}
return 1;
}
示例2: update_distances
void Info::update_distances(MapClass &map,Position source)
{
// This function does BREADTH FIRST TRAVERSAL on the Map and
// stores the distances in the appropriate objects. The logic is
// explained and you can change/add stuff to it if you want
queue <Position> q;
// visited : a 2D array which is used as a colour attribute in the BFT part
vector< vector <int> > visited(MAP_SIZE - 1,vector <int>(MAP_SIZE - 1,0));
// initial_move : a 2D array which stores the first moves to be
// made from the source to reach that position in BFT time
vector< vector <Move> > initial_move(MAP_SIZE - 1,vector <Move>(MAP_SIZE - 1));
// distance : a 2D vector which stores the BFT distances of various position
vector< vector <int> > distance(MAP_SIZE - 1,vector <int>(MAP_SIZE - 1, -1));
object_info temp_info_object, null_gold;
Position temp, temp1;
Direction d;
char char_buffer, map_element;
int x, y;
x=source.x;
y=source.y;
visited[x][y] = 1; // Set source to be visited
distance[x][y] = 0; // Distance from source to itself is 0
// Gold and bunker vectors need to be cleared,
// because each move we are rebuilding them.
// That is because they can change from move to move.
gold.clear ();
enemy_bunker.clear ();
// Initially pushing all the valid neighbors into the queue
// the initial_move must be appropiately assigned values
for(int i = 0; i<4; i++)
{
d.get_from_integer (i);
temp = source;
temp.go_in_direction (d);
map_element = map.get_element (temp);
if(map_element == enemy_ID.my_bunker || map_element == GOLD || map_element == EMPTY || map_element == BULLET1 || map_element == BULLET2 || map_element == enemy_ID.falcon_symbol){
// Unless the position is empty or gold
// dont enqueue the position.
if (map_element == enemy_ID.falcon_symbol){
opp_falcon.shortest_distance = 1;
opp_falcon.initial_move.dirn = d;
opp_falcon.posn = temp;
}
else{
q.push(temp);
initial_move[temp.x][temp.y].dirn = d;
visited[temp.x][temp.y] = 1; //set the colour
distance[temp.x][temp.y] = 1; //distance of the neighbours of source is 1.
}
}
}
// While queue is not empty bft proceeds
// This is the key BFT algo
while(q.empty()==false)
{
temp=q.front(); //temp is the first element in the queue
q.pop();
x = temp.x;
y = temp.y;
char_buffer = map.get_element(temp);
//get element returns the symbol of the given position
// Contains the info of the current node to be dequeued
temp_info_object.shortest_distance = distance[temp.x][temp.y];
temp_info_object.initial_move = initial_move[temp.x][temp.y];
temp_info_object.posn = temp;
// If the current position is GOLD push it into the
// gold gold vector
if(char_buffer == GOLD)
gold.push_back(temp_info_object);
if(char_buffer == enemy_ID.my_bunker)
enemy_bunker.push_back(temp_info_object);
// If the position is a tank or a falcon update the
// corresponding objects. But the neighbours shouldn't be
// pushed. so continue the process
else if (char_buffer == enemy_ID.tank_symbol)
{
opp_tank = temp_info_object;
}
else if (char_buffer == enemy_ID.falcon_symbol)
//.........这里部分代码省略.........