Sign in to follow this  

table for players to look up respect

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 this post

Link to post
Share on other sites
I think that easiest way is to do it with arrays;

#define MAX_PLAYERS 10

class player
float respect[MAX_PLAYERS];
void SetRespectForPlayer(int pl, float value) { respect[pl] = value;}


player myplayer[MAX_PLAYERS];


Share this post

Link to post
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 rating
respect_matrix["Prog101"]["Oluseyi"] = 1.0;

// respect ratings are asymmetric
respect_matrix["Oluseyi"]["Prog101"] = 1.1;

// query a respect rating without accidentally inserting
outer_iter o = respect_matrix.find("Oluseyi");
if(o == respect_matrix.end())
// Oluseyi has no respect for anyone! :p
inner_iter i = o->find("Prog101");
if(i == o->end())
// Oluseyi is oblivious of Prog101

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this