• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Two functions for the ELU Rating system
#1
Code for the ELU Rating system, explained here: http://mcompute.co.uk/showthread.php?tid...63#pid6363
Code requires math.h to be imported for the pow() and round() functions.

Updated for a who's won picker. Also for those wondering (Pack3t) I've done some thinking, and there is a technical limit. When it gets to a point where the percentage chance of the other is > 0.5% (Due to the round function, so really 0%) then nothing changes.
This program also allows for you to enter a long string, E.G I could enter 111 to signify Pack3t won 3 times or 2222 to signify Sharn won 4 times.
[code=c]
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

#define maxcandidates 20
#define maxlength 15
#define CONFIGURATION "configuration.txt"

int elupercentage( int Ra, int Rb );
void eluNewBR( int *winner, int *loser, int winpercent, int losepercent );
int scanfile();
void savefile(int savelimit);

int baserating[maxcandidates];
char candidate[maxcandidates][maxlength];

main(){
int percent1, percent2;
int limit = scanfile();
int x, y;
char c;
int badchar = 0;

do{
if(!badchar){
x = rand() % limit;
y = rand() % limit;
while ( x == y )
y = rand() % limit;
printf("\n > For %s to win enter 1\n", candidate[x]);
printf(" > For %s to win enter 2\n", candidate[y]);
printf(" > Hit 3 to save and exit\n\n");

percent1 = elupercentage( baserating[x], baserating[y] );
percent2 = elupercentage( baserating[y], baserating[x] );
printf("Base Rating of %s: %d\n", candidate[x], baserating[x]);
printf("Base Rating of %s: %d\n", candidate[y], baserating[y]);
printf("Chance of %s winning: %d%% \n", candidate[x], percent1);
printf("Chance of %s winning: %d%% \n", candidate[y], percent2);
}

badchar = 0;
c = getchar();
if (c == '1')
eluNewBR( &baserating[x], &baserating[y], percent1, percent2 );
else if (c == '2')
eluNewBR( &baserating[y], &baserating[x], percent1, percent2 );
else if (c == '3')
savefile(limit-1);
else
badchar = 1;
}while(1);

}

int elupercentage( int Ra, int Rb ){
return round(100 / ( 1+pow(10, (((float)Rb - (float) Ra) / 400))));
}

void eluNewBR( int *winner, int *loser, int winpercent, int losepercent ){
*winner += 100 - winpercent;
*loser -= losepercent;
}

int scanfile(){
FILE *config = fopen(CONFIGURATION, "r");
int z, y, i, x = 0;
char buffer[5]; //Allows for BR up to 99999
int username = 1;
if (config == NULL){
printf("Error!\n");
exit(1);
}

for(i = 0;; i++){
z = fgetc(config);
if (z == '\n' || z == EOF){
if (username == 1)
username = 0;
else if (username == 0){
baserating[x] = atoi(buffer);
x++;
for( y = 0; y <= 5; y++)
buffer[y] = 0;
username = 1;
}
i = -1;
if ( z == EOF )
break;
} else {
if (username == 1){
candidate[x][i] = z;
} else if(username == 0){
buffer[i] = z;
}
}

}
fclose(config);
return x;
}

void savefile(int savelimit){
FILE *config = fopen(CONFIGURATION, "w");
int length, place, position = 0;
char buffer[5]; //Matching previous buffer.


for ( place = 0; place <= savelimit; position = 0, place++){
while ( candidate[place][position] != '\0' ){
fputc( candidate[place][position], config );
position++;
}
fputc('\n', config);


length = sprintf ( buffer, "%d", baserating[place] );
for ( position = 0; position <= length; position++ )
fputc(buffer[position], config);

fputc('\n', config);

}
fclose(config);
exit(1);
} [/code]
[Image: nomnomnom.jpg]
;7$=v?%v%#5>v7v8994
The decrypt code is V, I could not make it any simpler!
  Reply
#2
Updated the code so it doesn't produce warnings when compiling. I did this by changing \% for %% in the printf statements.
[Image: nomnomnom.jpg]
;7$=v?%v%#5>v7v8994
The decrypt code is V, I could not make it any simpler!
  Reply
#3
UPDATE: Changed my example of how the code can be used so that it allows you to pick a winner, see first post.
[Image: nomnomnom.jpg]
;7$=v?%v%#5>v7v8994
The decrypt code is V, I could not make it any simpler!
  Reply
#4
UPDATE: Added a configuration.txt option, It MUST be formatted like so:
Username
Baserating
Username
Baserating

Etc. etc.
[Image: nomnomnom.jpg]
;7$=v?%v%#5>v7v8994
The decrypt code is V, I could not make it any simpler!
  Reply
#5
Mark
10000000000000
  Reply
#6
I haven't got my same file with me, But if I remember correctly it's something like:
Pack3t
700
Sharn
500
Latch
600
Mark
250
Drumm
100
[Image: nomnomnom.jpg]
;7$=v?%v%#5>v7v8994
The decrypt code is V, I could not make it any simpler!
  Reply
#7
Wait.. Does that mean Sharn is more likely to get rated over myself and you?
  Reply
#8
It would appear that is the case.....but yet not over me.
As a side note it would seem someone quietly took a lot of suggestions from an old fart, good times.
[Image: icpn5k.jpg]
Trolls are the last thing you need to be concerned with.

VCD Wrote:// Forever more, count and reply, bitch.
  Reply
#9
You were my guidance on this Pack3t :tongue. When you ain't 100% confident in what you're doing, it's good to have someone that can say "Yeah, that will work"
[Image: nomnomnom.jpg]
;7$=v?%v%#5>v7v8994
The decrypt code is V, I could not make it any simpler!
  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [C++] Inline Functions Tutorial Clones 1 9,472 11-09-2012, 11:30 AM
Last Post: annaharris
  Drumms Useful Functions! Drumm 4 11,617 08-10-2011, 10:36 PM
Last Post: Mark

Forum Jump: