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,105 @@
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////
|
2
|
+
//
|
3
|
+
// pgnlex.h
|
4
|
+
//
|
5
|
+
// CPGNLex class definition
|
6
|
+
// (PGN lexical analysis)
|
7
|
+
//
|
8
|
+
// Remi Coulom
|
9
|
+
//
|
10
|
+
// August 1996
|
11
|
+
//
|
12
|
+
////////////////////////////////////////////////////////////////////////////
|
13
|
+
#ifndef PGNLEX_H
|
14
|
+
#define PGNLEX_H
|
15
|
+
|
16
|
+
#include <iostream>
|
17
|
+
|
18
|
+
class CPGNLex //pgnlex
|
19
|
+
{
|
20
|
+
private: //////////////////////////////////////////////////////////////////
|
21
|
+
std::istream *pistr;
|
22
|
+
|
23
|
+
int CurrChar;
|
24
|
+
int Token;
|
25
|
+
int Value;
|
26
|
+
enum {MaxPGNLine = 1024};
|
27
|
+
char szString[MaxPGNLine];
|
28
|
+
enum {ContextSize = 40};
|
29
|
+
char szContextBuffer[ContextSize + 1];
|
30
|
+
int ContextIndex;
|
31
|
+
|
32
|
+
int NextChar();
|
33
|
+
|
34
|
+
public: ///////////////////////////////////////////////////////////////////
|
35
|
+
//
|
36
|
+
// Tokens
|
37
|
+
// Note : these tokens do not conform strictly with standard.txt
|
38
|
+
//
|
39
|
+
// DIGIT = [0-9]
|
40
|
+
// LETTER = [a-zA-Z]
|
41
|
+
// SYMBOLCONTINUATION = LETTER U DIGIT U {_} U {+} U {#} U {=} U {:} U {-}
|
42
|
+
//
|
43
|
+
enum
|
44
|
+
{
|
45
|
+
TOK_BOF, // Beginning Of File
|
46
|
+
TOK_EOF, // End Of File
|
47
|
+
TOK_String, //s '"'(ALLCHARACTERS U '\\' U '\"' - '\' - '"')*'"'
|
48
|
+
TOK_Integer, //n DIGIT+
|
49
|
+
TOK_Period, // '.'
|
50
|
+
TOK_GameTermination, //n '0-1' U '1/2-1/2' U '1-0' U '*'
|
51
|
+
TOK_TagOpen, // '['
|
52
|
+
TOK_TagClose, // ']'
|
53
|
+
TOK_RAVOpen, // '('
|
54
|
+
TOK_RAVClose, // ')'
|
55
|
+
TOK_ReservedOpen, // '<'
|
56
|
+
TOK_ReservedClose, // '>'
|
57
|
+
TOK_NAG, //n '$'DIGIT* U '?' U '!' U '!?' U '?!' U '!!' U '??'
|
58
|
+
TOK_Symbol, //s LETTER(SYMBOLCONTINUATION)*
|
59
|
+
TOK_Comment, //s '{'(ALLCHARACTERS - '}')*'}'
|
60
|
+
TOKs
|
61
|
+
};
|
62
|
+
|
63
|
+
//
|
64
|
+
// Constructor
|
65
|
+
//
|
66
|
+
CPGNLex();
|
67
|
+
CPGNLex(std::istream &istr);
|
68
|
+
|
69
|
+
//
|
70
|
+
// Function to reset the input stream
|
71
|
+
//
|
72
|
+
|
73
|
+
// Sets the current token to TOK_BOF
|
74
|
+
void Reset();
|
75
|
+
// Changes the input stream
|
76
|
+
void Reset(std::istream &istr);
|
77
|
+
|
78
|
+
//
|
79
|
+
// Functions to read tokens
|
80
|
+
//
|
81
|
+
|
82
|
+
// Function to move to the next token
|
83
|
+
int ReadNextToken();
|
84
|
+
|
85
|
+
// Access to the current token type
|
86
|
+
int GetToken() const {return Token;}
|
87
|
+
|
88
|
+
// Access to the current token value
|
89
|
+
// This value is set when TOK_Integer, TOK_GameTermination, TOK_NAG read
|
90
|
+
int TokenValue() const;
|
91
|
+
|
92
|
+
// Access to the current token string
|
93
|
+
// This value is set when a TOK_String or TOK_Symbol is read
|
94
|
+
const char *TokenString() const;
|
95
|
+
|
96
|
+
// returns 0 if the searched token is found, 1 if eof is reached
|
97
|
+
int WaitForToken(int Searched);
|
98
|
+
|
99
|
+
//
|
100
|
+
// Get context (useful to display error messages)
|
101
|
+
//
|
102
|
+
void PrintContext(std::ostream &out) const;
|
103
|
+
};
|
104
|
+
|
105
|
+
#endif
|
@@ -0,0 +1,126 @@
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////
|
2
|
+
//
|
3
|
+
// pgnstr.cpp
|
4
|
+
//
|
5
|
+
// PGN input/output functions
|
6
|
+
//
|
7
|
+
// Remi Coulom
|
8
|
+
//
|
9
|
+
// August, 1996
|
10
|
+
//
|
11
|
+
////////////////////////////////////////////////////////////////////////////
|
12
|
+
#include <iostream>
|
13
|
+
#include <sstream>
|
14
|
+
#include <cstring>
|
15
|
+
|
16
|
+
#include "pgn.h"
|
17
|
+
#include "str.h" // CSTR
|
18
|
+
#include "date.h" // CDate
|
19
|
+
#include "player.h" // CPlayer
|
20
|
+
#include "pgnlex.h" // CPGNLex
|
21
|
+
|
22
|
+
//
|
23
|
+
// Tag identifiers
|
24
|
+
//
|
25
|
+
const char * const CPGN::tszTag[] =
|
26
|
+
{
|
27
|
+
"Event",
|
28
|
+
"Site",
|
29
|
+
"Date",
|
30
|
+
"Round",
|
31
|
+
"White",
|
32
|
+
"Black",
|
33
|
+
"Result",
|
34
|
+
"SetUp",
|
35
|
+
"FEN"
|
36
|
+
};
|
37
|
+
|
38
|
+
//
|
39
|
+
// Result strings (CSTR for the enumeration)
|
40
|
+
//
|
41
|
+
const char * const CPGN::tszResult[] = {"0-1", "1/2-1/2", "1-0", "*"};
|
42
|
+
|
43
|
+
////////////////////////////////////////////////////////////////////////////
|
44
|
+
// WriteString
|
45
|
+
////////////////////////////////////////////////////////////////////////////
|
46
|
+
static void WriteString(const char *psz, std::ostream &ostr)
|
47
|
+
{
|
48
|
+
ostr << '"';
|
49
|
+
for(; *psz; psz++)
|
50
|
+
if (*psz == '"' || *psz == '\\')
|
51
|
+
ostr << '\\' << *psz;
|
52
|
+
else
|
53
|
+
ostr << *psz;
|
54
|
+
ostr << '"';
|
55
|
+
}
|
56
|
+
|
57
|
+
////////////////////////////////////////////////////////////////////////////
|
58
|
+
// WriteTag
|
59
|
+
////////////////////////////////////////////////////////////////////////////
|
60
|
+
void CPGN::WriteTag(int Tag, const char *psz, std::ostream &ostr)
|
61
|
+
{
|
62
|
+
ostr << '[' << tszTag[Tag] << ' ';
|
63
|
+
WriteString(psz, ostr);
|
64
|
+
ostr << "]\n";
|
65
|
+
}
|
66
|
+
|
67
|
+
////////////////////////////////////////////////////////////////////////////
|
68
|
+
// ReadTAG
|
69
|
+
////////////////////////////////////////////////////////////////////////////
|
70
|
+
static int ReadTAG(CPGNLex &pgnlex)
|
71
|
+
{
|
72
|
+
int i;
|
73
|
+
|
74
|
+
if (pgnlex.WaitForToken(CPGNLex::TOK_Symbol))
|
75
|
+
return CPGN::TAGs;
|
76
|
+
|
77
|
+
for (i = CPGN::TAGs; --i >= 0;)
|
78
|
+
if (!strcmp(pgnlex.TokenString(), CPGN::tszTag[i]))
|
79
|
+
break;
|
80
|
+
|
81
|
+
if (pgnlex.WaitForToken(CPGNLex::TOK_TagClose))
|
82
|
+
return CPGN::TAGs;
|
83
|
+
|
84
|
+
return i;
|
85
|
+
}
|
86
|
+
|
87
|
+
////////////////////////////////////////////////////////////////////////////
|
88
|
+
// ReadSTR
|
89
|
+
////////////////////////////////////////////////////////////////////////////
|
90
|
+
int CPGN::ReadSTR(CSTR &str, CPGNLex &pgnlex)
|
91
|
+
{
|
92
|
+
if (pgnlex.WaitForToken(CPGNLex::TOK_TagOpen))
|
93
|
+
return 1;
|
94
|
+
|
95
|
+
int TAGS = 0;
|
96
|
+
do
|
97
|
+
{
|
98
|
+
TAGS++;
|
99
|
+
switch (ReadTAG(pgnlex))
|
100
|
+
{
|
101
|
+
case TAG_Event: str.SetEvent(pgnlex.TokenString()); break;
|
102
|
+
case TAG_Site: str.SetSite(pgnlex.TokenString()); break;
|
103
|
+
case TAG_Date: str.SetDate(pgnlex.TokenString()); break;
|
104
|
+
case TAG_Round: str.SetRound(pgnlex.TokenString()); break;
|
105
|
+
case TAG_White: str.SetWhite(pgnlex.TokenString()); break;
|
106
|
+
case TAG_Black: str.SetBlack(pgnlex.TokenString()); break;
|
107
|
+
case TAG_Result:
|
108
|
+
{
|
109
|
+
int j;
|
110
|
+
|
111
|
+
for (j = CSTR::Results; --j >= 0;)
|
112
|
+
if (!strcmp(pgnlex.TokenString(), tszResult[j]))
|
113
|
+
break;
|
114
|
+
|
115
|
+
if (j >= 0)
|
116
|
+
str.SetResult(j);
|
117
|
+
}
|
118
|
+
break;
|
119
|
+
default:
|
120
|
+
TAGS--;
|
121
|
+
}
|
122
|
+
}
|
123
|
+
while (pgnlex.ReadNextToken() == CPGNLex::TOK_TagOpen && TAGS < 7);
|
124
|
+
|
125
|
+
return 0;
|
126
|
+
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////
|
2
|
+
//
|
3
|
+
// piece.h
|
4
|
+
//
|
5
|
+
// CPiece class definition
|
6
|
+
//
|
7
|
+
// Remi Coulom
|
8
|
+
//
|
9
|
+
// june 1996
|
10
|
+
//
|
11
|
+
////////////////////////////////////////////////////////////////////////////
|
12
|
+
#ifndef PIECE_H
|
13
|
+
#define PIECE_H
|
14
|
+
|
15
|
+
class CPiece // piece
|
16
|
+
{
|
17
|
+
private: //////////////////////////////////////////////////////////////////
|
18
|
+
int piece;
|
19
|
+
static char tcPiece[];
|
20
|
+
|
21
|
+
public: ///////////////////////////////////////////////////////////////////
|
22
|
+
enum
|
23
|
+
{
|
24
|
+
King = 0x00,
|
25
|
+
Queen = 0x01,
|
26
|
+
Rook = 0x02,
|
27
|
+
Bishop = 0x04,
|
28
|
+
Knight = 0x06,
|
29
|
+
Pawn = 0x08,
|
30
|
+
Black = 0x10,
|
31
|
+
Undef = 0x20,
|
32
|
+
Empty = 0xff
|
33
|
+
};
|
34
|
+
|
35
|
+
CPiece(int pieceValue) {piece = pieceValue;};
|
36
|
+
CPiece(const char *pcPiece);
|
37
|
+
|
38
|
+
operator int() const {return piece;};
|
39
|
+
int GetNature() const {return piece & 0x0f;};
|
40
|
+
int GetColor() const {return (piece & 0x30) >> 4;};
|
41
|
+
char GetChar() const;
|
42
|
+
};
|
43
|
+
|
44
|
+
#endif
|
@@ -0,0 +1,31 @@
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////
|
2
|
+
//
|
3
|
+
// player.h
|
4
|
+
//
|
5
|
+
// CPlayer class definition
|
6
|
+
//
|
7
|
+
// Remi Coulom
|
8
|
+
//
|
9
|
+
// june 1996
|
10
|
+
//
|
11
|
+
////////////////////////////////////////////////////////////////////////////
|
12
|
+
#ifndef PLAYER_H
|
13
|
+
#define PLAYER_H
|
14
|
+
|
15
|
+
class CPlayer // player
|
16
|
+
{
|
17
|
+
private: //////////////////////////////////////////////////////////////////
|
18
|
+
int player;
|
19
|
+
|
20
|
+
public: ///////////////////////////////////////////////////////////////////
|
21
|
+
enum
|
22
|
+
{
|
23
|
+
White = 0,
|
24
|
+
Black = 1
|
25
|
+
};
|
26
|
+
|
27
|
+
CPlayer(int i) {player = i;}
|
28
|
+
int Opponent() const {return player ^ Black;}
|
29
|
+
};
|
30
|
+
|
31
|
+
#endif
|
@@ -0,0 +1,89 @@
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////
|
2
|
+
//
|
3
|
+
// position.h
|
4
|
+
//
|
5
|
+
// CPosition class definition
|
6
|
+
//
|
7
|
+
// Remi Coulom
|
8
|
+
//
|
9
|
+
// june 1996
|
10
|
+
//
|
11
|
+
////////////////////////////////////////////////////////////////////////////
|
12
|
+
#ifndef POSITION_H
|
13
|
+
#define POSITION_H
|
14
|
+
|
15
|
+
class CMove;
|
16
|
+
class CHashCodeComputer;
|
17
|
+
|
18
|
+
class CPosition // pos
|
19
|
+
{
|
20
|
+
private: //////////////////////////////////////////////////////////////////
|
21
|
+
static CHashCodeComputer hcc;
|
22
|
+
|
23
|
+
unsigned char tpiece[64];
|
24
|
+
unsigned char player;
|
25
|
+
char fBlackOO;
|
26
|
+
char fWhiteOO;
|
27
|
+
char fBlackOOO;
|
28
|
+
char fWhiteOOO;
|
29
|
+
unsigned char sqEnPassant;
|
30
|
+
int nhmReversible;
|
31
|
+
int nm;
|
32
|
+
|
33
|
+
int IsAttackedDir(int sqFrom, int piece1, int piece2, int DirFlag) const;
|
34
|
+
|
35
|
+
public: ///////////////////////////////////////////////////////////////////
|
36
|
+
//
|
37
|
+
// Default constructor to prevent uninitialized data
|
38
|
+
//
|
39
|
+
CPosition();
|
40
|
+
|
41
|
+
//
|
42
|
+
// Test for equality
|
43
|
+
//
|
44
|
+
int operator==(const CPosition &pos) const;
|
45
|
+
int operator!=(const CPosition &pos) const {return !operator==(pos);}
|
46
|
+
|
47
|
+
//
|
48
|
+
// Gets
|
49
|
+
//
|
50
|
+
int GetPiece(int sq) const {return tpiece[sq];}
|
51
|
+
int GetPlayer() const {return player;}
|
52
|
+
int GetOpponent() const {return player ^ 1;}
|
53
|
+
int GetBlackOO() const {return fBlackOO;}
|
54
|
+
int GetWhiteOO() const {return fWhiteOO;}
|
55
|
+
int GetBlackOOO() const {return fBlackOOO;}
|
56
|
+
int GetWhiteOOO() const {return fWhiteOOO;}
|
57
|
+
int GetEnPassant() const {return sqEnPassant;}
|
58
|
+
int GetReversible() const {return nhmReversible;}
|
59
|
+
int GetMoves() const {return nm;}
|
60
|
+
|
61
|
+
int IsAttacked(int sq, int player) const;
|
62
|
+
int Check() const;
|
63
|
+
int IsLegal() const;
|
64
|
+
void Symmetrical(CPosition &pos) const;
|
65
|
+
|
66
|
+
//
|
67
|
+
// Sets
|
68
|
+
//
|
69
|
+
void SetPiece(int sq, int piece) {tpiece[sq] = piece;}
|
70
|
+
void SetPlayer(int playerNew) {player = playerNew;}
|
71
|
+
void SetBlackOO(int f) {fBlackOO = f;}
|
72
|
+
void SetWhiteOO(int f) {fWhiteOO = f;}
|
73
|
+
void SetBlackOOO(int f) {fBlackOOO = f;}
|
74
|
+
void SetWhiteOOO(int f) {fWhiteOOO = f;}
|
75
|
+
void SetEnPassant(int sq) {sqEnPassant = sq;}
|
76
|
+
void SetReversible(int nhm) {nhmReversible = nhm;}
|
77
|
+
void SetMoves(int nmNew) {nm = nmNew;}
|
78
|
+
|
79
|
+
void Reset();
|
80
|
+
void Clear();
|
81
|
+
void PlayMove(CMove move);
|
82
|
+
|
83
|
+
//
|
84
|
+
// Access to the hashcode computer
|
85
|
+
//
|
86
|
+
static const CHashCodeComputer &GetHashCodeComputer() {return hcc;}
|
87
|
+
};
|
88
|
+
|
89
|
+
#endif
|
@@ -0,0 +1,114 @@
|
|
1
|
+
// ////////////////////////////////////////////////////////////////////////////
|
2
|
+
// //
|
3
|
+
// // random.cpp
|
4
|
+
// //
|
5
|
+
// // CRandom class
|
6
|
+
// //
|
7
|
+
// // Remi Coulom
|
8
|
+
// //
|
9
|
+
// // August 1996
|
10
|
+
// //
|
11
|
+
// ////////////////////////////////////////////////////////////////////////////
|
12
|
+
// #include <cmath>
|
13
|
+
//
|
14
|
+
// ////////////////////////////////////////////////////////////////////////////
|
15
|
+
// // New seed
|
16
|
+
// ////////////////////////////////////////////////////////////////////////////
|
17
|
+
// template<class TYPE>
|
18
|
+
// void CRandom<TYPE>::Seed(TYPE ulSeed)
|
19
|
+
// {
|
20
|
+
// Index1 = 23;
|
21
|
+
// Index2 = 54;
|
22
|
+
// fNextGaussian = 0;
|
23
|
+
//
|
24
|
+
// //
|
25
|
+
// // The array is initialized with random values
|
26
|
+
// //
|
27
|
+
// {
|
28
|
+
// for (int i = 55; --i >= 0;)
|
29
|
+
// tulArray[i] = ulSeed = (ulSeed * 7) + 123456789L;
|
30
|
+
// }
|
31
|
+
//
|
32
|
+
// //
|
33
|
+
// // These are scrambled a little
|
34
|
+
// //
|
35
|
+
// {
|
36
|
+
// for (int i = 200; --i >= 0;)
|
37
|
+
// NewValue();
|
38
|
+
// }
|
39
|
+
// }
|
40
|
+
//
|
41
|
+
// ////////////////////////////////////////////////////////////////////////////
|
42
|
+
// // Next double (??? very bad)
|
43
|
+
// ////////////////////////////////////////////////////////////////////////////
|
44
|
+
// template<class TYPE>
|
45
|
+
// double CRandom<TYPE>::NextDouble()
|
46
|
+
// {
|
47
|
+
// return double(NewValue() & 0x7fffffff) / double(1U << 31);
|
48
|
+
// }
|
49
|
+
//
|
50
|
+
// ////////////////////////////////////////////////////////////////////////////
|
51
|
+
// // Next N(0,1)
|
52
|
+
// ////////////////////////////////////////////////////////////////////////////
|
53
|
+
// template<class TYPE>
|
54
|
+
// double CRandom<TYPE>::NextGaussian()
|
55
|
+
// {
|
56
|
+
// if (fNextGaussian)
|
57
|
+
// {
|
58
|
+
// fNextGaussian = 0;
|
59
|
+
// return NextGaussianValue;
|
60
|
+
// }
|
61
|
+
// else
|
62
|
+
// {
|
63
|
+
// fNextGaussian = 1;
|
64
|
+
// double x, y, n2;
|
65
|
+
// do
|
66
|
+
// {
|
67
|
+
// x = 2 * NextDouble() - 1;
|
68
|
+
// y = 2 * NextDouble() - 1;
|
69
|
+
// n2 = x * x + y * y;
|
70
|
+
// }
|
71
|
+
// while (n2 >= 1 || n2 == 0);
|
72
|
+
// double m = std::sqrt(-2 * std::log(n2) / n2);
|
73
|
+
// NextGaussianValue = y * m;
|
74
|
+
// return x * m;
|
75
|
+
// }
|
76
|
+
// }
|
77
|
+
//
|
78
|
+
// ////////////////////////////////////////////////////////////////////////////
|
79
|
+
// // Exponential law
|
80
|
+
// ////////////////////////////////////////////////////////////////////////////
|
81
|
+
// template<class TYPE>
|
82
|
+
// double CRandom<TYPE>::NextExponential()
|
83
|
+
// {
|
84
|
+
// double x;
|
85
|
+
// do
|
86
|
+
// x = NextDouble();
|
87
|
+
// while (x == 0);
|
88
|
+
// return -std::log(x);
|
89
|
+
// }
|
90
|
+
//
|
91
|
+
// ////////////////////////////////////////////////////////////////////////////
|
92
|
+
// // Binary I/O
|
93
|
+
// ////////////////////////////////////////////////////////////////////////////
|
94
|
+
// #include <iostream>
|
95
|
+
//
|
96
|
+
// template<class TYPE>
|
97
|
+
// void CRandom<TYPE>::BinaryWrite(std::ostream &out) const
|
98
|
+
// {
|
99
|
+
// out.write((const char *)&Index1, sizeof(Index1));
|
100
|
+
// out.write((const char *)&Index2, sizeof(Index2));
|
101
|
+
// out.write((const char *)tulArray, sizeof(tulArray));
|
102
|
+
// out.write((const char *)&fNextGaussian, sizeof(fNextGaussian));
|
103
|
+
// out.write((const char *)&NextGaussianValue, sizeof(NextGaussianValue));
|
104
|
+
// }
|
105
|
+
//
|
106
|
+
// template<class TYPE>
|
107
|
+
// void CRandom<TYPE>::BinaryRead(std::istream &in)
|
108
|
+
// {
|
109
|
+
// in.read((char *)&Index1, sizeof(Index1));
|
110
|
+
// in.read((char *)&Index2, sizeof(Index2));
|
111
|
+
// in.read((char *)tulArray, sizeof(tulArray));
|
112
|
+
// in.read((char *)&fNextGaussian, sizeof(fNextGaussian));
|
113
|
+
// in.read((char *)&NextGaussianValue, sizeof(NextGaussianValue));
|
114
|
+
// }
|