Skip to content

Commit

Permalink
Remove old commented code relating to old neighbour exchange
Browse files Browse the repository at this point in the history
  • Loading branch information
horgh committed Mar 27, 2011
1 parent f39d8aa commit 12296c4
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 448 deletions.
341 changes: 0 additions & 341 deletions map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,347 +500,6 @@ class Map {
return;
}

/*
Add the given puck to the given map
*/
/*
void
add_border_puck(antixtransfer::SendMap *map, Puck *p) {
antixtransfer::SendMap::Puck *p_pb = map->add_puck();
p_pb->set_x( p->x );
p_pb->set_y( p->y );
p_pb->set_held( p->held );
}
*/

/*
Add given robot to the given map
*/
/*
void
add_border_robot(antixtransfer::SendMap *map, Robot *r) {
antixtransfer::SendMap::Robot *r_pb = map->add_robot();
r_pb->set_x( r->x );
r_pb->set_y( r->y );
r_pb->set_team( r->team );
r_pb->set_id( r->id );
}
*/

/*
Debug function. Make sure the given robot is actually in the given map
True if it is, false otherwise
*/
/*
bool
check_in_border_robot(antixtransfer::SendMap *map, Robot *r) {
for (int i = 0; i < map->robot_size(); i++) {
if (map->robot(i).id() == r->id && map->robot(i).team() == r->team)
return true;
}
#if DEBUG
cout << "Error: robot not found in border map! In cell " << r->index << " id " << r->id << " team " << r->team << " at (" << r->x << ", " << r->y << ")" << endl;
#endif
return false;
}
*/

/*
Debug function: Look through robot vector and find those that need to be
in border map. Make sure they are actually in the given border maps
We don't check puck since it's hard to identify exactly due to no id
*/
/*
void
check_correct_robots_in_border(antixtransfer::SendMap *border_map_left, antixtransfer::SendMap *border_map_right) {
for (vector<Robot *>::iterator it = robots.begin(); it != robots.end(); it++) {
if ((*it)->x > my_max_x - Robot::vision_range) {
//cout << "Robot at " << (*it)->x << ", " << (*it)->y << " cell " << antix::Cell( (*it)->x, (*it)->y ) << endl;
assert(check_in_border_robot(border_map_right, *it));
}
else if ((*it)->x < my_min_x + Robot::vision_range) {
//cout << "Robot at " << (*it)->x << ", " << (*it)->y << " cell " << antix::Cell( (*it)->x, (*it)->y ) << endl;
assert(check_in_border_robot(border_map_left, *it));
}
}
}
*/

/*
Debug function. Make sure the given Robot is in the given move_bot message
True if it is, false otherwise
*/
/*
bool
check_in_move_msg(Robot *r, antixtransfer::move_bot *move_bot) {
for (int i = 0; i < move_bot->robot_size(); i++) {
if (move_bot->robot(i).id() == r->id && move_bot->robot(i).team() == r->team)
return true;
}
#if DEBUG
cout << "Error: robot not found in move msg! In cell " << r->index << endl;
#endif
return false;
}
*/

/*
Debug function: Look through robot vector & find those that need to be moved
Make sure they are actually in the given move messages
*/
/*
void
check_correct_robots_in_move(antixtransfer::move_bot *move_left_msg,
antixtransfer::move_bot *move_right_msg) {
for (vector<Robot *>::iterator it = robots.begin(); it != robots.end(); it++) {
// If robot's x is less than ours and bigger than our left neighbours, send
// to our left neighbour
if ((*it)->x < my_min_x && (*it)->x > my_min_x - antix::offset_size) {
assert(check_in_move_msg(*it, move_left_msg));
// Otherwise if it's less than ours and smaller than our left neighbour's,
// assume that we are the far right node: send it to our right neighbour
} else if ((*it)->x < my_min_x) {
assert(check_in_move_msg(*it, move_right_msg));
// If robot's x is bigger than ours and smaller than our right neighbour's,
// we send it to our right neighbour
} else if ((*it)->x >= my_max_x && (*it)->x < my_max_x + antix::offset_size) {
assert(check_in_move_msg(*it, move_right_msg));
// Otherwise it's bigger than ours and bigger than our right neighbour's,
// assume we are the far left node: send it to our left neighbour
} else if ((*it)->x >= my_max_x) {
assert(check_in_move_msg(*it, move_left_msg));
}
}
}
*/

/*
Look at the pucks and robots in the given cell
Add them to the respective protobuf messages if necessary
*/
/*
void
examine_border_cell(int index,
antixtransfer::move_bot *move_left_msg,
antixtransfer::move_bot *move_right_msg,
antixtransfer::SendMap *border_map_left,
antixtransfer::SendMap *border_map_right,
int side) {
// Robots
// while loop as iterator may be updated due to deletion
// NOTE: Can't remove function call to end it seems or fails asserts when
// removing robots. Possibly due to removal of final robot sometimes?
vector<Robot *>::iterator it_robot = Robot::matrix[index].robots.begin();
while (it_robot != Robot::matrix[index].robots.end()) {
// First we look whether robot needs to move to another node
if (side == LEFT_CELLS) {
// If robot's x is less than ours and bigger than our left neighbours,
// send to our left neighbour
if ((*it_robot)->x < my_min_x && (*it_robot)->x > my_min_x - antix::offset_size) {
#if DEBUG
cout << "Moving robot " << (*it_robot)->id << " on team " << (*it_robot)->team << " to left node (1) turn " << antix::turn << endl;
#endif
add_robot_to_move_msg(*it_robot, move_left_msg);
it_robot = remove_robot(it_robot);
continue;
// Otherwise if it's less than ours and smaller than our left neighbour's,
// assume that we are the far right node: send it to our right neighbour
} else if ((*it_robot)->x < my_min_x) {
#if DEBUG
cout << "Moving robot " << (*it_robot)->id << " on team " << (*it_robot)->team << " to right node (2) turn " << antix::turn << endl;
#endif
add_robot_to_move_msg(*it_robot, move_right_msg);
it_robot = remove_robot(it_robot);
continue;
}
// Otherwise right side cell
} else {
// If robot's x is bigger than ours and smaller than our right neighbour's,
// we send it to our right neighbour
if ((*it_robot)->x >= my_max_x && (*it_robot)->x < my_max_x + antix::offset_size) {
#if DEBUG
cout << "Moving robot " << (*it_robot)->id << " on team " << (*it_robot)->team << " to right node (3) turn " << antix::turn << endl;
#endif
add_robot_to_move_msg(*it_robot, move_right_msg);
it_robot = remove_robot(it_robot);
continue;
// Otherwise it's bigger than ours and bigger than our right neighbour's,
// assume we are the far left node: send it to our left neighbour
} else if ((*it_robot)->x >= my_max_x) {
#if DEBUG
cout << "Moving robot " << (*it_robot)->id << " on team " << (*it_robot)->team << " to left node (4) turn " << antix::turn << endl;
#endif
add_robot_to_move_msg(*it_robot, move_left_msg);
it_robot = remove_robot(it_robot);
continue;
}
}
// Check whether on the border
if (side == LEFT_CELLS) {
if ((*it_robot)->x < my_min_x + Robot::vision_range)
add_border_robot(border_map_left, *it_robot);
// Right side
} else {
if ((*it_robot)->x > my_max_x - Robot::vision_range)
add_border_robot(border_map_right, *it_robot);
}
it_robot++;
}
vector<Puck *>::iterator it_puck = Robot::matrix[index].pucks.begin();
vector<Puck *>::const_iterator end_puck = Robot::matrix[index].pucks.end();
// Pucks
for ( ; it_puck != end_puck; it_puck++) {
if (side == LEFT_CELLS) {
if ((*it_puck)->x < my_min_x + Robot::vision_range)
add_border_puck(border_map_left, *it_puck);
} else {
if ((*it_puck)->x > my_max_x - Robot::vision_range)
add_border_puck(border_map_right, *it_puck);
}
}
}
*/

/*
Look at the robots on the far left and far right of our matrix
Find those which need to be moved to another node, add them to move messages,
and remove.
Find those which are within sight distance to tell our neighbours and add them
to border messages.
We do this at same time as we only want to iterate over the cells once
*/
/*
void
build_moves_and_border_entities(antixtransfer::move_bot *move_left_msg,
antixtransfer::move_bot *move_right_msg,
antixtransfer::SendMap *border_map_left,
antixtransfer::SendMap *border_map_right) {
// old move messages no longer valid
move_left_msg->clear_robot();
move_right_msg->clear_robot();
// old maps are no longer valid
border_map_left->clear_robot();
border_map_left->clear_puck();
border_map_right->clear_robot();
border_map_right->clear_puck();
// we are rebuilding those to send to our neighbours, they are doing the same
// so clear our old data on neighbour's border entities
foreign_pucks.clear();
foreign_robots.clear();
// Now we look at robots and pucks on the sides of the matrix
// XXX all of these loops can probably be tightened to include less cols
// look down the cells on far left
// check 3 furthest left cols
int left_limit = antix::matrix_left_x_col + 10;
for (int x = antix::matrix_left_x_col - 10; x < left_limit; x++) {
for (int y = 0; y < antix::matrix_height; y++) {
// 2d array into 1d matrix: x + y*width
int index = x + y * antix::matrix_height;
//cout << "Index left " << index << " x " << x << " y " << y << endl;
if (index >= Robot::matrix.size())
continue;
assert(index < Robot::matrix.size());
// Look at the robots & pucks
examine_border_cell(index, move_left_msg, move_right_msg, border_map_left, border_map_right, LEFT_CELLS);
}
}
// and on far right
// check 3 farthest right columns. start from column on furthest right
// and go back
int right_limit = antix::matrix_right_x_col - 10;
for (int x = antix::matrix_right_x_col + 10; x > right_limit; x--) {
for (int y = 0; y < antix::matrix_height; y++) {
if (x < 0)
continue;
// 2d array into 1d matrix: x + y*width
int index = x + y * antix::matrix_height;
if (index >= Robot::matrix.size())
continue;
//cout << "Index right " << index << " x " << x << " y " << y << endl;
assert(index < Robot::matrix.size());
examine_border_cell(index, move_left_msg, move_right_msg, border_map_left, border_map_right, RIGHT_CELLS);
}
}
// far right node can have index for bot move into far left
for (int y = 0; y < antix::matrix_height; y++) {
int index = 0 + y * antix::matrix_height;
//cout << "Index far left " << index << " x " << 0 << " y " << y << endl;
assert(index < Robot::matrix.size());
examine_border_cell(index, move_left_msg, move_right_msg, border_map_left, border_map_right, LEFT_CELLS);
}
// far left node can have index for bot move into far right
int far_right_limit = antix::matrix_right_world_x_col - 10;
for (int x = antix::matrix_right_world_x_col + 10; x > far_right_limit; x--) {
for (int y = 0; y < antix::matrix_height; y++) {
if (x < 0)
continue;
int index = x + y * antix::matrix_height;
if (index >= Robot::matrix.size())
continue;
assert(index < Robot::matrix.size());
//cout << "Index far right " << index << " x " << x << " y " << y << endl;
examine_border_cell(index, move_left_msg, move_right_msg, border_map_left, border_map_right, RIGHT_CELLS);
}
}
*/

// It's also possible for robots to wrap around to cells on far side of world
// this may only be needed for far left node?
/*
for (int x = antix::matrix_right_world_x_col; x >= antix::matrix_right_world_x_col - 2; x--) {
for (int y = 0; y < antix::matrix_height; y++) {
// 2d array into 1d matrix: x + y*width
int index = x + y * antix::matrix_height;
assert(index < Robot::matrix.size());
//assert(index < antix::matrix_height * antix::matrix_width);
//cout << "Index FAR right " << index << " x " << x << " y " << y << endl;
examine_border_cell(index, move_left_msg, move_right_msg, border_map_left, border_map_right, RIGHT_CELLS);
//examine_border_cell(index, move_left_msg, move_right_msg, border_map_left, border_map_right, LEFT_CELLS);
}
}
*/
/*
assert( antix::matrix_left_x_col < Robot::matrix.size() );
examine_border_cell(antix::matrix_left_x_col, move_left_msg, move_right_msg, border_map_left, border_map_right, LEFT_CELLS);
assert( antix::matrix_right_x_col < Robot::matrix.size() );
examine_border_cell(antix::matrix_right_x_col, move_left_msg, move_right_msg, border_map_left, border_map_right, RIGHT_CELLS);
*/

/*
#ifndef NDEBUG
check_correct_robots_in_border(border_map_left, border_map_right);
check_correct_robots_in_move(move_left_msg, move_right_msg);
#endif
}
*/

/*
Build a map with one entry per team, each entry being a protobuf message stating
what the robots in that team see
Expand Down
Loading

0 comments on commit 12296c4

Please sign in to comment.