March 31st, 2013, 02:25 PM
2D array elimination
I'm trying to working on a part of program that involves an 2D array with randomly arrange 4 letter (b, r, g, y - symbolizing color).
Kind of like this. The size can vary.
The program will prompt the user to enter coordinate thereby picking a letter. For example b, then all the bs that's connected to each other would be eliminated. Then columns will collapse, and shift over to the left.
I'm still pretty new to C so any help will be appreciated.
I'll try to post up pictures but I can't right now...
March 31st, 2013, 02:36 PM
Say you start with something like this,
and the user enters the coordinates for the very top right b, then you get something like this (elimination of all the connected bs only vertically and horizontally. NOT diagonally connected)
then the columns will collapse so there's no letter that has no letter underneath it, as if by virtual gravity
then the columns shift over to that left so that columns with no elements are eliminated
And the user continues to enter coordinates until no more letters can be eliminated.
April 1st, 2013, 12:31 AM
So what's your question?
Because it looks like a homework dump and expectation of complete code on a plate in return, and that just isn't going to happen.
You showed three distinct steps, so how about 3 functions.
#define SIZE 10
// eliminate the connected letters starting at x,y
void eliminate ( char grid[SIZE][SIZE], int x, int y );
// do the gravity bit
void collapse ( char grid[SIZE][SIZE] );
// do the shift bit
void shift ( char grid[SIZE][SIZE] );
// For good measure, and an aid to debugging
// just print the grid
void print ( char grid[SIZE][SIZE] );
April 1st, 2013, 02:39 AM
I don't expect a full code. That would be way too generous. Just any hints or tips.
Originally Posted by salem
A short pseudo code would be awesome.
I'm wondering whether the first function would be necessary though. I don't necessarily need a turn the characters into a space. So long as the 1st grid ends up looking like the bottom grid, it's all good.
April 1st, 2013, 02:49 AM
You need to post some actual code (or actual pseudocode), so we can see exactly what you're capable of, and thus tune the advice and help accordingly.
Simply spoon-feeding anything beforehand suffers from the goldilocks problem (I knew that already :rolleyes: , just what I needed :) , I'm still confused :( )
But I'm guessing you'll need this to complete step 1.