0

I'm making a Monopoly game for a school project, written in C++. The first thing I'm working on is implementing the board. It's intuitive to me that each tile will be an object holding information and functions and whatnot, but I cannot decide whether these should be contained in a linked list or array.

It made sense for a linked list because i could simply have the last tile point to the first, but it also seems more efficient to use an array since I can instantly access Tile[5] for example.

Can anybody clarify as to which would be better for this purpose?

Hayden Holligan
  • 1,822
  • 2
  • 19
  • 26
  • An array list. Best of both worlds – Marshall Tigerus Nov 17 '14 at 19:45
  • Why not an `std::array`? It's not like the board is going to change size. – John Dibling Nov 17 '14 at 19:45
  • In this case an array is best choice. This question here answers how to select array vs linked list http://stackoverflow.com/questions/393556/when-to-use-a-linked-list-over-an-array-array-list – Malcolm McCaffery Nov 17 '14 at 19:47
  • @JohnDibling what are the advantages of using this over a normal array? I would prefer to stick to what I know to keep it simple but if it will actually make this easier I can consider it. – Hayden Holligan Nov 17 '14 at 19:48
  • Use an elementAt(n) method as part of your linked list. – Amesh Nov 17 '14 at 19:49
  • @HaydenHolligan: There is nothing to gain by using a C-style array versus usig `std::array`. The latter is a proper C++11 container, and directly supports all that entails. With `std::array`, there is really no reason to use C-style arrays at all. – John Dibling Nov 17 '14 at 19:57

1 Answers1

7
  • It's a fixed size. That negates about 90% of the advantages of a linked list.
  • You will NEVER be accessing it sequentially (unless, instead of dice, everybody just moves one square each time), but always randomly. That's about 90% of the advantage of an array.
  • The one reason you cite for using a linked-list is trivially handled differently. (new_position = (current_position + roll) % 40;)

Therefore: You unquestionably want to use an array.

James Curran
  • 101,701
  • 37
  • 181
  • 258