When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
23 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
The problem is that you start at just below the +, and you can only ever go straight down, or diagonally - so you just have to start straight down, and diagonally down
so change my int row = 1?
There's a couple methods, but that might be the easiest (plus adding a small condition that you don't overwrite the + with an o)
Yeah i changed the int row = 0, and it doesnt write to anything
but overwriting the + is how i get the marbles to print into the box
You also need to adjust your if (box[row][col] != '.') to be if (box[row][col] != '.' && box[row][col] != '+' ); otherwise it would exit before doing anything
why a '+'?
If I start a row = 1, itll never equal '+'
and starting a row = 0 kills my program
You are comepletly right , sorry
Only thing is it replaced my '+' with a 'o' (marble) for some reason
In that case, you can also do a for loop to start one to the left, straight down, and one to the right of (1, startingColumn); this is the alternative solution, which IMHO is uglier than starting at the +
It works now with your logic
just that it replaced my '+' with a marble , which i assume is the last iteration
You just need to guard your assignment of box[row][col] = 'o'; with an extra if (box[row][col] == '.') (and probably return false if that is not the case in an else)
bool dropMarble(vector<string> &box, int openingCol)
{
int row = 0; // Start at the opening
int col = openingCol;
if (box[row][col] != '.' && box[row][col] != '+')
{
return false;
}
while (row < box.size() - 1)
{
if (box[row + 1][col] == '.')
{
row++; // Fall straight down
}
else if (col > 1 && box[row + 1][col - 1] == '.')
{
row++; col--; // Move left
}
else if (col < box[0].size() - 2 && box[row + 1][col + 1] == '.')
{
row++; col++; // Move right
}
else if (box[row][col] == '.')
{
box[row][col] = 'o';
return true;
}
else
{
return false;
}
}
return false;
}
This is what I'm thinking should work, assuming the calling code works as I imagine
Thank you and let us know if you have any more questions!
This thread is now set to auto-hide after an hour of inactivity
@main spindle
Please don't delete forum posts. They can be helpful to refer to later and other members can learn from them. In the future you can use !solved to close a post and mark a post as solved.
@main spindle Has your question been resolved? If so, type !solved :)
!solved