PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
2D Array Question-VBForums
Results 1 to 5 of 5

Thread: 2D Array Question

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    2D Array Question

    I don't understand the array at the bottom of the code. It shows it as a 2d array 2 x 2 yet there are 16 members in it.

    Code:
    #define coMAX 2
    
    #define isqB1 1
    #define isqC1 2
    #define isqD1 3
    #define isqF1 5
    #define isqG1 6
    #define isqB8 113
    #define isqC8 114
    #define isqD8 115
    #define isqF8 117
    #define isqG8 118
    		
    #define cfE1G1	0x0001
    #define cfE1C1	0x0002
    #define cfE8G8	0x0004
    #define cfE8C8	0x0008
    
    typedef struct tagCSTL
    {
      int cf;                    
      int isqRookTo;      
      int isqKnight;      
      int isqKingTo;      
    }
    CSTL;
    
    CSTL const c_argcstl[coMAX][2] =
    {
      cfE1G1,   isqF1,  isqG1,  isqG1,
      cfE1C1,   isqD1,  isqB1,  isqC1,
      cfE8G8,   isqF8,  isqG8,  isqG8,
      cfE8C8,   isqD8,  isqB8,  isqC8,
    };


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  2. #2
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: 2D Array Question

    The array is 2 x 2 however each array element has 4 integer members.

    C Code:
    1. CSTL const c_argcstl[coMAX][2] =
    2. {
    3.   // cf    RookTo  Knight  KingTo
    4.   cfE1G1,  isqF1,  isqG1,  isqG1,
    5.   cfE1C1,  isqD1,  isqB1,  isqC1,
    6.   cfE8G8,  isqF8,  isqG8,  isqG8,
    7.   cfE8C8,  isqD8,  isqB8,  isqC8,
    8. };
    W o t . S i g

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: 2D Array Question

    Not sure I completely understand. Is it like arrays within an array? How do I index isqG8 under the Knight column for example?

    Code:
    CSTL const c_argcstl[coMAX][2] =
    {
     // cf    Rook To  Knight  KingTo
      cfE1G1,  isqF1,  isqG1,  isqG1,
      cfE1C1,  isqD1,  isqB1,  isqC1,
      cfE8G8,  isqF8,  isqG8,  isqG8,
      cfE8C8,  isqD8,  isqB8,  isqC8,
    };
    Last edited by jmsrickland; Nov 22nd, 2014 at 12:07 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  4. #4
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: 2D Array Question

    isqG8 would be indexed c_argcstl[1][0].isqKnight;

    c_argcstl is an array of arrays of CSTL structures. The initializer goes in order [0][0], [0][1], [1][0], [1][1]

    C Code:
    1. CSTL const c_argcstl[coMAX][2] =
    2. { // cf    RookTo  Knight  KingTo
    3.   cfE1G1,  isqF1,  isqG1,  isqG1, //[0][0]
    4.   cfE1C1,  isqD1,  isqB1,  isqC1, //[0][1]
    5.   cfE8G8,  isqF8,  isqG8,  isqG8, //[1][0]
    6.   cfE8C8,  isqD8,  isqB8,  isqC8, //[1][1]
    7. };
    W o t . S i g

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: 2D Array Question

    OK, I understand now. Thanks, Milk


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width