1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2013
Posts
3
Rep Power
0

#### 2D array elimination

Hey
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.
Code:
```gbbybbbb
ryybbrby
yrbrybyr
yrbybybb
ybybbybg
byygybby
bbggrbbg
brrbgbbr```
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...
2. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2013
Posts
3
Rep Power
0
Code:
```
grygbbb
grbbbbb
grbbbby
grrbbgy
grrrbgy
grrrbby```
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)
Code:
```gryg
gr
gr    y
grr  gy
grrr gy
grrr  y```
then the columns will collapse so there's no letter that has no letter underneath it, as if by virtual gravity
Code:
```gr
gr
gry    y
grrg   y
grrr  gy
grrr  gy```
then the columns shift over to that left so that columns with no elements are eliminated
Code:
```gr
gr
gry  y
grrg y
grrrgy
grrrgy```
And the user continues to enter coordinates until no more letters can be eliminated.

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.
Code:
```#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] );```
4. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2013
Posts
3
Rep Power
0
Originally Posted by salem

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.
Code:
```#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] );```
I don't expect a full code. That would be way too generous. Just any hints or tips.
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.
5. 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.