all-up-in-your-elo 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +22 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +42 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/all-up-in-your-elo.gemspec +148 -0
- data/ext/bayeselo/.gitignore +4 -0
- data/ext/bayeselo/CBradleyTerry.cpp +670 -0
- data/ext/bayeselo/CBradleyTerry.h +137 -0
- data/ext/bayeselo/CCDistribution.cpp +135 -0
- data/ext/bayeselo/CCDistribution.h +44 -0
- data/ext/bayeselo/CCDistributionCUI.cpp +104 -0
- data/ext/bayeselo/CCDistributionCUI.h +38 -0
- data/ext/bayeselo/CCondensedResults.cpp +253 -0
- data/ext/bayeselo/CCondensedResults.h +64 -0
- data/ext/bayeselo/CDiscretization.h +40 -0
- data/ext/bayeselo/CDistribution.cpp +123 -0
- data/ext/bayeselo/CDistribution.h +58 -0
- data/ext/bayeselo/CDistributionCollection.cpp +34 -0
- data/ext/bayeselo/CDistributionCollection.h +29 -0
- data/ext/bayeselo/CEloRatingCUI.cpp +1046 -0
- data/ext/bayeselo/CEloRatingCUI.h +67 -0
- data/ext/bayeselo/CIndirectCompare.h +28 -0
- data/ext/bayeselo/CJointBayesian.cpp +111 -0
- data/ext/bayeselo/CJointBayesian.h +38 -0
- data/ext/bayeselo/CLUDecomposition.cpp +154 -0
- data/ext/bayeselo/CLUDecomposition.h +36 -0
- data/ext/bayeselo/CMatrix.cpp +48 -0
- data/ext/bayeselo/CMatrix.h +35 -0
- data/ext/bayeselo/CMatrixIO.cpp +27 -0
- data/ext/bayeselo/CMatrixIO.h +17 -0
- data/ext/bayeselo/CPredictionCUI.cpp +393 -0
- data/ext/bayeselo/CPredictionCUI.h +50 -0
- data/ext/bayeselo/CResultSet.cpp +245 -0
- data/ext/bayeselo/CResultSet.h +50 -0
- data/ext/bayeselo/CResultSetCUI.cpp +355 -0
- data/ext/bayeselo/CResultSetCUI.h +44 -0
- data/ext/bayeselo/CTimeIO.cpp +58 -0
- data/ext/bayeselo/CTimeIO.h +19 -0
- data/ext/bayeselo/CVector.cpp +110 -0
- data/ext/bayeselo/CVector.h +42 -0
- data/ext/bayeselo/EloDataFromFile.cpp +120 -0
- data/ext/bayeselo/EloDataFromFile.h +21 -0
- data/ext/bayeselo/README +8 -0
- data/ext/bayeselo/ReadLineToString.cpp +32 -0
- data/ext/bayeselo/ReadLineToString.h +18 -0
- data/ext/bayeselo/chtime.cpp +56 -0
- data/ext/bayeselo/chtime.h +61 -0
- data/ext/bayeselo/chtimer.h +27 -0
- data/ext/bayeselo/clktimer.cpp +178 -0
- data/ext/bayeselo/clktimer.h +29 -0
- data/ext/bayeselo/consolui.cpp +538 -0
- data/ext/bayeselo/consolui.h +154 -0
- data/ext/bayeselo/const.cpp +79 -0
- data/ext/bayeselo/const.h +42 -0
- data/ext/bayeselo/date.cpp +96 -0
- data/ext/bayeselo/date.h +44 -0
- data/ext/bayeselo/debug.h +58 -0
- data/ext/bayeselo/elomain.cpp +26 -0
- data/ext/bayeselo/eloratings.cpp +76 -0
- data/ext/bayeselo/extconf.rb +6 -0
- data/ext/bayeselo/list.h +367 -0
- data/ext/bayeselo/listi.h +125 -0
- data/ext/bayeselo/move.cpp +249 -0
- data/ext/bayeselo/move.h +139 -0
- data/ext/bayeselo/pgn.h +62 -0
- data/ext/bayeselo/pgnlex.cpp +432 -0
- data/ext/bayeselo/pgnlex.h +105 -0
- data/ext/bayeselo/pgnstr.cpp +126 -0
- data/ext/bayeselo/piece.h +44 -0
- data/ext/bayeselo/player.h +31 -0
- data/ext/bayeselo/position.h +89 -0
- data/ext/bayeselo/random.cpp +114 -0
- data/ext/bayeselo/random.h +63 -0
- data/ext/bayeselo/readstr.cpp +51 -0
- data/ext/bayeselo/readstr.h +19 -0
- data/ext/bayeselo/square.h +61 -0
- data/ext/bayeselo/str.cpp +81 -0
- data/ext/bayeselo/str.h +71 -0
- data/ext/bayeselo/version.cpp +30 -0
- data/ext/bayeselo/version.h +28 -0
- data/ext/bayeselo/version_number.h +1 -0
- data/lib/elo_ratings.rb +9 -0
- data/lib/elo_ratings/c_bayeselo.rb +5 -0
- data/lib/elo_ratings/results.rb +41 -0
- data/test/elo_ratings/test_c_bayeselo.rb +84 -0
- data/test/elo_ratings/test_results.rb +41 -0
- data/test/helper.rb +19 -0
- metadata +233 -0
@@ -0,0 +1,63 @@
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////
|
2
|
+
//
|
3
|
+
// random.h
|
4
|
+
//
|
5
|
+
// CRandom class declaration
|
6
|
+
// (Algorithm from "The Art Of Computer Programming")
|
7
|
+
//
|
8
|
+
// Remi Coulom
|
9
|
+
//
|
10
|
+
// August 1996
|
11
|
+
//
|
12
|
+
////////////////////////////////////////////////////////////////////////////
|
13
|
+
#ifndef RANDOM_H
|
14
|
+
#define RANDOM_H
|
15
|
+
|
16
|
+
#include <iosfwd>
|
17
|
+
|
18
|
+
template<class TYPE>
|
19
|
+
class CRandom // rnd
|
20
|
+
{
|
21
|
+
private: //////////////////////////////////////////////////////////////////
|
22
|
+
int Index1;
|
23
|
+
int Index2;
|
24
|
+
TYPE tulArray[55];
|
25
|
+
|
26
|
+
int fNextGaussian;
|
27
|
+
double NextGaussianValue;
|
28
|
+
|
29
|
+
public: ///////////////////////////////////////////////////////////////////
|
30
|
+
CRandom(TYPE n = 0) : fNextGaussian(0) {Seed(n);}
|
31
|
+
|
32
|
+
//
|
33
|
+
// Seed
|
34
|
+
//
|
35
|
+
void Seed(TYPE ulSeed);
|
36
|
+
|
37
|
+
//
|
38
|
+
// Random number generation
|
39
|
+
//
|
40
|
+
TYPE NewValue()
|
41
|
+
{
|
42
|
+
if (--Index1 < 0)
|
43
|
+
Index1 = 54;
|
44
|
+
|
45
|
+
if (--Index2 < 0)
|
46
|
+
Index2 = 54;
|
47
|
+
|
48
|
+
return tulArray[Index2] += tulArray[Index1];
|
49
|
+
}
|
50
|
+
double NextDouble();
|
51
|
+
double NextGaussian();
|
52
|
+
double NextExponential();
|
53
|
+
|
54
|
+
//
|
55
|
+
// Binary I/O
|
56
|
+
//
|
57
|
+
void BinaryWrite(std::ostream &out) const;
|
58
|
+
void BinaryRead(std::istream &in);
|
59
|
+
};
|
60
|
+
|
61
|
+
#include "random.cpp"
|
62
|
+
|
63
|
+
#endif
|
@@ -0,0 +1,51 @@
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////
|
2
|
+
//
|
3
|
+
// readstr.cpp
|
4
|
+
//
|
5
|
+
// ReadString function
|
6
|
+
//
|
7
|
+
// Remi Coulom
|
8
|
+
//
|
9
|
+
// june, 1998
|
10
|
+
//
|
11
|
+
////////////////////////////////////////////////////////////////////////////
|
12
|
+
#include <iostream>
|
13
|
+
|
14
|
+
using namespace std;
|
15
|
+
|
16
|
+
#include "readstr.h"
|
17
|
+
|
18
|
+
////////////////////////////////////////////////////////////////////////////
|
19
|
+
// Function : Reads a string from a stream
|
20
|
+
// Return : Length of the string read, -1 if EOF
|
21
|
+
////////////////////////////////////////////////////////////////////////////
|
22
|
+
int ReadString(istream &is, char *pszBuffer, int Size)
|
23
|
+
{
|
24
|
+
int i;
|
25
|
+
|
26
|
+
if (is.eof())
|
27
|
+
return -1;
|
28
|
+
|
29
|
+
for(i = 0; i < Size; i++)
|
30
|
+
{
|
31
|
+
int c;
|
32
|
+
c = is.peek();
|
33
|
+
|
34
|
+
if (c == std::char_traits<char>::eof() || is.fail())
|
35
|
+
{
|
36
|
+
pszBuffer[i] = 0;
|
37
|
+
return -1;
|
38
|
+
}
|
39
|
+
|
40
|
+
is.get();
|
41
|
+
if (c == '\n')
|
42
|
+
{
|
43
|
+
pszBuffer[i] = 0;
|
44
|
+
return i;
|
45
|
+
}
|
46
|
+
else
|
47
|
+
pszBuffer[i] = c;
|
48
|
+
}
|
49
|
+
|
50
|
+
return i;
|
51
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////
|
2
|
+
//
|
3
|
+
// readstr.h
|
4
|
+
//
|
5
|
+
// ReadString function
|
6
|
+
//
|
7
|
+
// Remi Coulom
|
8
|
+
//
|
9
|
+
// june, 1998
|
10
|
+
//
|
11
|
+
////////////////////////////////////////////////////////////////////////////
|
12
|
+
#ifndef READSTR_H
|
13
|
+
#define READSTR_H
|
14
|
+
|
15
|
+
#include <iostream>
|
16
|
+
|
17
|
+
int ReadString(std::istream &is, char *pszBuffer, int Size);
|
18
|
+
|
19
|
+
#endif
|
@@ -0,0 +1,61 @@
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////
|
2
|
+
//
|
3
|
+
// square.h
|
4
|
+
//
|
5
|
+
// CSquare class definition
|
6
|
+
//
|
7
|
+
// Remi Coulom
|
8
|
+
//
|
9
|
+
// june 1996
|
10
|
+
//
|
11
|
+
////////////////////////////////////////////////////////////////////////////
|
12
|
+
#ifndef SQUARE_H
|
13
|
+
#define SQUARE_H
|
14
|
+
|
15
|
+
class CSquare // sq
|
16
|
+
{
|
17
|
+
private: //////////////////////////////////////////////////////////////////
|
18
|
+
int sq;
|
19
|
+
|
20
|
+
public: ///////////////////////////////////////////////////////////////////
|
21
|
+
enum
|
22
|
+
{
|
23
|
+
a1, b1, c1, d1, e1, f1, g1, h1,
|
24
|
+
a2, b2, c2, d2, e2, f2, g2, h2,
|
25
|
+
a3, b3, c3, d3, e3, f3, g3, h3,
|
26
|
+
a4, b4, c4, d4, e4, f4, g4, h4,
|
27
|
+
a5, b5, c5, d5, e5, f5, g5, h5,
|
28
|
+
a6, b6, c6, d6, e6, f6, g6, h6,
|
29
|
+
a7, b7, c7, d7, e7, f7, g7, h7,
|
30
|
+
a8, b8, c8, d8, e8, f8, g8, h8
|
31
|
+
};
|
32
|
+
|
33
|
+
enum
|
34
|
+
{
|
35
|
+
Left = -1,
|
36
|
+
Right = +1,
|
37
|
+
Up = +8,
|
38
|
+
Down = -8
|
39
|
+
};
|
40
|
+
|
41
|
+
CSquare() {}
|
42
|
+
CSquare(int i) {sq = i;}
|
43
|
+
CSquare(const char *psz) {sq = psz[0] - 'a' + 8 * (psz[1] - '1');}
|
44
|
+
|
45
|
+
operator int() const {return sq;}
|
46
|
+
const CSquare &operator +=(int i) {sq += i; return *this;}
|
47
|
+
const CSquare &operator -=(int i) {sq -= i; return *this;}
|
48
|
+
const CSquare &operator ++() {sq++; return *this;}
|
49
|
+
|
50
|
+
int GetRank() const {return sq / 8;}
|
51
|
+
int GetFile() const {return sq % 8;}
|
52
|
+
int IsWhite() const {return ((sq / 8) + (sq % 8)) & 1;}
|
53
|
+
void MakeString(char *psz)
|
54
|
+
{
|
55
|
+
psz[0] = 'a' + GetFile();
|
56
|
+
psz[1] = '1' + GetRank();
|
57
|
+
psz[2] = 0;
|
58
|
+
}
|
59
|
+
};
|
60
|
+
|
61
|
+
#endif
|
@@ -0,0 +1,81 @@
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////
|
2
|
+
//
|
3
|
+
// str.cpp
|
4
|
+
//
|
5
|
+
// CSTR class
|
6
|
+
// (Seven Tag Roster)
|
7
|
+
//
|
8
|
+
// Remi Coulom
|
9
|
+
//
|
10
|
+
// june 1996
|
11
|
+
//
|
12
|
+
////////////////////////////////////////////////////////////////////////////
|
13
|
+
#include <cstring>
|
14
|
+
|
15
|
+
#include "debug.h"
|
16
|
+
#include "str.h"
|
17
|
+
|
18
|
+
////////////////////////////////////////////////////////////////////////////
|
19
|
+
// Safe copy of a string to another string with limited size
|
20
|
+
////////////////////////////////////////////////////////////////////////////
|
21
|
+
static void SafeCopy(char *pszDest, const char *pszOrig, int Size)
|
22
|
+
{
|
23
|
+
strncpy(pszDest, pszOrig, Size);
|
24
|
+
pszDest[Size - 1] = 0;
|
25
|
+
}
|
26
|
+
|
27
|
+
////////////////////////////////////////////////////////////////////////////
|
28
|
+
// Default constructor
|
29
|
+
////////////////////////////////////////////////////////////////////////////
|
30
|
+
CSTR::CSTR()
|
31
|
+
{
|
32
|
+
Reset();
|
33
|
+
}
|
34
|
+
|
35
|
+
////////////////////////////////////////////////////////////////////////////
|
36
|
+
// Reset function
|
37
|
+
////////////////////////////////////////////////////////////////////////////
|
38
|
+
void CSTR::Reset()
|
39
|
+
{
|
40
|
+
*szEvent = 0;
|
41
|
+
*szSite = 0;
|
42
|
+
*szRound = 0;
|
43
|
+
*szWhite = 0;
|
44
|
+
*szBlack = 0;
|
45
|
+
Result = Unknown;
|
46
|
+
date = CDate::Today();
|
47
|
+
}
|
48
|
+
|
49
|
+
////////////////////////////////////////////////////////////////////////////
|
50
|
+
// Functions to set strings
|
51
|
+
////////////////////////////////////////////////////////////////////////////
|
52
|
+
void CSTR::SetEvent(const char *psz)
|
53
|
+
{
|
54
|
+
SafeCopy(szEvent, psz, sizeof szEvent);
|
55
|
+
}
|
56
|
+
|
57
|
+
void CSTR::SetSite(const char *psz)
|
58
|
+
{
|
59
|
+
SafeCopy(szSite, psz, sizeof szSite);
|
60
|
+
}
|
61
|
+
|
62
|
+
void CSTR::SetRound(const char *psz)
|
63
|
+
{
|
64
|
+
SafeCopy(szRound, psz, sizeof szRound);
|
65
|
+
}
|
66
|
+
|
67
|
+
void CSTR::SetWhite(const char *psz)
|
68
|
+
{
|
69
|
+
SafeCopy(szWhite, psz, sizeof szWhite);
|
70
|
+
}
|
71
|
+
|
72
|
+
void CSTR::SetBlack(const char *psz)
|
73
|
+
{
|
74
|
+
SafeCopy(szBlack, psz, sizeof szBlack);
|
75
|
+
}
|
76
|
+
|
77
|
+
void CSTR::SetResult(int i)
|
78
|
+
{
|
79
|
+
ASSERT(i >= BlackWins && i <= Unknown);
|
80
|
+
Result = i;
|
81
|
+
}
|
data/ext/bayeselo/str.h
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////
|
2
|
+
//
|
3
|
+
// str.h
|
4
|
+
//
|
5
|
+
// CSTR class definition
|
6
|
+
// (Seven Tag Roster)
|
7
|
+
//
|
8
|
+
// R�mi Coulom
|
9
|
+
//
|
10
|
+
// june 1996
|
11
|
+
//
|
12
|
+
////////////////////////////////////////////////////////////////////////////
|
13
|
+
#ifndef STR_H
|
14
|
+
#define STR_H
|
15
|
+
|
16
|
+
#include "date.h" // CDate
|
17
|
+
|
18
|
+
class CSTR // str
|
19
|
+
{
|
20
|
+
private: //////////////////////////////////////////////////////////////////
|
21
|
+
char szEvent[64];
|
22
|
+
char szSite[64];
|
23
|
+
CDate date;
|
24
|
+
char szRound[32];
|
25
|
+
char szWhite[64];
|
26
|
+
char szBlack[64];
|
27
|
+
int Result;
|
28
|
+
|
29
|
+
public: ///////////////////////////////////////////////////////////////////
|
30
|
+
//
|
31
|
+
// Possible Results
|
32
|
+
//
|
33
|
+
enum
|
34
|
+
{
|
35
|
+
BlackWins, // 0-1
|
36
|
+
Draw, // 1/2-1/2
|
37
|
+
WhiteWins, // 1-0
|
38
|
+
Unknown, // *
|
39
|
+
Results
|
40
|
+
};
|
41
|
+
|
42
|
+
//
|
43
|
+
// Default constructor, to prevent dangerous uninitialized data
|
44
|
+
//
|
45
|
+
CSTR();
|
46
|
+
|
47
|
+
//
|
48
|
+
// Sets
|
49
|
+
//
|
50
|
+
void Reset();
|
51
|
+
void SetResult(int i);
|
52
|
+
void SetDate(const CDate &dateNew) {date = dateNew;}
|
53
|
+
void SetEvent(const char *psz);
|
54
|
+
void SetSite(const char *psz);
|
55
|
+
void SetRound(const char *psz);
|
56
|
+
void SetWhite(const char *psz);
|
57
|
+
void SetBlack(const char *psz);
|
58
|
+
|
59
|
+
//
|
60
|
+
// Gets
|
61
|
+
//
|
62
|
+
int GetResult() const {return Result;}
|
63
|
+
const CDate &GetDate () const {return date;}
|
64
|
+
const char *GetEvent() const {return szEvent;}
|
65
|
+
const char *GetSite () const {return szSite;}
|
66
|
+
const char *GetRound() const {return szRound;}
|
67
|
+
const char *GetWhite() const {return szWhite;}
|
68
|
+
const char *GetBlack() const {return szBlack;}
|
69
|
+
};
|
70
|
+
|
71
|
+
#endif
|
@@ -0,0 +1,30 @@
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////
|
2
|
+
//
|
3
|
+
// version.cpp
|
4
|
+
//
|
5
|
+
// CVersion class
|
6
|
+
//
|
7
|
+
// Remi Coulom
|
8
|
+
//
|
9
|
+
// May, 1997
|
10
|
+
//
|
11
|
+
////////////////////////////////////////////////////////////////////////////
|
12
|
+
#include "version.h"
|
13
|
+
|
14
|
+
#include "version_number.h"
|
15
|
+
|
16
|
+
const char CVersion::szVersion[] = VERSION;
|
17
|
+
const char CVersion::szCopyright[] =
|
18
|
+
"version "VERSION", Copyright (C) 1997-2010 Remi Coulom.\n"
|
19
|
+
"compiled "__DATE__" "__TIME__".\n"
|
20
|
+
"This program comes with ABSOLUTELY NO WARRANTY.\n"
|
21
|
+
"This is free software, and you are welcome to redistribute it\n"
|
22
|
+
"under the terms and conditions of the GNU General Public License.\n"
|
23
|
+
"See http://www.gnu.org/copyleft/gpl.html for details.\n";
|
24
|
+
|
25
|
+
const char CVersion::szBinary[] =
|
26
|
+
"version "VERSION".\n"
|
27
|
+
"Copyright 1997-2010 by Remi Coulom. All Rights Reserved.\n"
|
28
|
+
"Permission is granted to freely use and distribute this program,\n"
|
29
|
+
"provided that no charge is made for it and it is distributed unmodified\n"
|
30
|
+
"This program comes with ABSOLUTELY NO WARRANTY.\n";
|
@@ -0,0 +1,28 @@
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////
|
2
|
+
//
|
3
|
+
// version.h
|
4
|
+
//
|
5
|
+
// CVersion class declaration
|
6
|
+
//
|
7
|
+
// Remi Coulom
|
8
|
+
//
|
9
|
+
// May, 1997
|
10
|
+
//
|
11
|
+
////////////////////////////////////////////////////////////////////////////
|
12
|
+
#ifndef VERSION_H
|
13
|
+
#define VERSION_H
|
14
|
+
|
15
|
+
class CVersion
|
16
|
+
{
|
17
|
+
private: //////////////////////////////////////////////////////////////////
|
18
|
+
static const char szVersion[];
|
19
|
+
static const char szCopyright[];
|
20
|
+
static const char szBinary[];
|
21
|
+
|
22
|
+
public: ///////////////////////////////////////////////////////////////////
|
23
|
+
static const char *GetVersion() {return szVersion;}
|
24
|
+
static const char *GetCopyright() {return szCopyright;}
|
25
|
+
static const char *GetBinaryCopyright() {return szBinary;}
|
26
|
+
};
|
27
|
+
|
28
|
+
#endif
|
@@ -0,0 +1 @@
|
|
1
|
+
#define VERSION "0057"
|
data/lib/elo_ratings.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
module EloRatings
|
2
|
+
class Results
|
3
|
+
def initialize
|
4
|
+
@c_bayeselo = CBayeselo.new
|
5
|
+
@players = []
|
6
|
+
end
|
7
|
+
|
8
|
+
def add_game player_1, player_2, result
|
9
|
+
@c_bayeselo.append index_for!(player_1), index_for!(player_2), result
|
10
|
+
end
|
11
|
+
|
12
|
+
def count_games_for player
|
13
|
+
return 0 if !exists? player
|
14
|
+
@c_bayeselo.count_games(index_for(player)).to_i
|
15
|
+
end
|
16
|
+
|
17
|
+
def elo_for player
|
18
|
+
return nil if !exists? player
|
19
|
+
@c_bayeselo.get_elo index_for(player)
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
|
24
|
+
def exists? player
|
25
|
+
!!index_for(player)
|
26
|
+
end
|
27
|
+
|
28
|
+
def index_for player
|
29
|
+
@players.index player
|
30
|
+
end
|
31
|
+
|
32
|
+
def index_for! player
|
33
|
+
index = index_for player
|
34
|
+
if index.nil?
|
35
|
+
index = @players.length
|
36
|
+
@players << player
|
37
|
+
end
|
38
|
+
index
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|