Like Tree2Likes

Draw a grid using the following characters?

This is a discussion on Draw a grid using the following characters? within the C Programming forums, part of the General Programming Boards category; If you're making a bejeweled type game, you're going to need a function to check for sequences during the course ...

  1. #31
    Registered User
    Join Date
    Jun 2011
    Posts
    2,706
    If you're making a bejeweled type game, you're going to need a function to check for sequences during the course of game play. You could use this same function during initialization to check for sequences after randomly determining the starting values. If any are found, change those spots to new characters. Repeat until there are no duplicates side by side.

  2. #32
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    This is an example of what I was suggesting - the setup function:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    #define R 5
    #define C 5
    
    void setup(char grid[R][C]);
    void printIt(char grid[R][C]);
    
    int main(void) {
    
       int r, c;
       char grid[R][C];
    
       srand(time(NULL));
       for(r=0;r<R;r++) {
          for(c=0;c<C;c++) {
             grid[r][c]=rand() % ('F'-'A') + 'A';
          }
          printf("\n");
       }
       printIt(grid); 
       
       setup(grid);
       printf("\n\n");
       printIt(grid); 
    
       return 0;
    }
    void setup(char grid[R][C]) {
       int row,col, change=0; 
       
       for(row=0;row<R;row++) {
          for(col=0;col<C-1;col++) {
             while(grid[row][col]==grid[row][col+1]) { 
                grid[row][(col+1)]++;
                change++;
                if(grid[row][col+1]>'E') {
                   grid[row][col+1]='A';
                }
             }
          } 
       }   
       printf("\n\nchange: %d\n",change);
    }
    void printIt(char grid[R][C]) {
       int r,c;
       for(r=0;r<R;r++) {
          for(c=0;c<C;c++)
             printf("%c ",grid[r][c]);
          putchar('\n');
       }
    }

  3. #33
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Correction, the above is NOT what I was suggesting, but it was what seemed best, after I got to working on the problem a bit more. It does closely model what Matticus suggested above.

  4. #34
    Registered User
    Join Date
    Aug 2013
    Posts
    16
    Hi again! Um, since it's a Bejeweled like game, do you have any suggestions on how to check for matches of 3, for, or 5 in a row?

  5. #35
    Registered User HelpfulPerson's Avatar
    Join Date
    Jun 2013
    Location
    Over the rainbow
    Posts
    288
    Quote Originally Posted by programmingnewb View Post
    Hi again! Um, since it's a Bejeweled like game, do you have any suggestions on how to check for matches of 3, for, or 5 in a row?
    Try making it on your own first, and if it's super inefficient, come back here.
    "Some people think they can outsmart me, maybe. Maybe. I've yet to meet one that can outsmart bullet" - Meet the Heavy, Team Fortress 2

  6. #36
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,762
    There is a thing called greedy matching. Take the first thing you see as a possible match and visit the nearest neighbor in every direction for number 2. If you find it, you have to keep going in that direction to "collect" the match. So for example you find a yellow block going down, you keep going down looking for yellow; the idea is to match as many yellow things as you can in a line. It shouldn't be too hard to cover the entire board.

Page 3 of 3 FirstFirst 123
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with a grid
    By karimoftos in forum C Programming
    Replies: 6
    Last Post: 04-19-2011, 12:32 PM
  2. Grid
    By mortalc in forum C Programming
    Replies: 7
    Last Post: 03-12-2011, 06:23 AM
  3. Plz, teach me how to draw a grid!
    By Messiah in forum C++ Programming
    Replies: 5
    Last Post: 06-30-2010, 12:16 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21