Skip to content

Commit

Permalink
pub init
Browse files Browse the repository at this point in the history
  • Loading branch information
leiizko authored Aug 7, 2017
1 parent bc50463 commit 21e640b
Show file tree
Hide file tree
Showing 15 changed files with 2,168 additions and 1 deletion.
661 changes: 661 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions LICENSE_ORIGINAL
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
Caution
=======

This TrueSkill project is opened under the BSD license but the
TrueSkill(TM) brand is not. Microsoft permits only Xbox Live games or
non-commercial projects to use TrueSkill(TM). If your project is
commercial, you should find another rating system.

References
==========

The core ideas used in this project were described in
"TrueSkill (TM): A Bayesian Skill Rating System" available at
http://research.microsoft.com/apps/pubs/default.aspx?id=67956

Some concepts were based on Jeff Moser's code and documents, available
at http://www.moserware.com/2010/03/computing-your-skill.html

License
=======

All the Python code and the documentation in this TrueSkill project is
Copyright (c) 2012-2015 by Heungsub Lee. All rights reserved.

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* The names of the contributors may not be used to endorse or
promote products derived from this software without specific
prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,46 @@
# cod4_trueskill_plugin
# CoD4X Trueskill plugin
A game rating system made available to use as CoD4X plugin

## Copyright notice
Trueskill algorithm code in this plugin is a port of [sublee/trueskill](https://github.com/sublee/trueskill) from python to C++. For more information consult [LICENSE_ORIGINAL](https://github.com/leiizko/cod4x_trueskill/blob/master/LICENSE_ORIGINAL).

All C++ code is released under AGPL-v3.

## Added functions
```
* TS_Rate( <number of teams>, <team rankings> )
- <number of teams>: Integer, number of teams in game, each player counts as a team in FFA mode
- <team rankings>: String, team placements separated by space. Lower number is better, same numbers is a tie.
Needs to be in a specfic order, the string gets tokenized into an array. Array index+1 represents a team. Example:
TS_Rate( 2, "0 1" ) - Number of teams is 2, Axis is 1, Allies is 2: Axis wins the round, Allies lose.
TS_Rate( 5, "2 0 0 1 3" ) - FFA mode, 5 players. Player 1 is third, players 2 and 3 are tied at first place,
player 4 is second and player 5 is fourth.
Returns array of updated MEAN(mu) and VARIANCE(sigma) values in the same order as added by TS_AddPlayer.
Arr[ i ][ 0 ] = MEAN(mu)
Arr[ i ][ 1 ] = VARIANCE(sigma)
Clears all players added by TS_AddPlayer function.
* TS_Quality( <number of teams> )
- <number of teams>: Integer, number of teams in game, each player counts as a team in FFA mode
Returns a float of game quality ( 0 - 1 ). Multiply by 100 to get percentage of draw chance
Clears all players added by TS_AddPlayer function.
* TS_AddPlayer( <player ID>, <player mu>, <player sigma>, <player team>, [<player weight>] )
- <player ID> - Integer, slot number
- <player mu> - Float, mean rating of a player
- <player sigma> - Float, variance rating of a player
- <player team> - Integer, team of a player, start at 1, in FFA each player is a team, example:
TDM mode, Allies = 1, Axis = 2
FFA mode, player 1 = 1, player 2 = 2, player 3 = 3, etc..
- [<player weight>], OPTIONAL, Float, weight for the player, defaults to 1.
* TS_ClearAllPlayers()
Clears all players added by TS_AddPlayer function.
* TS_UpdateMu( <new mu> )
- <new mu> - Float, updates the default rating values. New players must start at this mean value, sigma is MU/3
* TS_UpdateDraw( <new_draw> )
- <new_draw> - Float, 0 - 1, updates the default draw chance (0.1)
```

47 changes: 47 additions & 0 deletions src/basemath.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <cmath>
#ifndef M_PI
static const double M_PI = 3.14159265358979323846;
#endif

double erfcinv( double y );

// Probability density function
double pdf( double x, double mu, double sigma )
{
return ( 1 / sqrt( 2 * M_PI ) * std::abs( sigma ) * exp( -pow( ( x - mu ) / std::abs( sigma ), 2 ) / 2 ) );
}

// Cumulative distribution function
double cdf( double x, double mu, double sigma )
{
return 0.5 * erfc( -( x - mu ) / ( sigma * sqrt( 2 ) ) );
}

// Inverse cdf
double ppf( double x, double mu, double sigma )
{
return mu - sigma * sqrt( 2 ) * erfcinv( 2 * x );
}

// Inverse ercf ( error complementary function )
double erfcinv( double y )
{
if( y >= 2 )
return -100;
else if( y <= 0 )
return 100;

bool zero_point = y < 1;
if( !zero_point )
y = 2 - y;

double t = sqrt( -2 * log( y / 2 ) );
double x = -0.70711 * ( ( 2.30753 + t * 0.27061 ) / ( 1 + t * ( 0.99229 + t * 0.04481 ) ) - t );
for( int i = 0; i < 2; i++ )
{
double err = erfc( x ) - y;
x += err / ( 1.12837916709551257 * exp( -( pow( x, 2 ) ) ) - x * err );
}

return zero_point ? x : -x;
}
Loading

0 comments on commit 21e640b

Please sign in to comment.