I am working on a project that docks ships within 3 docks and each dock has 10 rows and row has 5 smallBerths, 3 medium, 2 large.
I am trying to get my program to check through the rows and say if at that row index the smallBerths.size() < 5 then dock the ship and return true.
If this does not work try again in the next row.
So at the moment I am trying to put in 50 ships which should fill dock1 and there smallBerths completely.
The code I am using to do that is
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
int num_Small_Ships = 50;
for (int i = 0; i < num_Small_Ships; i++)
{
ship->_size = Ship::ShipSizes::SMALL;
ship->_shipName = "TestShip";
for (int i = 0; i < port._Port.size(); i++)
{
if (port._Port[i].dock(*ship) == true)
{
i = port._Port.size();
}
else
{
//do stuff
}
}
}
The code that is ran inside dock at the moment is
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
if (ship._size == Ship::ShipSizes::SMALL)
{
for (int i = 0; i < test._Rows.size(); i++)
{
if (test._Rows[i]._smallBerths.size() < SMALL_SIZE)
{
_smallBerths.push_back(ship);
returntrue;
}
}
}
Currently when this code is ran it puts 50 into the first smallBerth vector even though the size shouldn't go past 5.
When I take for (int i = 0; i < test._Rows.size(); i++) out it works fine but obviously does not loop through the rows.