-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboardlist.c
129 lines (109 loc) · 2.35 KB
/
boardlist.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
/*
* boardlist.c
* (c) 2017, Brian Stephenson
* brian@bstephen.me.uk
*
* A program to test orthodox chess problems of the types:
*
* directmates
* selfmates
* relfexmates
* helpmates
*
* Input is taken from the program options and output is xml on stdout.
*
*
* This is the module that includes all routines to do with boardlists.
*/
#include "sengine.h"
static int refutCompare(void*, void*);
void putRefutsToEnd(BOARDLIST* bml)
{
LL_SORT(bml->vektor, refutCompare);
return;
}
static int refutCompare(void* a, void* b)
{
BOARD* aa = (BOARD*) a;
BOARD* bb = (BOARD*) b;
int ia;
int ib;
ia = (aa->tag == '!') ? 1 : 0;
ib = (bb->tag == '!') ? 1 : 0;
if (ia == ib) {
return 0;
} else {
return (ia < ib) ? -1 : 1;
}
}
bool bListEquals(BOARDLIST* ibl, BOARDLIST* obl)
{
int counto, counti;
BOARD* tmp;
BOARD* tmp1;
BOARD* a;
BOARD* b;
assert(obl != NULL);
assert(ibl != NULL);
assert(ibl->moveNumber == obl->moveNumber);
//assert(obl->vektor != NULL);
//assert(ibl->vektor != NULL);
#ifdef MOVESTAT
fprintf(stderr, "%d bListEquals()\n", ibl->moveNumber);
#endif
LL_COUNT(ibl->vektor, tmp, counti);
LL_COUNT(obl->vektor, tmp1, counto);
if (counti != counto) {
return false;
}
if (counti == 0) {
return true;
}
/*
a = ibl->vektor->next;
b = obl->vektor->next;
*/
a = ibl->vektor;
b = obl->vektor;
while (a != NULL) {
assert(b != NULL);
if (deepEquals(a, b) == false) {
return false;
}
a = a->next;
b = b->next;
}
return true;
}
void weedOutShortVars(BOARDLIST* ml, unsigned char maxstip)
{
BOARDLIST* bl;
BOARD* b;
BOARD* tmp;
LL_FOREACH_SAFE(ml->vektor, b, tmp) {
bl = b->nextply;
if (bl != NULL) {
if (bl->stipIn < maxstip) {
LL_DELETE(ml->vektor, b);
freeBoard(b);
}
}
}
return;
}
void weedOutLongVars(BOARDLIST* thisml)
{
BOARDLIST* ml;
BOARD* m;
BOARD* tmp;
LL_FOREACH_SAFE(thisml->vektor, m, tmp) {
ml = m->nextply;
if (ml != NULL) {
if (ml->stipIn > thisml->minStip) {
LL_DELETE(thisml->vektor, m);
freeBoard(m);
}
}
}
return;
}