#define BCAR_PSLOT_H
#include <ostream>
+#include <vector>
#include "bcar.hh"
namespace bcar {
/*! Return `true` if `c`'s car frame collide with `this` border. */
bool collide(BicycleCar const& c) const;
+ /*! \brief Drive car `c` into the parking slot `this`.
+ *
+ * \param c Starting bicycle car.
+ * \param max Maximum number of backward-forward direction changes.
+ */
+ std::vector<BicycleCar> drive_in_slot(BicycleCar c, unsigned int& max);
+
friend std::ostream& operator<<(std::ostream& o, ParkingSlot const& s);
};
&& c.front().intersects_with(this->front_);
}
+std::vector<BicycleCar>
+ParkingSlot::drive_in_slot(BicycleCar c, unsigned int& max)
+{
+ assert(this->parallel());
+ assert(this->right());
+ assert(c.len() < this->len());
+ assert(c.w() < this->w());
+ std::vector<BicycleCar> path;
+ path.reserve(max + 2);
+ path.push_back(c);
+ unsigned int cusp = 0;
+ while (cusp < max) {
+ if (c.h() < this->h()) {
+ return std::vector<BicycleCar>();
+ }
+ if (this->parked(c)) {
+ if (cusp < max) {
+ max = cusp;
+ }
+ break;
+ }
+ c.next();
+ if (this->collide(c)) {
+ c.sp(c.sp() * -1.0);
+ c.next();
+ path.push_back(c);
+ c.st(c.st() * -1.0);
+ cusp += 1;
+ }
+ }
+ path.push_back(c);
+ return path;
+}
+
std::ostream&
operator<<(std::ostream& o, ParkingSlot const& s)
{