Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <math.h>
- #define PLAYER_WEIGHT_MAX 20
- #define PLAYER_WEIGHT_FLUX 12
- #define WORLD_GRID_SIZE 8191
- #define WORLD_OFFSET 4096
- #define FREQUENCY_DEPTH 20
- typedef struct Neuron {
- Dendrite * root;
- long frequency;
- } neuronArrayPtr[WORLD_GRID_SIZE ^ 2];
- typedef struct Dendrite{
- Dendrite * left;
- Dendrite * right;
- long frequency;
- Frequency * root;
- };
- typedef struct Frequency {
- Frequency * left;
- Frequency * right;
- long frequency;
- PlayerWeight * proot;
- Synapse * root;
- };
- typedef struct Synapse {
- Synapse * left;
- Synapse * right;
- PlayerWeight * root;
- Neuron * neuron;
- };
- typedef struct PlayerWeight {
- PlayerWeight * left;
- PlayerWeight * right;
- long playerId;
- int count;
- };
- typedef struct PlayerPath {
- PlayerPath * prev;
- Neuron * neuron;
- };
- typedef struct FrequencyOffset {
- FrequencyOffset * left;
- FrequencyOffset * right;
- long offset;
- Frequency * frequency;
- };
- PlayerPath * createPath(Player * p) {
- return updatePath(p,NULL);
- }
- PlayerPath * updatePath(Player * p, PlayerPath * prev) {
- PlayerPath * ret;
- ret = malloc(sizeof(PlayerPath));
- if (prev == NULL)
- ret->prev = ret;
- else
- ret->prev = prev;
- ret->neuron = getNeuron(p->x,p->y);
- updateNeuron(p,ret,pathFrequency(prev));
- return ret;
- }
- void updateNeuron(Player * p, PlayerPath * path, long pathFreq) {
- //getDendrite(path->neuron,path->prev->neuron->frequency,true),pathFreq));
- getSynapse(getFrequency(getDendrite(path->prev->neuron,path->prev->prev->neuron->frequency),pathFreq,p,true),p);
- }
- PlayerWeight * getPlayerWeight(PlayerWeight * pw, Player * p) {
- //TODO: Replace steamID variable with real
- if (pw->playerId > p->steamID) {
- if (pw->left == NULL) {
- pw->left = malloc(sizeof(PlayerWeight));
- pw->left->playerId = p->steamID;
- pw->left->count = 1;
- pw->left->weight = 1;
- return pw->left;
- }
- return getPlayerWeight(pw->left, p);
- }
- if (pw->playerId < p->steamID) {
- if (pw->right == NULL) {
- pw->right = malloc(sizeof(PlayerWeight));
- pw->right->playerId = p->steamID;
- pw->right->count = 1;
- pw->right->weight = 1;
- return pw->right;
- }
- return getPlayerWeight(pw->right, p);
- }
- pw->count++;
- return pw;
- }
- FrequencyOffset * addFrequencyOffset(FrequencyOffset * ret, Frequency * freq, long offset) {
- if (ret->offset > offset) {
- if (ret->left == NULL) {
- ret->left = malloc(sizeof(FrequencyOffset));
- ret->left->frequency = freq;
- ret->left->offset = offset;
- return ret->left;
- }
- else {
- return addFrequencyOffset(ret->left,freq,offset);
- }
- }
- if (ret->offset < offset) {
- if (ret->right == NULL) {
- ret->right = malloc(sizeof(FrequencyOffset));
- ret->right->frequency = freq;
- ret->right->offset = offset;
- return ret->right;
- }
- else {
- return addFrequencyOffset(ret->right,freq,offset);
- }
- }
- return ret;
- }
- FrequencyOffset * fillFrequencyOffset(FrequencyOffset * ret, Frequency * freq, Player * p, long parentFreq,bool sniff) {
- if (sniff) {
- if (freq->frequency > parentFreq) {
- if (freq->left == NULL) {
- freq->left = malloc(sizeof(Frequency));
- freq->left->frequency = parentFreq;
- freq->left->proot = malloc(sizeof(PlayerWeight));
- freq->left->proot->count = 1;
- freq->left->proot->playerId = p->steamId;
- }
- else {
- fillFrequencyOffset(ret,freq->left,p,parentFreq,true);
- if (freq->right != NULL)
- fillFrequencyOffset(freq->right,p,parentFreq,false);
- }
- return ret;
- }
- if (freq->frequency < parentFreq) {
- if (freq->right == NULL) {
- freq->right = malloc(sizeof(Frequency));
- freq->right->frequency = parentFreq;
- freq->right->proot = malloc(sizeof(PlayerWeight));
- freq->right->proot->count = 1;
- freq->right->proot->playerId = p->steamId;
- }
- else {
- fillFrequencyOffset(ret,freq->right,p,parentFreq,true);
- if (freq->left != NULL)
- fillFrequencyOffset(freq->left,p,parentFreq,false);
- }
- return ret;
- }
- }
- if (freq->left != NULL)
- fillFrequencyOffset(ret,freq->left,p,parentFreq,false);
- if (freq->right != NULL)
- fillFrequencyOffset(ret,freq->right,p,parentFreq,false);
- addFrequencyOffset(ret,freq,ceil(abs(parentFreq - freq->frequency) * frequencyWeight(freq,getPlayerWeight(freq->proot,p))))
- return ret;
- }
- FrequencyOffset * createFrequencyOffset(Frequency * freq, Player * p, long parentFreq) {
- FrequencyOffset * ret = malloc(sizeof(FrequencyOffset));
- ret->frequency = freq;
- ret->offset = ceil(abs(parentFreq - freq->frequency) * frequencyWeight(freq,getPlayerWeight(freq->proot,p)))
- return fillFrequencyOffset(ret,freq,p,parentFreq,true);
- }
- FrequencyOffset * getFrequency(FrequencyOffset * freq,Player * p) {
- if (freq->offset > 0) {
- if (freq->left == NULL) {
- return freq;
- }
- else {
- return getFrequency(freq->left,p);
- }
- }
- if (freq->offset < 0) {
- if (freq->right == NULL) {
- return freq;
- }
- else {
- return getFrequency(freq->right,p);
- }
- }
- return freq;
- }
- Frequency * getFrequency(Dendrite * dend,long parentFreq,Player * p,bool retNew) {
- Frequency * freq = dend->root;
- if (freq == NULL) {
- freq = malloc(sizeof(Frequency));
- freq->frequency = parentFreq;
- }
- Frequency * ret = getFrequency(createFrequencyOffset(freq,p,parentFreq),p)->frequency;
- return ret;
- }
- Frequency * getFrequency(Dendrite * dend,long p,Player * pl) {
- return getFrequency(dend,p,pl,false);
- }
- /*************************************************/
- Dendrite * getDendrite(Dendrite * dend,long parentFreq,bool retNew) {
- if (dend->frequency == parentFreq)
- return dend;
- if (dend->frequency > parentFreq)
- if (dend->left == NULL) {
- dend->left = malloc(sizeof(Dendrite));
- dend->left->frequency = parentFreq;
- return retNew ? dend->left : dend;
- }
- else
- return getDendrite(dend->left,parentFreq);
- if (dend->frequency < parentFreq)
- if (dend->right == NULL) {
- dend->right = malloc(sizeof(Dendrite));
- dend->right->frequency = parentFreq;
- return retNew ? dend->right : dend;
- }
- else
- return getDendrite(dend->right,parentFreq);
- }
- Dendrite * getDendrite(Neuron * neuron,long parentFreq,bool retNew) {
- Dendrite * dend = neuron->root;
- if (dend == NULL) {
- dend = malloc(sizeof(Dendrite));
- dend->frequency = parentFreq;
- neuron->root = dend;
- }
- return getDendrite(dend,parentFreq,retNew);
- }
- Dendrite * getDendrite(Neuron * neuron,long parentFreq) {
- return getDendrite(neuron,parentFreq,false);
- }
- long pathFrequency(PlayerPath * path) {
- PlayerPath * iter = path;
- long frequency = 0;
- for (int i = 0; i < FREQUENCY_DEPTH; i++) {
- frequency += iter->neuron->frequency;
- iter = iter->prev;
- }
- return frequency;
- }
- float frequencyWeight(Frequency * syn, PlayerWeight * weight) {
- if (weight == NULL)
- return 1f;
- return 1f - ((PlAYER_WEIGHT_MAX - (PLAYER_WEIGHT_FLUX / (pow(4f,weight->count) / pow(3.6f,weight->count)))) / 100);
- }
- float synapseWeight(Synapse * syn, PlayerWeight * weight) {
- if (weight == NULL)
- return 1f;
- return 1f - ((PlAYER_WEIGHT_MAX - (PLAYER_WEIGHT_FLUX / (pow(4f,weight->count) / pow(3.6f,weight->count)))) / 100);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement