src/slice.cpp
/**
 *	Generate a random slice from the given pizza.
 */
Generate a random slice from the given pizza.
Generate a random slice from the given pizza .
Slice::Slice(const Pizza& pizza) {
	int cnt = pizza.cnt_, ts;
	do {
		w_ = min(pizza.C_, rand() % pizza.H_ + 1);
		h_ = min(pizza.R_, rand() % (pizza.H_ / w_) + 1);
		x_ = rand() % (pizza.C_ - w_ + 1);
		y_ = rand() % (pizza.R_ - h_ + 1);
		ts = pizza.get_tomatoes(y_, x_, y_ + h_ - 1, x_ + w_ - 1);
	} while((ts < pizza.L_ || ts > area() - pizza.L_) && cnt--);
}
Slice :: Slice ( const Pizza & pizza ) { int cnt = pizza . cnt_ , ts ; do { w_ = min ( pizza . C_ , rand ( ) % pizza . H_ + 1 ) ; h_ = min ( pizza . R_ , rand ( ) % ( pizza . H_ / w_ ) + 1 ) ; x_ = rand ( ) % ( pizza . C_ - w_ + 1 ) ; y_ = rand ( ) % ( pizza . R_ - h_ + 1 ) ; ts = pizza . get_tomatoes ( y_ , x_ , y_ + h_ - 1 , x_ + w_ - 1 ) ; } while ( ( ts < pizza . L_ || ts > area ( ) - pizza . L_ ) && cnt -- ) ; }
Generate a random slice from the given pizza.
Generate a random slice from the given pizza .
// Width of the slice should be at least one, // and at most the width of the pizza or the  // given maximum slice size. // Height bounds depend on the already determined // width as well. // Position should have the slice be contained within // the pizza. // Get the number of tomatoes on the slice. /*	if (x_ == 2 && y_ == 0 && w_ == 1 && h_ == 3) {
		cout << "MID: " << ts << endl;
	} else if (x_ == 0 && y_ == 0 && w_ == 2 && h_ == 3) {
		cout << "LEFT: " << ts << endl;
	} else if (x_ == 3 && y_ == 0 && w_ == 2 && h_ == 3) {
		cout << "RIGHT: " << ts << endl;
	}*/ //cout << x_ <<  " " << y_ << " " <<  x_+w_ << " " << y_ + h_ << endl;