# table for players to look up respect

This topic is 4063 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

i want to create a table so say i have 10 players and they all have respect levels towards each other for example player1 has 0.1 respect for player2 player1 has 0.5 respect for player3 etc i know this will be a big table but what would be the best way to store the data?

##### Share on other sites
I think that easiest way is to do it with arrays;
#define MAX_PLAYERS 10class player{public:float respect[MAX_PLAYERS];void SetRespectForPlayer(int pl, float value) { respect[pl] = value;}};player myplayer[MAX_PLAYERS];myplayer[0].SetRespectForPlayer(3,0.1f);myplayer[0].SetRespectForPlayer(7,0.6f);

##### Share on other sites
Does every player necessarily have respect for every other player? If you have a population of 10,000 players, not all players will know all other players. In such an instance, storing "zeroes" in the majority of cells in your matrix is wasteful. This is why there's a data structure called a sparse matrix.

Using C++:
#include <map>#include <string>using namespace std;typedef map<string, double>::iterator inner_iter;typedef map< string, map<string, double> >::iterator outer_iter;map< string, map<string, double> > respect_matrix;// add a respect ratingrespect_matrix["Prog101"]["Oluseyi"] = 1.0;// respect ratings are asymmetricrespect_matrix["Oluseyi"]["Prog101"] = 1.1;// query a respect rating without accidentally insertingouter_iter o = respect_matrix.find("Oluseyi");if(o == respect_matrix.end()){  // Oluseyi has no respect for anyone! :p}else{  inner_iter i = o->find("Prog101");  if(i == o->end())  {    // Oluseyi is oblivious of Prog101  }}

##### Share on other sites
Quote:
 Oluseyi has no respect for anyone!

Lol!

1. 1
Rutin
26
2. 2
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 21
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631763
• Total Posts
3002186
×