Subversion Repositories Games.Chess Giants

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
112 pmbaty 1
/*
2
    Protector -- a UCI chess engine
3
 
4
    Copyright (C) 2009-2010 Raimund Heid (Raimund_Heid@yahoo.com)
5
 
6
    This program is free software: you can redistribute it and/or modify
7
    it under the terms of the GNU General Public License as published by
8
    the Free Software Foundation, either version 3 of the License, or
9
    (at your option) any later version.
10
 
11
    This program is distributed in the hope that it will be useful,
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
    GNU General Public License for more details.
15
 
16
    You should have received a copy of the GNU General Public License
17
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 
19
*/
20
 
21
#ifndef _tools_h_
22
#define _tools_h_
23
 
24
#define INCLUDE_TABLEBASE_ACCESS        /* activate egtb access code */
25
 
26
#ifndef _MSC_VER // Pierre-Marie Baty -- protect macro redefinition
27
#define min(x,y) ((x)<(y)?(x):(y))
28
#define max(x,y) ((x)>(y)?(x):(y))
29
#endif // !_MSC_VER
30
#define avg(a,b) (((a)+(b))/2)
31
#define max4(a,b,c,d)      ( max(max((a),(b)),max((c),(d))) )
32
 
33
/**
34
 * Get the system time in milliseconds.
35
 */
36
unsigned long getTimestamp(void);
37
 
38
/**
39
 * Get the process time in milliseconds.
40
 */
41
long getProcessTimestamp(void);
42
 
43
typedef struct
44
{
45
   char *buffer;
46
   char *tail;
47
   unsigned int bufferSize;
48
}
49
String;
50
 
51
/**
52
 * Get an initialized empty string.
53
 */
54
String getEmptyString(void);
55
 
56
/**
57
 * Get an initialized string.
58
 */
59
String getString(const char *buffer, const char *lastChar);
60
 
61
/**
62
 * Free all memory allocated for the specified String.
63
 */
64
void deleteString(String * string);
65
 
66
/**
67
 * Append a formatted C-string to String.
68
 *
69
 * @return a pointer to the new String
70
 */
71
String *appendToString(String * string, const char *fmt, ...);
72
 
73
/**
74
 * Break the string specified by 'buffer' into lines of a maximum length
75
 * of 'maxLineLength'. The breaks will be realised by substituting
76
 * appropriate space characters with newline characters.
77
 */
78
void breakLines(char *buffer, unsigned int maxLineLength);
79
 
80
/**
81
 * Remove all space characters from the beginning and from the end
82
 * of 'buffer'.
83
 */
84
void trim(char *buffer);
85
 
86
/**
87
 * Get a token delimited by 'tokenDelimiters'.
88
 *
89
 * @return a substring of token, obtained using 'malloc'
90
 */
91
char *getToken(const char *token, const char *tokenDelimiters);
92
 
93
/**
94
 * Test if a number is a prime.
95
 *
96
 * @return 0 if 'candidate' is no prime
97
 */
98
int isPrime(unsigned long candidate);
99
 
100
/**
101
 * Calculate y = ln(x)
102
 *
103
 * @return a rounded integer
104
 */
105
int logIntValue(const double zeroPoint, const int maxPoint,
106
                const double maxValue, const int x);
107
 
108
/**
109
 * Apply a 256-based weight to the specified value.
110
 *
111
 * @return a rounded integer
112
 */
113
int applyWeight(double value, double weight);
114
 
115
/**
116
 * Get a value in specified min/max range.
117
 *
118
 * @return value if it is between minValue and maxValue
119
 */
120
int getLimitedValue(const int minValue, const int maxValue, const int value);
121
 
122
/**
123
 * Convert unsigned long long to hex string and vice versa.
124
 */
125
unsigned long long getUnsignedLongLongFromHexString(const char *str);
126
void getHexStringFromUnsignedLongLong(char *buffer, unsigned long long value);
127
 
128
/**
129
 * Initialize this module.
130
 *
131
 * @return 0 if no errors occurred.
132
 */
133
int initializeModuleTools(void);
134
 
135
/**
136
 * Test this module.
137
 *
138
 * @return 0 if all tests succeed.
139
 */
140
int testModuleTools(void);
141
 
142
#endif