Guest User

Untitled

a guest
Apr 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. void Ant::update( GameState* state ) {
  2.  
  3.    enemiesinsight = 0;
  4.    foodinsight = 0;
  5.    friendsinsight = 0;
  6.  
  7.    std::queue<Location> locqueue;
  8.    Location cloc, nloc;
  9.  
  10.    std::vector<std::vector<bool> > visited(state->rows, std::vector<bool>( state->cols, 0 ));
  11.  
  12.    locqueue.push(loc);
  13.  
  14.    state->map[loc.row][loc.col].flags |= S_VISIBLE_BIT;
  15.    visited[loc.row][loc.col] = 1;
  16.  
  17.    while( !locqueue.empty() ) {
  18.       cloc = locqueue.front();
  19.       locqueue.pop();
  20.  
  21.       for ( int d = 0; d < TDIRECTIONS; ++d ) {
  22.          nloc = getloc( cloc, d );
  23.          if (!visited[nloc.row][nloc.col] && GameState::distance2(loc, nloc) <= state->viewrange) {
  24.             locqueue.push(nloc);
  25.          }
  26.       }
  27.  
  28.       state->map[cloc.row][cloc.col].flags |= S_VISIBLE_BIT;
  29.  
  30.       if ( state->map[cloc.row][cloc.col].ant > 0 ) enemiesinsight++;
  31.       if ( state->map[cloc.row][cloc.col].flags & S_FOOD_BIT ) foodinsight++;
  32.       if ( state->map[cloc.row][cloc.col].ant == 0 ) friendsinsight++;
  33.  
  34.       visited[cloc.row][cloc.col] = 1;
  35.    }
  36. }
Add Comment
Please, Sign In to add comment