-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathinidone.c
342 lines (281 loc) · 6.14 KB
/
inidone.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
/*
Ordo is program for calculating ratings of engine or chess players
Copyright 2013 Miguel A. Ballicora
This file is part of Ordo.
Ordo is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Ordo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Ordo. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stddef.h>
#include <assert.h>
#include "inidone.h"
#include "mymem.h"
bool_t
ratings_init (player_t n, struct RATINGS *r)
{
enum {MAXU=9};
void *pu[MAXU];
bool_t ok;
int i,u;
size_t szu[MAXU] = {
sizeof(player_t),
sizeof(gamesnum_t),sizeof(gamesnum_t),
sizeof(double),sizeof(double),sizeof(double),
sizeof(double),sizeof(double),sizeof(double)
};
assert (n > 0);
for (ok = TRUE, u = 0, i = 0; i < MAXU && ok; i++) {
if (NULL != (pu[i] = memnew (szu[i] * (size_t)n))) {
u++;
} else {
while (u-->0) memrel(pu[u]);
ok = FALSE;
}
}
if (ok) {
r->size = n;
r->sorted = pu[0];
r->playedby = pu[1];
r->playedby_results = pu[2];
r->obtained = pu[3];
r->ratingof = pu[4];
r->ratingbk = pu[5];
r->changing = pu[6];
r->ratingof_results = pu[7];
r->obtained_results = pu[8];
}
return ok;
}
void
ratings_done (struct RATINGS *r)
{
r->size = 0;
memrel(r->sorted);
memrel(r->playedby);
memrel(r->playedby_results);
memrel(r->obtained);
memrel(r->ratingof);
memrel(r->ratingbk);
memrel(r->changing);
memrel(r->ratingof_results);
memrel(r->obtained_results);
}
static void
ratings2_copy (const struct RATINGS *src, struct RATINGS *tgt) //FIXME organize nomenclature, there is a ratings_copy() already
{
player_t i, n = src->size;
tgt->size = src->size;
for (i = 0; i < n; i++) {
tgt->sorted[i] =src->sorted[i];
tgt->playedby[i] =src->playedby[i];
tgt->playedby_results[i] =src->playedby_results[i];
tgt->obtained[i] =src->obtained[i];
tgt->ratingof[i] =src->ratingof[i];
tgt->ratingbk[i] =src->ratingbk[i];
tgt->changing[i] =src->changing[i];
tgt->ratingof_results[i] =src->ratingof_results[i];
tgt->obtained_results[i] =src->obtained_results[i];
}
}
bool_t
ratings_replicate (const struct RATINGS *src, struct RATINGS *tgt)
{
bool_t ok;
ok = ratings_init (src->size, tgt);
if (ok) {
ratings2_copy (src, tgt);
}
return ok;
}
//
bool_t
games_init (gamesnum_t n, struct GAMES *g)
{
struct gamei *p;
assert (n > 0);
if (NULL == (p = memnew (sizeof(struct gamei) * (size_t)n))) {
g->n = 0;
g->size = 0;
g->ga = NULL;
return FALSE; // failed
}
g->n = 0; /* empty for now */
g->size = n;
g->ga = p;
return TRUE;
}
void
games_done (struct GAMES *g)
{
memrel(g->ga);
g->n = 0;
g->size = 0;
g->ga = NULL;
}
static void
games_copy (const struct GAMES *src, struct GAMES *tgt)
{
gamesnum_t i, n = src->n;
struct gamei *s = src->ga;
struct gamei *t = tgt->ga;
tgt->n = src->n;
tgt->size = src->size;
for (i = 0; i < n; i++) {
t[i] = s[i];
}
}
bool_t
games_replicate (const struct GAMES *src, struct GAMES *tgt)
{
bool_t ok;
ok = games_init (src->n, tgt);
if (ok) {
games_copy (src, tgt);
}
return ok;
}
//
bool_t
players_init (player_t n, struct PLAYERS *x)
{
enum VARIAB {NV = 6};
bool_t failed;
size_t sz[NV];
void * pv[NV];
int i, j;
assert (n > 0);
// size of the individual elements
sz[0] = sizeof(char *);
sz[1] = sizeof(bool_t);
sz[2] = sizeof(bool_t);
sz[3] = sizeof(bool_t);
sz[4] = sizeof(bool_t);
sz[5] = sizeof(int);
for (failed = FALSE, i = 0; !failed && i < NV; i++) {
if (NULL == (pv[i] = memnew (sz[i] * (size_t)n))) {
for (j = 0; j < i; j++) memrel(pv[j]);
failed = TRUE;
}
}
if (failed) return FALSE;
x->n = 0; /* empty for now */
x->size = n;
x->anchored_n = 0;
x->name = pv[0];
x->flagged = pv[1];
x->present_in_games = pv[2];
x->prefed = pv[3];
x->priored = pv[4];
x->performance_type = pv[5];
x->perf_set = FALSE;
return TRUE;
}
void
players_done (struct PLAYERS *x)
{
assert(x->name);
assert(x->flagged);
assert(x->prefed);
assert(x->priored);
assert(x->performance_type);
memrel(x->name);
memrel(x->flagged);
memrel(x->prefed);
memrel(x->priored);
memrel(x->performance_type);
x->n = 0;
x->size = 0;
x->name = NULL;
x->flagged = NULL;
x->prefed = NULL;
x->priored = NULL;
x->performance_type = NULL;
}
#include "plyrs.h"
bool_t
players_replicate (const struct PLAYERS *src, struct PLAYERS *tgt)
{
bool_t ok;
ok = players_init (src->n, tgt);
if (ok) {
players_copy (src, tgt);
}
return ok;
}
//
bool_t
supporting_auxmem_init ( player_t nplayers
, struct prior **pPP
, struct prior **pPP_store
)
{
struct prior *d;
struct prior *e;
size_t sd = sizeof(struct prior);
size_t se = sizeof(struct prior);
assert(nplayers > 0);
if (NULL == (d = memnew (sd * (size_t)nplayers))) {
return FALSE;
} else
if (NULL == (e = memnew (se * (size_t)nplayers))) {
memrel(d);
return FALSE;
}
*pPP = d;
*pPP_store = e;
return TRUE;
}
void
supporting_auxmem_done ( struct prior **pPP
, struct prior **pPP_store)
{
priorlist_done (pPP);
priorlist_done (pPP_store);
return;
}
#include "relprior.h"
struct prior *
priorlist_init (player_t nplayers)
{
struct prior *d;
size_t sd = sizeof(struct prior);
assert(nplayers > 0);
if (NULL == (d = memnew (sd * (size_t)nplayers))) {
return NULL;
}
return d;
}
void
priorlist_done (struct prior **pPP)
{
struct prior *pp = *pPP;
if (pp)
memrel (pp);
pp = NULL;
*pPP = pp;
return;
}
#include <stdio.h>
bool_t
priorlist_replicate ( player_t nplayers
, struct prior *PP
, struct prior **pQQ
)
{
bool_t ok;
struct prior *qq;
qq = priorlist_init (nplayers);
ok = qq != NULL;
if (ok) {
priors_copy (PP, nplayers, qq);
*pQQ = qq;
}
return ok;
}