Solved

Creating a sports simulation

Posted on 1998-10-07
5
459 Views
Last Modified: 2010-07-27
I am beginning to create a sports(hockey) simulation in C++ using Win95/MSVC++ 4.0  It will be text/statistical related only with no graphics.  I would like to move it to MFC after the main "engine" is completed.

I would like to know an efficient way to hold the roster of players in memory and how they would be linked. My first idea was this:

class Player{
   //list of attributes such as name, jersey number,
       //array of player abilities,(attributes)...etc
   //Here I might put pointers of type Team and Player so
      // that it might point the player to his team and to other
      //players for the purpose of sorting.
};

 I have decided to make it very object oriented so that players and teams could be created and destroyed easly.  All the linking will be done by me without the help of things such as STL(unless you think that would work better).

I have tried to come up with a way to link players to box scores, team and to each other in a way that will make it easy to sort, and create leaderboards.  Also, I would like an easy way to store them to a dat file using as little space as possible (maybe using bitfields)
If you need more information, I will be happy to provide it
              Chris
              nexguy@quik.com
0
Comment
Question by:nexguy
  • 5
5 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 200 total points
Comment Utility
>>All the linking will be done by me without the help of things such as
>>STL(unless you think that would work better)

STL was written to make the programmer's job easier.  If you want to make this easier, use it.  If you want to do the wrok yourself--good experience--then do it yourself.
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
I would store the players in either a linked list or if used STL, a vector.  

However, another posibility to consider is to store them in a hash table.  This would allow you to access them quickly by name, or some other attribute you have them hashed on.  (This decission really needs to be made by looking at what data inside the player class will be used in finding a player.)  If there is one aattribute that will always or almost always be used to find a player, like the name, a hasn table may be a good idea.  (If you need to find them based on lots of things, then you may want to store them in a linked list, but provided several hash tables that reference-but don't store, the players.)
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
The team should be a seperate class.  It should store a a list (linked list or STL vector) of pointers to the players.  Note that it doesn't store the players, but links or pointers to them.  Similarly, the player class will have a pointer to the team object it belongs to.

To make this work, the player is created (constructed) with a NULL team pointer and the team is constructed with a empty player list.  The team will have a member function for adding a player to the team that takes a pointer to the player object to be added.  This function will check that the player is not the member of any team, if it is it probably should remove the player from the team before continueing (or it could report an error, depends on your needs).  Then it would set the player's team pointer to the currrent team (has to be a friend), and it would add the player to te player list.  There would be a remove player member function that set the player's team pointer to NULL and removed the player from the list.  Then to make everything safe, the player's destrcutor will look at its team pointer, if it is not NULL, it is still part of a team (and the team doesn't know the player is being destroyed (danger!) so the player destructor will remove the player from the team.  (this is why the player needs a pointer back to its team).  Similarly, the team's destructor must look through its list of players when it is being destroyed and remve each player in the list from the team.  (because again the players don't know the team is being destroyed.)


0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
That should get you started.  Think about it and ask if you have questions.
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
No questions?  If so, you can ask later.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now