Thread: dynamic board

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    115

    dynamic board

    Hello

    I am trying to make a board for a game.

    The board starts with 1 tile, then the first player can place a tile at the 4 borders of this tile,
    The second player can place a tile at the borders from these 2 tiles and so on.

    What is the best data structure for this board?

    I was thinking of an vector.
    But then I have to move a lot of my tiles around in my vector.

    Does anyone have a better idea?

    Thank you

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I'm assuming this is a 2D board?

    I would ask yourself if the container you are thinking of is the right container for the job. What are its advantages and what are its disadvantages? If you figure this out and write it down before you write any code you will probably save yourself a lot of rework.

    If it were me, and it isn't, I would use an array. You said the board is dynamic. How dynamic? Does it change frame to frame or does it change slowly? You could create a fixed size array on the heap that would handle many changes. Once that board was exhausted you could then allocate another 'chunk' for the board. In this manner you would only be re-creating and re-allocating every so often as the board gets filled up. I would not do this every time the array size changes.

    So to start out you could init a 64x64 array. When that gets filled up you could then allocate a 128x128 array and copy the 64x64 into half of the 128x128. You could also create lists of arrays linked by pointers. This would mean the board consisted of a tree of 64x64 arrays. Each array would have 8 pointers to other arrays.

    Code:
    struct BoardSection
    {
        unsigned int *pArray;
        unsigned int numRows;
        unsigned int numColumns;
        std::vector<BoardSection*> neighbors
    };
    You could also use an array of 8 BoardSection pointers in the struct since you know each 'board section' could have 8 neighbors.

    In the end there are many things you could do but since I do not know enough of the requirements I can't really advise you which way to go.

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    115
    Thank you for your response.

    I think you are right.

    Your idea to use an array is a better way then I have stated.
    I think this is ideal.

    Thank you very much

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Your idea to use an array is a better way then I have stated.
    I think this is ideal.
    Whoa! Hold on there fella. I didn't say my way was right or better I just said it is what I would do given your requirements. Programming is far more than just implementation or getting it to work. You should take a very close look at your requirements before you make any decisions. Why don't you post more about what this app is supposed to do in detail and perhaps others here can chime in and give you further direction.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems in creating a Battleships board
    By TheYeIIowDucK in forum Game Programming
    Replies: 2
    Last Post: 08-27-2010, 05:49 AM
  2. Network Programming Board
    By Eibro in forum A Brief History of Cprogramming.com
    Replies: 32
    Last Post: 07-07-2003, 12:04 PM
  3. Dynamic Toolbars
    By nvoigt in forum Windows Programming
    Replies: 1
    Last Post: 01-11-2002, 10:21 AM
  4. Welcome to the FAQ Board
    By kermi3 in forum FAQ Board
    Replies: 0
    Last Post: 11-01-2001, 10:33 AM