Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Programming Issue. Linked Lists, Vectors, or what else???  (Read 2172 times)

Alexhans

  • Bay Watcher
  • This is toodamn shortto write something meaningful
    • View Profile
    • Osteopatia y Neurotonia
Programming Issue. Linked Lists, Vectors, or what else???
« on: December 30, 2008, 07:47:41 am »

  Hi... I'm toying with a roguelike game that I'm making (more of a simulation exercise for entertaiment purposes ;) nothing serious) and stopped cold when trying to make an inventory for the the players in the world... Should I use an linked list? vector? static array (Urgh!).
  I'll try to be explicit about what I need...
   Suppose I have a world with 200 people (constant, 199 AI and 1 player) and each of those persons will have an inventory with stuff.  They should be able to "get or "drop" things from their inventory. 
   Suppose this  is the struct of the people:

struct sPerson {  //never mind public or private... I simplified this...
   char name[MAX_NAME_LENGHT];
   char ASCII[1]; //the ASCII Image
   int hp;   // healthpoints... whatever
   int xpos;
   int ypos;
}Person[MAX_PEOPLE], *PtrPerson;

what would you think would be the best way to accomplish that? (thinking about memory, good clean coding, and all that).  Making a linked list struct and placing it inside the sPerson struct? or what?

AS i want to make a good pathfinding algorithm later and will probably use the A*http://en.wikipedia.org/wiki/A*_search_algorithm I thought I should be sticking with linked lists... but i'm not sure...

Thanks for your help. 

PD: Oh... Im using Visual C++ (6 or 2005)
« Last Edit: December 30, 2008, 07:50:08 am by Alexhans »
Logged
“Eight years was awesome and I was famous and I was powerful" - George W. Bush.

DJ

  • Bay Watcher
    • View Profile
Re: Programming Issue. Linked Lists, Vectors, or what else???
« Reply #1 on: December 30, 2008, 11:04:43 am »

Linked list fo sho. With inventories you'll want to remove items from the middle of the list or reorder them or stuff, and linked lists are simply better than vectors when it comes to this.

Also, I don't see how inventory has anything to do with pathfinding, so it doesn't matter what you go with.
Logged
Urist, President has immigrated to your fortress!
Urist, President mandates the Dwarven Bill of Rights.

Cue magma.
Ah, the Magma Carta...

Alexhans

  • Bay Watcher
  • This is toodamn shortto write something meaningful
    • View Profile
    • Osteopatia y Neurotonia
Re: Programming Issue. Linked Lists, Vectors, or what else???
« Reply #2 on: December 30, 2008, 04:13:47 pm »

Also, I don't see how inventory has anything to do with pathfinding, so it doesn't matter what you go with.

Inventory is not related to pathfinding... ;) is just that the A* algorithm for pathfinding that i learned (theory only) uses linked lists, wich im not so used to yet... just starting to experiment with.

nice tutorial for A* http://www.policyalmanac.org/games/aStarTutorial.htm

anyway... I've been hearing that STL Links,vectors,queues etc are great... should I use those links as opposed to making my own? (speed differences?)
« Last Edit: December 30, 2008, 04:31:17 pm by Alexhans »
Logged
“Eight years was awesome and I was famous and I was powerful" - George W. Bush.

Gantolandon

  • Bay Watcher
  • He has a fertile imagination.
    • View Profile
Re: Programming Issue. Linked Lists, Vectors, or what else???
« Reply #3 on: December 30, 2008, 06:01:41 pm »

Quote
what would you think would be the best way to accomplish that? (thinking about memory, good clean coding, and all that).  Making a linked list struct and placing it inside the sPerson struct? or what?

First, if you are using C++, why would you want to use structs instead of objects?

I would use a set. It's a part of STL. I don't think you should use a linked list, because order of items in inventory is irrelevant.

I would also consider making inventory a separate object, thus moving methods like get() and drop() from the person. There will be propably a lot of them.

Quote
anyway... I've been hearing that STL Links,vectors,queues etc are great... should I use those links as opposed to making my own? (speed differences?)

You shouldn't ever do by yourself anything that is in STL unless for the purpose of learning things. Especially not on this stage.
« Last Edit: December 30, 2008, 06:04:25 pm by Gantolandon »
Logged

Gigalith

  • Bay Watcher
    • View Profile
    • O and H Books
Re: Programming Issue. Linked Lists, Vectors, or what else???
« Reply #4 on: December 31, 2008, 01:09:18 pm »

Quote
anyway... I've been hearing that STL Links,vectors,queues etc are great... should I use those links as opposed to making my own? (speed differences?)

You shouldn't ever do by yourself anything that is in STL unless for the purpose of learning things. Especially not on this stage.
This. Seriously. When you're doing pathfinding, don't try to make your own binary heap or anything, just plug in priority_queue and it will work straight out of the box. 
Logged
Check out my books at O and H Books