Solved

Creating a sports simulation

Posted on 1998-10-07
5
463 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
ID: 1174635
>>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
ID: 1174636
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
ID: 1174637
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
ID: 1174638
That should get you started.  Think about it and ask if you have questions.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1174639
No questions?  If so, you can ask later.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

773 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