/** * \brief Change the state of the toggle. * \param b The new state. * \param activator The item that activates the toggle, if any. */ void bear::engine::with_toggle::toggle( bool b, base_item* activator ) { if ( b ) { if ( !is_on() ) toggle_on( activator ); } else if ( is_on() ) toggle_off( activator ); } // with_toggle::toggle()
LightMap LightMap::evolve() { LightMap result(max_x,max_y); for (unsigned int x = 0; x < max_x; x++) { for (unsigned int y = 0; y < max_y; y++) { if ( (!is_on(x,y)) && should_be_turned_on(x,y)) { result.turn_on(x,y); } if ( (is_on(x,y)) && (!should_be_turned_off(x,y))) { result.turn_on(x,y); } } } return result; }
unsigned int LightMap::get_active_lights() const { unsigned int light_count = 0; for (unsigned int x = 0; x < max_x; x++) { for(unsigned int y = 0; y <max_y; y++) { if (is_on(x,y)) { light_count++; } } } return light_count; }
unsigned int LightMap::get_number_of_on_neighbors(unsigned int x, unsigned int y) { unsigned int number_of_on_neighbors = 0; for (short x_diff = (x == 0 ? 0 : -1); x_diff <= 1; x_diff++) { for (short y_diff = (y == 0 ? 0: -1); y_diff <= 1; y_diff++) { if ((x_diff == 0) && (y_diff==0)) { continue; } unsigned int target_x = x + x_diff; unsigned int target_y = y + y_diff; if ((target_x >= max_x) || (target_y >= max_y)) { continue; } if (is_on(target_x, target_y)) { number_of_on_neighbors++; } } } return number_of_on_neighbors; }
inline bool operator[](size_type w) const { NTA_ASSERT(w < board.size()); return is_on(w); }
/** * \brief Change the state of the toggle. * \param activator The item that activates the toggle, if any. */ void bear::engine::with_toggle::toggle( base_item* activator ) { toggle( !is_on(), activator ); } // with_toggle::toggle()