Gold Stack

  1. Parse input to array
  2. Inject the array to flipped stack
  3. while(command) do check if it is DIG OR USE
  4. If DIG then check whteher it need to be added to the item queue or loot queue or immediately active
  5. Don't bother to implement the function first, just make sure that when the specify item is found, you cout "Bomb active" or "Gold Found"
  6. Make Sure the input and the flow are correct untill the end
  7. Do from small test case first
  8. If you need idea or intuition, we can discuss block by block and not the overall program

For reference:

class stack { public: stack(); ~stack(); bool isFull(); bool isEmpty(); void push(char); void pop(); char peek(); int count; private: char * arr; int top; }; class queue { public: queue(); ~queue(); bool isFull(); bool isEmpty(); void enQ(char); char deQ(); char slash(); char back(); char peek(); int count; private: char * arr; int front; int rear; }; // List of all function logic that you need: void parseItem(stack * map[], int col_selected, int cols, queue * bag, queue * loot, char item); void bombEffect(stack * map[], int col_selected, int cols); void pigEffect(queue * loot); void cloverEffect(stack * map[], int col_selected, int cols, queue * loot); void flashEffect(stack * map[], int cols); void magnetEffect(stack * map[], int cols, queue * loot, queue * bag); //This one you should build to debug void printBag(queue * Bag); void printLoot(queue * Loot); void printFinal(stack * map[], int cols); void printBag(queue * Bag) { cout << "FINAL BAG:\n"; int unload = Bag->count; for(int i = 0; i < unload; i++) { if(!Bag->isEmpty()) { cout << Bag->deQ(); if(i!= (unload - 1)) cout << " "; } } cout << endl; } void printLoot(queue * Loot) { cout << "FINAL BAG:\n"; int unload = Loot->count; for(int i = 0; i < unload; i++) { if(!Loot->isEmpty()) { cout << Loot->deQ(); cout << " "; } } cout << endl; } /*========= STACK IMPLEMENTATION =========*/ stack::stack() { arr = new char[MAX_SIZE]; top = -1; count = 0; //---Stack Debugger // stack holder; // holder.push('a'); // holder.push('b'); // holder.pop(); // holder.push('c'); // cout << "Top: " << holder.peek() << endl; // cout << "Count: " << holder.count << endl; // holder.pop(); // holder.pop(); // holder.peek(); } stack::~stack() { delete arr; arr = nullptr; } bool stack::isFull() { return(top == (MAX_SIZE - 1)); } bool stack::isEmpty() { return(top == -1); } void stack::push(char item) { if(!isFull()) { arr[++top] = item; // cout << "[LOG] " << "Pushed new item: " << arr[top] << endl; count++; } else { //cout << "[LOG] " << "Stack is full" << endl; } } void stack::pop() { if(!isEmpty()) { char topElement = arr[top--]; // cout << "[LOG] " << "Poped item: " << topElement << endl; count--; } else { //cout << "[LOG] " << "pop Stack is empty" << endl; } } char stack::peek() { if(!isEmpty()) { char topElement = arr[top]; // cout << "[LOG] " << "Top Item is " << topElement << endl; return topElement; } else { //cout << "[LOG] " << "peek Stack is empty" << endl; return '$'; } } /*========= QUEUE IMPLEMENTATION =========*/ queue::queue() { arr = new char[MAX_SIZE]; front = -1; rear = -1; count = 0; //---Queue Debugger // queue line; // line.enQ('a'); // line.enQ('b'); // cout << "Count: " << line.count << endl; // char take = line.deQ(); // cout << "Grabbed: " << take << endl; // cout << "Count: " << line.count << endl; // line.peek(); // take = line.deQ(); // take = line.deQ(); } queue::~queue() { delete arr; arr = nullptr; } bool queue::isFull() { return(front == 0 && rear == (MAX_SIZE - 1)); } bool queue::isEmpty() { return(count == 0); } void queue::enQ(char item) { if(!isFull()) { if(front == -1) front++; arr[++rear] = item; // cout << "[LOG] " << "Appended new item: " << arr[rear] << endl; count++; } else { //cout << "[LOG] " << "Queue is full" << endl; } } char queue::deQ() { if(!isEmpty()) { char frontElement = arr[front++]; // cout << "[LOG] " << "Grab Queue: " << frontElement << endl; count--; return frontElement; } else { //cout << "[LOG] " << "Queue is empty" << endl; return '$'; } } char queue::slash() { if(!isEmpty()) { char rearElement = arr[rear--]; count--; // cout << "[LOG] " << "Sneak Peek: " << frontElement << endl; return rearElement; } else { //cout << "[LOG] " << "Queue is empty" << endl; return '$'; } } char queue::back() { if(!isEmpty()) { char rearElement = arr[rear]; // cout << "[LOG] " << "Sneak Peek: " << frontElement << endl; return rearElement; } else { //cout << "[LOG] " << "Queue is empty" << endl; return '$'; } } char queue::peek() { if(!isEmpty()) { char frontElement = arr[front]; // cout << "[LOG] " << "Sneak Peek: " << frontElement << endl; return frontElement; } else { //cout << "[LOG] " << "Queue is empty" << endl; return '$'; } }