Thread: create a pattern from center to edge in a 2d array

  1. #16
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by ryuti View Post
    Now can you please guide me. You said before there are 4 possible starting cells. I would like to point to all of them and choose the one that does no contain a blank space and after how do i move to the next cell to sort out the maze?
    Simply keep track of where you are, and move a direction by increasing or decreasing the row or column (x or y) coordinate. Since you have an even number of rows and columns, you cannot have an exact middle, so cut that in half, and check the four for whatever you need.


    Quzah.
    Hope is the first step on the road to disappointment.

  2. #17
    Registered User
    Join Date
    May 2011
    Posts
    10
    my matrix can go horizontally or vertically. should i choose cases: Ex: case o: y--; case 1: x++... ? for movement?
    what i do not understand is from starting point ex: matrix[5][5]...how to adjust the coordinates? another function?

  3. #18
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    size_t here_x, here_y;
    
    /* set the starting point randomly between 5 and 6 */
    here_x = 5 + (rand() % 2);
    here_y = 5 + (rand() % 2);
    
    /* move north */
    here_x--;
    cellvalue = maze[ here_x ][ here_y ];
    
    /* move east */
    here_y++;
    cellvalue = maze[ here_x ][ here_y ];
    
    /* move south */
    here_x++;
    cellvalue = maze[ here_x ][ here_y ];
    
    /* move west */
    here_y--;
    cellvalue = maze[ here_x ][ here_y ];

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #19
    Registered User
    Join Date
    May 2011
    Posts
    10
    Quote Originally Posted by quzah View Post
    Code:
    size_t here_x, here_y;
    
    /* set the starting point randomly between 5 and 6 */
    here_x = 5 + (rand() % 2);
    here_y = 5 + (rand() % 2);
    
    /* move north */
    here_x--;
    cellvalue = maze[ here_x ][ here_y ];
    
    /* move east */
    here_y++;
    cellvalue = maze[ here_x ][ here_y ];
    
    /* move south */
    here_x++;
    cellvalue = maze[ here_x ][ here_y ];
    
    /* move west */
    here_y--;
    cellvalue = maze[ here_x ][ here_y ];

    Quzah.
    Thank you both for your reply's. I will try to sort out the code. Sorry for being so pushy, but my assignment is due on Friday and need to work too. I do not have to much time left. Thanks again. I will post the solution of the whole maze.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. create and populate create bidimensional array
    By darkducke in forum C Programming
    Replies: 0
    Last Post: 12-03-2010, 07:06 AM
  2. Wish to create a pattern of numbers using loops
    By bharat_kaushik in forum C Programming
    Replies: 12
    Last Post: 09-04-2009, 11:08 AM
  3. Edge Detect
    By 250co in forum C Programming
    Replies: 0
    Last Post: 05-22-2006, 08:51 PM
  4. storing a pattern of characters into a 2D array
    By haroonie in forum C Programming
    Replies: 2
    Last Post: 04-20-2005, 05:19 AM