1
votes

So I have two structs that work together. This is a game that works like a bubble pop game.

When a balloon pops in the grid I want to use flood fill to remove the balloons an then have it using a stack so I can undo the process later.

1
Are you asking about an undo stack or about floodfill? What attempts have you made? Presumably your unfortunate term pop is related to the balloon game, not to a stack. If so can I suggest using burst internally to the program?Weather Vane
Im asking about flood fill with the stack. Also my flood fill doesnt work for some reason. Also it should be balloon_popcode
As bb_pop appears to be your recursive function, you might want to past that as well.Michael Dorgan
Bb should be baloon sorry. I edited itcode
bb_pop/balloon_pop returns a total score or something else?Michael Dorgan

1 Answers

1
votes

Used a pre-sized stack array to keep things simple. When you want your data back, just call pop_balloon until the stack is empty (use the function).

The following code is untested and pulled out of thin air, but it should show you want you need:


Balloon balloonStack[MAX_NUM_BALLOONS_POSSBILE];
int balloonStackIndex = 0;

bool balloonStackIsEmpty()
{
  return balloonStackIndex == 0;
}

void balloonPush(Balloon balloon)
{
  assert(balloonStackIndex &lt MAX_NUM_BALLOONS_POSSBILE);
  balloonStack[balloonStackIndex++] = balloon;
}

Balloon balloonPop()
{
  assert(balloonStackIndex > 0);
  return balloonStack[balloonStackIndex--]
}

int balloon_pop(BBoardPtr b, int r, int c) {

    if(b->board[r][c].color != None /*&& r >= 0 && c >= 0 && r rows && c cols*/) {
        return 0;
    }

    balloonPush(b->board[r][c]);
    b->board[r][c].color = None;
    b->board[r][c].is_popped = 1;
    //...